完成串行数据通信协议

This commit is contained in:
2024-12-24 09:32:33 +08:00
parent dc8bff918d
commit 5838f18742
3 changed files with 57 additions and 24 deletions

View File

@@ -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;
}
}
}
}