# Automatic CAN bus termination

I have two CAN busses which are each terminated on each end by a 120Ω resistor, as shown in the diagram below. The CAN bus consists of a CAN high, CAN low and ground connection. To terminate it, a 120Ω resistor connects CAN high and CAN low.

Sometimes I want to use both CAN busses completely separate but in some situations, I want to connect the devices D3 and D4 together, making a single bigger CAN bus.

To connect the two, I need to remove the two resistors R2 and R3 and then connect the CAN bus together. My CAN connection currently terminates in a D-SUB connector X1 (at each end D1, D3, D4, D6) to easily connect other CAN devices. At the same time I have a switch (S1) that will enable or disable the CAN bus termination, as can be seen in the schematic below.

What I want to do is to remove the manual operation of the switch S1 by including something in the D-Sub connector X1. When nothing is connected to it, the terminating resistor R1 will connect CAN high and CAN low. But when I connect another device to the connector X1, the resistor R1 will not connect CAN high and CAN low anymore.

I would appreciate any tips that point me towards a possible solution. I should also mention that connecting and disconnecting any device will happen when everything is powered off and does not need to happen during operation.

## 1 Answer

The first thing you must do is to fix your incorrect connector pin-out and turn it into CAN. DB9 connectors for CAN are widely standardized and professional engineers follow industry standards. You should have CANHI=7, CANLO=2, GND=3.

Once you have turned your pin-out into CAN, the simplest solution might be to buy pre-made DB9 terminators and plug those in whenever you don't connect the buses together. For example these: https://www.kvaser.com/product/kvaser-d-sub-9-pin-120-ohm-termination-adapter-2/ (though Kvaser specifically are ridiculously expensive - there's plenty of 2nd source doing the same thing for a 10th of the price).

Alternatively, you could also connect two pins of the DB9 connector together at each end (to once again violate the standard pin-out...) and then have that signal activate an analog switch, which in turn enables the resistor on that board only. Larger BOM but cheaper external adapters.