# Wrong data displayed from UART connection

I have trouble displaying a certain hex string on an LCD. The hex string comes from a external display device that communicates with a serial display.

With the oscilloscope, the data from the display looks like this: 5A A5 20 81 00 80 28.

I have an USB-RS232 connector like in this datasheet:

https://www.ftdichip.com/Support/Documents/DataSheets/Cables/DS_US232R-10_R-100-500.pdf

With this cable, I could see the correct hex data in the RealTerm serial terminal on my PC.

However, when I want to display the hex string on a LCD display with a PIC microcontroller, to test if the connection is correct, I get the following hex string: "58d5eefdfdd7 0a9..." (I'm not sure if more data is following, because the LCD doens't have more space to display).

The display wires are connected directly to the PCB with the PIC and the LCD.

I use MCC. The baud rate of the PIC matches the display (9600). I get the same result regardless of the choosen data polarity in MCC(inverted or noninverted). I think that is all the relevant settings.

I use the following code fragment:

while (1)
{
{
char hex[2];
sprintf(hex, "%2x", tmp);
Lcd_Write_String(hex);
}
}


So I get data coming from the display. Those 58 and D5 seem to be related to 5A and A5. It is as if there is some pattern to the errors, but I fail to see it.

• Two characters is not enough to hold a string with two characters as there is no room for null terminator. It may overwrite something in the stack or something may overwrite the null terminator so the string can be arbitrarily long so it never terminates. – Justme Aug 16 '20 at 14:52

10110001101010111101110111111011111110111010111 = 58d5eefdfdd7

10110101010010100100000100000010000000010 = 5A A5 20 81 00 80 28

Try 1’s complement

10110101010010100100000100000010000000010

... fe956b7dfbfd

No correlation

but looks bit wise inverted and glitch on byte sync. Or ?

Investigate for reasons

• I couldn't really follow you HEX -> binary translation? – Mike Aug 18 '20 at 5:35
• The spacing and number of ‘0’ ‘s in your 1st binary string matches the same of mentally inverted ‘1’s in the second string match yet the Hex does not match, so it is out of sync and inverted . Why? – Tony Stewart EE75 Aug 18 '20 at 13:39