Maybe I should not seek help from here, but I don’t know that where to discuss the problem.
I use stm32l476rg and five serial ports in my project.
I use uart4 to connect a device with a private protocol device as I send
HEX(0x)[7E 7E 01 …] and it will return
HEX(0x)[7E 7E 00 30 00 08 27 01 62 98 32 80 08 02 02 53 21 03 19 12 08 47 04 87 22 ], that’s all right.
But actually, it runs as the picture:
the first two bytes are wrong, so I use an RS232 debugger to direct connect my protocol device’s rx pin to the debugger’s rx pin, I see the device have right response, as the picture
Here is my unoptimized program for receiving the data:
size_t Mod_ZJ_Water::readDownloadData(uint8_t *buf, size_t size)
{
uint8_t recCount = 0;
delay(2000); // Wait for the data
while(this->_serial->available() > 0)
{
buf[recCount] = this->_serial->read();
recCount = recCount + 1;
}
return recCount;
}
I don’t know the possible reason to cause it, and would you like to share a good program frame for
receiving the serial data with timeout check?
Thank you very much!