For the CAN bus, is it OK to swap CANH and CANL lines?
I couldn't find any reference that gave a definitive answer. But looking at a few datasheets, I don't think so. USB is looking at the presence or absence of a change in voltage. Whereas CANBus is looking at the voltage itself.
Here is an example of a USB transmission:
The ones and zeros are coded depending on whether or not there is a transition.
As opposed to CANBus which takes the difference in the voltage levels as seen in this app note:
If we look at a datasheet for a CANBus transceiver, for example the MCP2551, we see something along the lines of:
Sym Characteristic Min Max Units
VDIFF(r)(i) Recessive differential input voltage -1.0 +0.5 V
VDIFF(d)(i) Dominant differential input voltage 0.9 5.0 V
Since a negative voltage is mentioned, this leads me to believe that polarity is important and they are not taking the absolute value of the differential voltage.
So if we have:
$$CANH = 2.5V$$ $$CANL = 2.5V$$
Normally the transceiver would do:
$$CANH - CANL = 2.5V - 2.5V = 0.0V = Recessive$$
If you swapped the lines it would do:
$$CANL - CANH = 2.5V - 2.5V = 0.0V = Recessive$$
So far so good. The problem comes when we have:
$$CANH = 3.5V$$ $$CANL = 1.5V$$
Here, the transceiver would normally do:
$$CANH - CANL = 3.5V - 1.5V = 2.0V = Dominant$$
If you swapped the lines it would do:
$$CANL - CANH = 1.5V - 3.5V = -2.0V = Recessive (out\ of\ spec)$$
So you the receiving end would see nothing but recessive bits.
Swapping CAN-High and CAN-Low lines does not work. This is easy enough to establish empirically. I and my coworkers sometimes swap the lines by accident, and it is immediately apparent that it does not work.