Tag: 串口通信

UART ISR Tx Rx架构

我让事情复杂化了吗? 我正在设计我的代码,通过UART从8051微型到外围设备进行通信。 外设响应来自主机的命令,并且一次只能响应一个命令。 这是一个简单的发送和接收协议。 (tx1,rx1,tx2,rx2,tx3,rx3)每个TX消息以CR终止,每个响应以>终止。 在收到对最后一个的回复之前,我无法发送新消息。 如果我启用该选项,响应也可以在回显打印原始TX消息(但这会导致更多流量) 一个示例消息是: 德克萨斯:你好 RX:世界!> 或者使用echo选项…… 德克萨斯:你好 RX:你好\ rWorld!> 选项A getHello等函数由发送和接收组成。 并行ISR例程将收集传入的字节,并在收到“>”字符时抛出一个标志。 char* getHello(char * buf){ sendMsg(“Hello\r”); delay(10ms); //wait a little bit //wait for receive to come in or timeout to occur while(!receiveFlag || !timeoutFlag); //thrown by ISR receiveMsg(buf); //parse the message and do some other stuff return buf; } […]