串行阅读同步

时间:2020-06-29 13:06:49

标签: c++ c embedded mbed nucleo

我正在使用hc-05模块与Nucleo板进行通讯。但是信息可以以我不想要的方式到达。

void BLE_thread(void){
    char read[0];
    uint16_t command = 0;
    while(1){
        //comm_mutex.lock();
        //comm_mutex.unlock();

        device.fsync();
        device.gets(read,2);
        command = read[0];
        device.gets(read,2);
        command += read[0]<<8;
        pc.printf("bytes = %X\r\n",command);
        read[0] = 0;
    }
}

输出应该是ABCD,但是可能无法预测。

enter image description here

关于如何使输出的接收字节始终保持正确顺序的任何建议?

0 个答案:

没有答案