Glitching on UART RX line with RS485 transceiver
The idle state of UART RX must be high, not low.
Before a transmission, the UART RX must start cleanly from high level to low level for proper start bit, and after the transmission of the final stop bit that is high, they UART RX line must stay high until the next transmission.
The RS485 tranceiver DO will be high when the bus is idle, i.e. when it is not driven.
So this means that transmitting side must start DI from logic 1 before enabling the transmitter so there is no transition when bus goes from idle to logic 1, and must also leave DI to logic high before disabling the transmitter so there is no transition when bus goes from logic 1 to idle.
When two devices have A and B swapped, and you need to use the XOR inversion, the DO pin will output logic 1 but UART RX side will see incorrect logic 0 until the transmitter gets enabled and the RX goes high (DO low). Then after data is transmitted and transmitter is disabled, the DO will go high when idle, but UART RX will go low, so it will see extra 0x00 with Framing Error.
So basically, whether or not the A&amp;B wires are swapped, the DO output will idle high on an undriven bus, and only the driven bus logic levels are swapped. That is a reason not to swap A&amp;B. Use only connectors that allow for direct A-A and B-B connections, or make the software aware that extra bytes are to be expected when inversion is used.
If the hardware flaws cannot be solved to remove the need for swapping, then you must make software workarounds.
You could lengthen the time how long the transmitter is enabled before first byte is sent, and also lengthen the time how long the transmitter is enabled after the last byte is sent. The last scope picture reveals that you turn off the transmitter immediately when last byte is sent, so there is no proper logic high level for the stop bit. Then the receiver should know that bytes arriving within certain time are valid, and if there is a too long gap between bytes, it must be invalid byte. Even define the packets to have a certain preamble or start of packet indicator, with packet length unless packets are always fixed size. Then you can ignore any bytes received before or after a packet.