How do I create a 12v K-BUS sim?

Hey Guys,

For a car project I wanted to create a test bench so I can test at my desk instead of having to sit in my car all the time.

It's a simple send - receive test which works fine when in the car.
2 Arduino nanos both with a TH3122.4 tranceiver. (also converts 12v to 5v).

When I hook up the wires in the car, all is fine. Messages are being sent and received on the other side.

On my testbench however, neither of the Arduinos receive messages.
I'm guessing this is because of the canbus wire not having the right voltage.

I simply bridged the 12v from power supply to the canbus wire, as the canbus in the car is also 12v.
Is there a way of getting a stable 12v on the canbus wire so the communication between both Arduinos will work?

I don't know much on the physical side of how these things work, unfortunately.
Should I use a capacitor or something like that?

Hoping someone can help me out!

Hi,

CAN usually uses two wires for data CAN High and CAN Low, which are a differential twisted pair and ground. There are other optional ground and power wires are sometimes connected too, if the CAN transceivers you're using require it. On a 9-way d-type connector, the pinout is usually as follows:

2 CAN_L
3 GND
5 Cable shield (Optional)
6 GND (Optional)
7 CAN_H
9 Power (Optional)

You also need some termination, which is a 120ohm resistor across CAN_H and CAN_L, either in the connector or on the board between connector and transceiver. The first option can be more flexible, because it allows you to add and remove terminating resistors depending on your setup.

For 2 devices on a bench connected with a short cable a single 120ohm resistor at one end of the cable should do it.

Note: this is all for standard CAN, I don't know how K-BUS differs, if it does.

Hi there rstro,

Many thanks for replying.
What I do now about K-BUS is that (in this sepcific car, BMW E46) it's just 1 wire.
When connecting a multimeter to it in the car, it reads 12v.

So I guess it 'should' be a simpler setup than a real Can which has multiple wires.

Well, I added a 100 ohm resistor and two 10ohm resistors and it's working great now!
Only thing left for me to do is fixing the fact that message that were just sent pop up as 'received' messages on the same device. But that shouldn't be to hard.

Many thanks for your help rstro!

One last question (probably a dumb one). How is it that adding 120ohm resistance fixes the issue?

One last question (probably a dumb one). How is it that adding 120ohm resistance fixes the issue?

That may not be the correct value.

Turn off the power and measure across CAN-H and CAN-L to see if it is 120 ohms or 60 ohms.

CANBUS requires TWO termination resistors (NOT ONE). One should be at the transmitter end and the other at the furthest end of the CANBUS. Measuring the termination resistance can be tricky
because sometimes the termination resistor on the transmitter (MASTER) is an active resistor that is
enabled when the system has power (think resistor separated by an analog switch that gets turned on
when power is applied). Thus, you might measure 120 ohms with power off but it might actually be 60 ohms with power on. It can't hurt to check. If you measure 120 ohms , try adding another 120s at the opposite end. (if you put the 120 ohms closest to the transmitter, add the other 120 ohms at the receiver.
If it works with both of them then leave them both on. If it only works with the first one you added , then
remove the second one. All CANBUSes operate with one at each end and as you know , two 120 ohm resistors in parallel is 60 ohms.

This is true:

For 2 devices on a bench connected with a short cable a single 120ohm resistor at one end of the cable should do it.

Meaning it might work fine with a short cable but not with a 100 meter cable. If you extend the cable and it doesn't work that means you need to add the second resistor at the OPPOSITE end from where you put the first one. (for non-electronics people, this means you CANNOT put them both in the same place !)

raschemmel:
Meaning it might work fine with a short cable but not with a 100 meter cable. If you extend the cable and it doesn't work that means you need to add the second resistor at the OPPOSITE end from where you put the first one. (for non-electronics people, this means you CANNOT put them both in the same place !)

Absolutely, you might need a bit of trial and error to get it working in the vehicle, but it sounds like he's got some comms there already and it was the bench setup that was the problem.

LuckHermsen:
Only thing left for me to do is fixing the fact that message that were just sent pop up as 'received' messages on the same device. But that shouldn't be to hard.

You're right, you probably just need to configure a receive acceptance filter for the messages you're interested in. There may be some sort of "source node ID" built into the message ID, so you could use a mask to filter out nodes from your own ID.....or something! You'll work it out, all depends on the design of the data on the bus.

LuckHermsen:
One last question (probably a dumb one). How is it that adding 120ohm resistance fixes the issue?

Not a dumb one at all, I have a limited understanding of 'why' myself apart from it reduces signal reflections on the cable. I am an embedded software engineer so have some practical electronics experience but lack a lot of theory. This wikipedia article explains in great depth if you really want to know more! Reflections of signals on conducting lines - Wikipedia

Cheers,
Richard

rstro:
You're right, you probably just need to configure a receive acceptance filter for the messages you're interested in. There may be some sort of "source node ID" built into the message ID, so you could use a mask to filter out nodes from your own ID.....or something! You'll work it out, all depends on the design of the data on the bus.

Got it working bny filtering on Source ID, thanks!

rstro:
Reflections of signals on conducting lines - Wikipedia

This was a good read!

Many thanks for all the help!!