项目场景:
提示:这里简述项目相关背景:
项目场景:两块板子通过串口进行通信,串口发送芯片为STM32F407VGTx,串口接收芯片为STM32G070RBTx。
问题描述
提示:这里描述项目中遇到的问题:
数据传输过程中发送不成功,也接收不成功。通过串口调试助手打印发送的数据,发现与发送的数据不一致。
STM32F407VGTx发送端:
u8 breath_detectWay;
HAL_UART_Transmit(&huart1,(uint8_t *)breath_detectWay,sizeof(breath_detectWay),100);
STM32G070RBTx接收端:
u8 breath_detectWay;
HAL_UART_Receive_IT(&huart2,(uint8_t *)breath_detectWay,1);
原因分析:
提示:这里填写问题的分析:
HAL_UART_Transmit(UART_HandleTypeDef *huart, const uint8_t *pData, uint16_t Size, uint32_t Timeout)
与HAL_UART_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
函数,发送与接送的是数组,而不是变量将breath_detectWay
定义为数组u8 breath_detectWay[1]
就ok了。
解决方案:
提示:这里填写该问题的具体解决方案:
STM32F407VGTx发送端:
u8 breath_detectWay[1];
HAL_UART_Transmit(&huart1,breath_detectWay,sizeof(breath_detectWay),100);
STM32G070RBTx接收端:
u8 breath_detectWay[1];
HAL_UART_Receive_IT(&huart2,breath_detectWay,1);