CAN bus open circuit detection
I have a PIC18 and I'm trying to detect whether it is connected on the CAN bus or not.
When the PIC is not connected on the bus, and I load the transmit buffers, after setting the TXREQ flag. The transmission does not start. This is also mentioned in the datasheet:
Setting the TXREQ bit does not initiate a message transmission.
However I cannot find a reliable way to detect that the PIC is not plugged into a healthy bus.
Also, no errors in the registers appear.
The only thing I can think of is polling the TXREQ flag for a few milliseconds to check if the peripheral initiated a transmission or not.
But I'm not sure if that is a reliable algorithm. If yes, how much should that timeout be? 1ms or 100ms?
1 answer
There is no direct way to determine whether the PIC is connected to a CAN bus. Part of the problem is that the PIC never directly connected to the CAN bus anyway. There is a transceiver chip like the MCP2551 between the PIC and the bus. The PIC interfaces to the transceiver via two digital signals: CANTX and CANRX.
CANRX indicates the state of the bus, whether it is in recessive (idle) or dominant state. Since it is a digital signal, you only get one of those two indications. There is no way to signal not connected.
CANTX allows the PIC to either drive the bus to the dominant state or leave it alone. Again, it's a digital signal, so you only get those two choices.
The signal levels on the CAN bus itself (CANH and CANL lines) are quite different from digital logic signals. The two lines are passively pulled together by a total of 60 Ω when everything is connected correctly. There is also circuitry in the driver chips to float these signals at a nominal 2.5 V. To signal the dominant state, CANH is pulled high by 900 mV, and CANL low by 900 mV. To "read" the bus, you decide whether the signals are at the same level, or 1.8 V apart. That makes the bus differential, with good common mode noise immunity.
The MCP2551 weakly holds both CAN lines together, so they float at the same voltage when nothing is connected to the CANH and CANL pins. The PIC therefore sees no difference between a bus in the idle state, and no bus connected.
To truly check whether a valid CAN bus is connected to CANH and CANL, you would have to look at their analog levels and test their impedance. This would take additional hardware, and could also interfere with bus operation when there is a real bus connected.
About the best you can do from the PIC without additional hardware is see whether messages are sent successfully. For a message to be sent, there has to no only be a bus connected, but there has to be at least one other node on the bus to respond with ACK to the message. If the PIC sends a message and receives no ACK, then it retries automatically. I don't remember if it gives up after some number of retries to avoid polluting the bus, but either way, this is something you should be able to detect.
1 comment thread