cancel
Showing results for 
Search instead for 
Did you mean: 

Can't get oneshot timers to work

DavidL_
Associate III

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);
	}
}

 

1 ACCEPTED SOLUTION

Accepted Solutions
DavidL_
Associate III

Needed to add

HAL_TIM_Base_Stop_IT(&htim15);

View solution in original post

1 REPLY 1
DavidL_
Associate III

Needed to add

HAL_TIM_Base_Stop_IT(&htim15);