Skip to main content
Graduate
September 27, 2024
Solved

Can't get oneshot timers to work

  • September 27, 2024
  • 1 reply
  • 520 views

I want tim16 to, every 1 second, start tim15 which is a oneshot timer which then does something when the period elapsed.

I start tim16 in my main function, which works correctly, but the tim15 interrupt only triggers once, so my output looks like this:

First!
Second!
First!
First!
First!
...

 

Here is my code:

 

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
	if(htim == &htim16)
	{
		const char* message = "First!\r\n";
	 HAL_UART_Transmit(&huart2, (uint8_t*)message, strlen(message), HAL_MAX_DELAY);

		HAL_TIM_Base_Start_IT(&htim15);
	}
	else if(htim == &htim15)
	{
		const char* message = "Second!\r\n";
		HAL_UART_Transmit(&huart2, (uint8_t*)message, strlen(message), HAL_MAX_DELAY);
	}
}

 

    This topic has been closed for replies.
    Best answer by DavidL_

    Needed to add

    HAL_TIM_Base_Stop_IT(&htim15);

    1 reply

    DavidL_AuthorAnswer
    Graduate
    September 27, 2024

    Needed to add

    HAL_TIM_Base_Stop_IT(&htim15);