i am any to ARM. i bought a sam D20 xplained board to play with at home. right now i have made a small program that uses SysTick irq to scan the push button input on PB02 and to turn on an led on PA08. The SysTick irq is working. but the code in my main loop to turn LED on and off does not get to run at all. the code stack in my setup function for SysTick. I even tried to put my main loop code inside my SysTick handler, since it is working at the time. I still can not get it to run. I scoped that SysTick frequency, because i use it to turn an output enable on a latch on and off. Systick is running at 20ms period. it should not block my main code execution , 20ms isa lot of time. can someone tell me what i did wrong? here is my code:
Code: Select all
#include <asf.h>
static void configure_systick_handler(void);
static struct port_config GPIO_config;
static uint8_t tenMS;
static uint32_t PB_Mask;
static uint32_t PB_Reg;
static uint32_t PB_Reg_buf;
int main (void)
{
system_init();
tenMS = 0x00;
//configuring PB01 as output, use for bus output enable
GPIO_config.direction = PORT_PIN_DIR_OUTPUT;
GPIO_config.input_pull = PORT_PIN_PULL_NONE;
port_pin_set_config(0x21, &GPIO_config);
GPIO_config.direction = PORT_PIN_DIR_OUTPUT;
GPIO_config.input_pull = PORT_PIN_PULL_NONE;
port_pin_set_config(PIN_PA08, &GPIO_config);
//configuring group of PB to be input
GPIO_config.direction = PORT_PIN_DIR_INPUT;
GPIO_config.input_pull = PORT_PIN_PULL_NONE;
//&PB_Group = 0x41004480;//base address of PB register
PB_Mask = 0x00000ffc;
port_group_set_config(&PORTB, PB_Mask, &GPIO_config);
//port_pin_set_output_level(0x21, 0x01);//bus output enable is off, active low
configure_systick_handler();
// Insert application code here, after the board has been initialized.
// This skeleton code simply sets the LED to the state of the button.
while (1) {
if((PB_Reg & 0x00000004 == 0x00000004) && (PB_Reg_buf & 0x00000004 == 0x00000000))
port_pin_toggle_output_level(PIN_PA08);
tenMS = 0x01;
while(tenMS == 0x01);
}
}
static void configure_systick_handler(void)
{
SysTick->CTRL = 0;
SysTick->LOAD = 80000;
SysTick->VAL = 0;
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_TICKINT_Msk | SysTick_CTRL_ENABLE_Msk;
}
void SysTick_Handler (void)
{
port_pin_toggle_output_level(0x21);// bus output enable on
//cpu_irq_enter_critical();
PB_Reg_buf = PB_Reg;
PB_Reg = port_group_get_input_level(&PORTB, PB_Mask);
if((PB_Reg & 0x00000004 == 0x00000004) && (PB_Reg_buf & 0x00000004 == 0x00000000))
port_pin_toggle_output_level(PIN_PA08);
tenMS = 0x00;
//cpu_irq_leave_critical();
}