STM32f4 Timer interrupt
I got program which is requesting measurement results from external device and store them in array. My goal is to generate timer interrupt every 0.5s and process collected results, but it seems like timer interrupt somehow disrupt my UART communication with external device.
Here is my code:
case 2:
{
HAL_TIM_Base_Start_IT(&htim3);
while(Instruction == 2)
{
Send_request(&huart3, &Ocular_1_TxBuffer[0], &Ocular_1_RxBuffer[0]);
GetMeasurementValue(&Ocular_1_RxBuffer[0]);
CollectedData[Measurement] = MeasurementValue;
Measurement++;
}
HAL_TIM_Base_Stop_IT(&htim3);
break;
}
Timer interrupt handler:
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
if(htim == &htim3)
{
BubbleSort(CollectedData,Measurement);
Measuerement = 0;
}
}
Timer has priority number 1, UART has priority number 0. Error is generated becouse UART does not receive 4 bytes as expected. It seems like UART communication is not finished before timer interrupt occurs. When I comment line: HAL_TIM_Base_Start_IT(&htim3) UART communication works fine. Timer is configurated fine I already checked it's init function.
Do you have any idea what is wrong?
#stm32f4-discovery #stm32f4-timer #stm32f4-uart