串口配置如下:
Uart5_Handle.Instance = UART5;
Uart5_Handle.Init.BaudRate = 115200;
Uart5_Handle.Init.WordLength = UART_WORDLENGTH_8B;
Uart5_Handle.Init.StopBits = UART_STOPBITS_1;
Uart5_Handle.Init.Parity = UART_PARITY_EVEN;
Uart5_Handle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
Uart5_Handle.Init.Mode = UART_MODE_TX_RX;
Uart5_Handle.Init.OverSampling = UART_OVERSAMPLING_16;
Uart5_Handle.MspInitCallback = HAL_UART5_MspInit;
HAL_UART_Init(&Uart5_Handle);
发送数据 01 02 03 04 05
串口助手接收 81 82 20 58 F0
完全对不上,经过2天1夜查找问题,确认需要将8位,改成9位,最后一位是奇偶校验位。
Uart5_Handle.Init.WordLength = UART_WORDLENGTH_9B;
Uart5_Handle.Init.Parity = UART_PARITY_EVEN;
在串口助手上的配置保持不变,8数据位,1停止位,偶校验。
成功解决~~