generated from hulk/gd32e23x_template
完成串行数据通信协议
This commit is contained in:
@@ -132,9 +132,18 @@ void USART0_IRQHandler(void) {
|
||||
|
||||
// 检查是否接收到换行符,表示指令结束
|
||||
if (received_data == '\n') {
|
||||
// rx_buffer[rx_index] = '\0'; // 添加字符串结束符
|
||||
process_command(rx_buffer, rx_index); // 处理指令
|
||||
rx_index = 0; // 重置缓冲区索引
|
||||
if (calculate_crc(rx_buffer, rx_index - 2) == rx_buffer[rx_index - 2]) {
|
||||
// printf("CRC check success\r\n");
|
||||
// rx_buffer[rx_index] = '\0'; // 添加字符串结束符
|
||||
process_command(rx_buffer, rx_index); // 处理指令
|
||||
rx_index = 0; // 重置缓冲区索引
|
||||
} else {
|
||||
// printf("CRC check failed\r\n");
|
||||
printf("%c%c%c%c\r\n", 0xB5, 0xF2, 0x00, 0xF2);
|
||||
rx_index = 0; // 重置缓冲区索引
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user