在CUBEMX上生成LIN模式的代码,增加了一些代码(如下),通过逻辑分析仪看LIN上的信号是正常,现在的问题就是无法接收到指定字节的数据:发送和接收都是用的中断。
下面是main50ms调度首次的主节点发出的数据,这里OK。- case 0:
- LIN_RPID = 0xB1;
- //TstLin1_MASTER_SendBuff[0] = 0x31;
- TstLin1_MASTER_SendBuff[0] = 0x03;
- TstLin1_MASTER_SendBuff[1] = 0x0A;
- TstLin1_MASTER_SendBuff[2] = 0xFC;
- TstLin1_MASTER_SendBuff[3] = 0x00;
- TstLin1_MASTER_SendBuff[4] = 0x04;
- TstLin1_MASTER_SendBuff[5] = 0x00;
- TstLin1_MASTER_SendBuff[6] = 0x00;
- TstLin1_MASTER_SendBuff[7] = 0x00;
-
- sum = LIN_RPID;
- for(ix = 0; ix < 8; ix++)
- {
- sum += TstLin1_MASTER_SendBuff[ix];
- if(sum & 0xFF00)
- {
- sum = (sum & 0x00FF) + 1;
- }
- }
- sum ^= 0x00FF;
- TstLin1_MASTER_SendBuff[8] = (uint8_t)sum;
- while(HAL_LIN_SendBreak(&huart1 ) != HAL_OK );
- while(HAL_UART_Transmit_IT(&huart1, &lin_data1 , 1) != HAL_OK);
- while(HAL_UART_Transmit_IT(&huart1, &LIN_RPID , 1) != HAL_OK);
- while(HAL_UART_Transmit_IT(&huart1, TstLin1_MASTER_SendBuff , 9) != HAL_OK){}
- //while(HAL_UART_Transmit_IT(&huart1, (uint8_t *)sum , 1) != HAL_OK);
- //Lin1MASTER_SendDataStream(TstLin1_MASTER_SendBuff, 4, TstLin1_Master_Cks);
- TstLIN1_MasterCnt++;
- break;
复制代码再50ms后发送从机的PID,并开启接收中断。
- case 2:
- LIN_RLEN = 9;
- while(HAL_LIN_SendBreak(&huart1 ) != HAL_OK );
- while(HAL_UART_Transmit_IT(&huart1, &lin_data1 , 1) != HAL_OK ); //发55
- while(HAL_UART_Transmit_IT(&huart1, &lin_data2 , 1) != HAL_OK ); //发PDI
- while(HAL_UART_Receive_IT(&huart1, Lin_Buff, LIN_RLEN) != HAL_OK );//开中断
- TstLIN1_MasterCnt++;
- break;
复制代码中断回调函数如下。
- void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
- {
- uint8_t ls_data,i;
- if(huart ->Instance == USART1)
- {
- for(i=0;i<LIN_RLEN ;i++)
- {
- Lin_Data [i] = Lin_Buff [i];
- }
- Lin_Cont_EN = 1;
- }
- x++;
- }
复制代码其他代码均没有作修改的,现在就是收不到指定字节的数据,通过DEBUG下偶尔可以看到Lin_Buff有一个字节的数据在变化,下面贴出LIN从机回复的PDI波形。
下面是主机发出的数据
各位大神看是哪里的问题呀,谢谢!
一周热门 更多>