STM32f4定时器中断

时间:2018-06-28 09:37:53

标签: timer interrupt uart stm32f4discovery

我有一个程序从外部设备请求测量结果并将其存储在阵列中。我的目标是每0.5秒生成一次定时器中断并处理收集的结果,但是定时器中断似乎以某种方式破坏了我与外部设备的UART通信。

这是我的代码:

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

计时器中断处理程序:

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
    if(htim == &htim3)
    {
        BubbleSort(CollectedData,Measurement);
        Measuerement = 0;
    }
}

定时器的优先级为1,UART的优先级为0。由于UART未按预期接收4个字节,因此产生了错误。似乎在定时器中断发生之前UART通信尚未完成。当我注释行时:HAL_TIM_Base_Start_IT(&htim3)UART通信正常。计时器已配置好,我已经检查了它的初始化功能。

你知道哪里出了问题吗?

0 个答案:

没有答案