I use LED in call back function and the timer looks doing well. Then I add a xTimerStop()
to check that the timer stops at the time I want. But it seems timer doesn’t stop.
#include <Arduino_FreeRTOS.h>
#include <timers.h>
#define mainAUTO_RELOAD_TIMER_PERIOD pdMS_TO_TICKS( 5000 )
TimerHandle_t myTimer;
BaseType_t xTimerStarted;
BaseType_t xTimerStopped;
int key = 1;
void setup() {
pinMode(13, OUTPUT);
pinMode(7, OUTPUT);
myTimer = xTimerCreate(“MyTimer”,
mainAUTO_RELOAD_TIMER_PERIOD,
pdFALSE,
0,
prvTimerCallback);
if (myTimer != NULL)
{
xTimerStarted = xTimerStart(myTimer, 0);
if (xTimerStarted == pdPASS)
vTaskStartScheduler();
if (key == 1)
{
xTimerStopped = xTimerStart(myTimer, 0);
if (xTimerStopped == pdPASS) digitalWrite(7, HIGH);
}
}
}static void prvTimerCallback(TimerHandle_t myTimer)
{digitalWrite(13, HIGH);
}void loop() {}