I'm hoping someone can help point me in the right direction to solve a problem I'm having with reading serial data from an external device.
The device outputs 6 bytes of data via serial that I need to interpret. The device sends at 19200 baud with 8N1. The serial data packets are organised as 16 bit words in big endian order.
When I connect the device to a PC and use Realterm to see the data in Hex form I get exactly what I'm supposed to and it looks like this:
B2 82 5B 13 00 02
When I connect the device to an ESP32 Dev board and run the simple code below I get 6 bytes but they look like this:
93 9F 2A F7 FB 00
At first I thought it was an endian issue but swapping bytes around doesn't help here. Any help with explaining why the data is so different on the ESP32 would be greatly appreciated.
My code:
Code: Select all
int LC2bytePOS = 0;
byte LC2msg[7];
void setup() {
Serial.begin(115200);
Serial1.begin(19200, SERIAL_8N1, RXD1, TXD1); //Setup the Lambda (LC-1) serial UART
}
void loop() {
char LC2byte;
while (Serial1.available() > 0) {
LC2byte=Serial1.read();
if (LC2byte == 0x93) { // Should be B2 but lets go with this as a header byte for now
LC2msg[0] = LC2byte; // Start building the message from the beginning
LC2bytePOS = 0; // Reset byte counter
Serial.print("\n\r");
}
else {
LC2bytePOS++;
LC2msg[LC2bytePOS]=LC2byte; // Add the byte to the message
if (LC2bytePOS > 6) {LC2bytePOS=6;}
}
Serial.printf("%02X ", LC2byte);
}
}