Hello,
I have a question because there is a problem with writing code using timer.
I wrote the following code to avoid using the LED timer when I first ran it.
However, All_Stop() will not function properly the first time the code below is executed (that is, when the upload or when the pressed reset button).
void All_Start()
{
uint32_t err_code;
CenterLED_timers_start();
//err_code = app_button_enable();
//APP_ERROR_CHECK(err_code);
}
void All_Stop()
{
uint32_t err_code;
//err_code = app_button_disable();
//APP_ERROR_CHECK(err_code);
CenterLED_timers_stop();
nrf_gpio_pin_clear(BAT_LED_1); //LED Off
nrf_gpio_pin_clear(BAT_LED_2);
nrf_gpio_pin_clear(BAT_LED_3);
}
.
.
.
.
int charging_state = 0; //Used to prevent repeated output of CenterLED_timers_start.
.
.
.
else //no charging
{
//charging_state = 0;
if(charging_state == 0)
{
nrf_gpio_pin_clear(BAT_LED_1); //LED Off
nrf_gpio_pin_clear(BAT_LED_2);
nrf_gpio_pin_clear(BAT_LED_3);
CenterLED_timers_start(); //LED1,2,3 toggle repeate timer
charging_state = 1; //Used to prevent repeated output of CenterLED_timers_start.
//nrf_delay_ms(100);
printf("%d\n", charging_state); //check charging_state
if(charging_state == 1) //No LED activity before Bluetooth connection
{
printf("All_Stop\n");
//CenterLED_timers_stop();
All_Stop(); //center timer stop & LED Off
}
}
}
The timer starts because the charging_state was initially defined as zero, but the timer must be cancelled via All_Stop() immediately after.
This issue only occurs the first time I run it, and it will work normally after that (after a single change in the value of the charging_state).
When checked at the terminal, All_Stop seemed to have been executed properly.
Can you tell me the reason for this problem?
Thank you in advance.
(I think my explanation is complicated, but I'm sorry if the English interpretation is a little weird.)
