关于freemodbus加入奇偶校验的程序处理办法
基于stm32f4平台HAL库
Modbus RTU/ASCII:
- Parity checking should be used for the characters when received. This
is not strictly necessary because we use CRC or LRC but it is recommended
in the standard
这是frreemodbus v1.6中doc文件中的todo.doc中说明文字
freemodbus推荐使用校验位,所以我在代码中添加了PE(奇偶校验位错误)位的处理程序
void USART1_IRQHandler(void)
{
/* USER CODE BEGIN USART1_IRQn 0 */
uint8_t tmp;
if(__HAL_UART_GET_FLAG(&huart1,UART_FLAG_PE))//PE位置位则丢弃当前字节
{
HAL_UART_Receive(&huart1,&tmp,1,1);
}
else if(__HAL_UART_GET_FLAG(&huart1,UART_FLAG_RXNE)&&__HAL_UART_GET_IT_SOURCE(&huart1,UART_IT_RXNE))
{
prvvUARTRxISR();
}
if(__HAL_UART_GET_FLAG(&huart1,UART_FLAG_TXE)&&__HAL_UART_GET_IT_SOURCE(&huart1,UART_IT_TXE))
{
prvvUARTTxReadyISR();
}
/* USER CODE END USART1_IRQn 0 */
HAL_UART_IRQHandler(&huart1);
/* USER CODE BEGIN USART1_IRQn 1 */
/* USER CODE END USART1_IRQn 1 */
}