STM32学习笔记——串口通信 STM32新手一枚,记录一下学习过程。 采用USART进行通信——其中接收采用接收中断的方式。
#include
"usart1.h"
#include
"stm32f1xx.h"
unsigned char usart1_rev_buf
[max_rec_lenth
]={0};
unsigned char usart1_temp
[rec_lenth
]={0};
unsigned int usart1_rx_cnt
=0;
void HAL_UART_RxCpltCallback(UART_HandleTypeDef
*huart
)
{
usart1_rev_buf
[usart1_rx_cnt
++]=usart1_temp
[0];
HAL_UART_Transmit(&huart1
, (uint8_t
*)usart1_rev_buf
, 1, 100);
HAL_UART_Receive_IT(&huart1
, (uint8_t
*)usart1_temp
, rec_lenth
);
}
实验结果