2019-07-14 18:29发布
60user61 发表于 2018-8-18 08:05 不要elseif 把两段if 分开试一下。很可能这两个标志位是同时产生的,你用elseif的话,下面的IDLE永远进不去。
niggle 发表于 2018-8-18 08:30 还是不行啊
最多设置5个标签!
还是不行啊
本帖最后由 jjbboox 于 2018-3-8 11:15 编辑
我是用HAL库实现的,可能和你不太一样。
/* USART6 串口空闲中断函数 */
void HeaterComm_Callback(void)
{
uint32_t TmpFlag = 0;
uint32_t TmpLength;
TmpFlag = __HAL_UART_GET_FLAG(&huart6, UART_FLAG_IDLE);
if((TmpFlag != RESET))
{
__HAL_UART_CLEAR_IDLEFLAG(&huart6);
//HAL_UART_AbortReceive_IT(&huart6);
HAL_UART_DMAStop(&huart6);
TmpLength = __HAL_DMA_GET_COUNTER((DMA_HandleTypeDef *)&hdma_usart6_rx);
//TmpLength = hdma_usart6_rx.Instance->NDTR;
HeaterComm.DataLength = 32 - TmpLength;
osSignalSet (HeaterComm_TaskHandle, 1); //HeaterComm.ReceiveFlag = 1;
}
}
/* HeaterCommTask function */
void HeaterCommTask(void const * argument)
{
/* USER CODE BEGIN HeaterCommTask */
osEvent Event;
HeaterComm.CommStatus = 1;
HeadData.Sensor.TcTemp[0].Status = Normal;
HeadData.Sensor.TcTemp[1].Status = Normal;
HeadData.Sensor.TcTemp[2].Status = Normal;
HeadData.Sensor.TcTemp[0].Value = 25;
HeadData.Sensor.TcTemp[1].Value = 25;
HeadData.Sensor.TcTemp[2].Value = 25;
__HAL_UART_ENABLE_IT(&huart6, UART_IT_IDLE);
HAL_UART_Receive_DMA(&huart6, Rs422RxData.Char, 32);
/* Infinite loop */
for(;;)
{
Event = osSignalWait(1, 2000);
if(Event.status == osEventSignal)
{//接收到一帧数据
osMutexWait (MutexGetTempHandle, 3);
if((Rs422RxData.Sensor.Head == 0x4c)
&& (crc16(Rs422RxData.Char, HeaterComm.DataLength - 2) == Rs422RxData.Sensor.Crc))
{
HeadData.Sensor.NtcTemp = Rs422RxData.Sensor.NtcTemp;
for(uint8_t i=0; i<3; i++)
{
HeadData.Sensor.TcTemp.Data = Rs422RxData.Sensor.TcTemp.Data;
// HeadData.Sensor.TcTemp.Value = Rs422RxData.Sensor.TcTemp.Value;
}
HeaterComm.CommStatus = 1;
}
else
{
TestData++;
// HeaterComm.DataLength = 0;
}
HeaterComm.DataLength = 0;
osMutexRelease (MutexGetTempHandle);
HAL_UART_Receive_DMA(&huart6, Rs422RxData.Char, 32);
}
else
{//接收超时
HeaterComm.CommStatus = 0;
}
xEventGroupSetBits(xCreatedEventGroup, EVENT_BIT_HEATER_COMM_TASK);
osThreadYield();
}
/* USER CODE END HeaterCommTask */
}
一周热门 更多>