stm32f103 hal库写串口2的时候,发现只可以发送但不能接收
再检查了cubemx配置无误后
发现,并没有打开中断:
因此我采用:在
void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle)
这个函数中加入
__HAL_UART_ENABLE_IT(uartHandle, UART_IT_RXNE); /* 使能UART接收中断 */
__HAL_UART_ENABLE_IT(uartHandle, UART_IT_IDLE); /* 使能UART总线空闲中断 */
这两句。
但我看到在很多代码中,有这种加法,现在main.c文件中加入:
uint8_t aRxBuffer; //接收中断缓冲
uint8_t Uart1_RxBuff[256]; //接收缓冲
uint8_t Uart1_Rx_Cnt = 0; //接收缓冲计数
uint8_t cAlmStr[] = "数据溢出(大于256)\r\n";
HAL_UART_Receive_IT(&huart1, (uint8_t
-
/* USER CODE BEGIN 4 */ /** * @brief Rx Transfer completed callbacks. * @param huart pointer to a UART_HandleTypeDef structure that contains * the configuration information for the specified UART module. * @retval None */ v