写STM32F03C8T6单片机串口中断服务函数(接收的一帧数据并判断是否正确);
时间: 2023-03-15 19:59:31 浏览: 123
void USART_IRQHandler(void)
{
static uint8_t rx_buffer[RX_BUF_SIZE];
static uint16_t rx_index;
uint16_t rx_data;
if (USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)
{
/* Read one byte from the receive data register */
rx_data = USART_ReceiveData(USART1); if (rx_data != 0x0d)
{
rx_buffer[rx_index++] = rx_data;
}
else
{
rx_buffer[rx_index++] = '\0';
rx_index = 0; if (VerifyChecksum(rx_buffer) == true)
{
/* the frame is correct */
}
else
{
/* the frame is incorrect */
}
}
}
}
阅读全文