Inconsistent data readings

Hey,

I am not sure if this is the correct forum, or perhaps "Networking, Protocols, and Devices" since this may be a protocol issue.

I'm using an Arduino Pro Micro (https://www.sparkfun.com/products/12640) to communicate with my car's radio unit.
The protocol is called MELBUS and is detailed here - http://volvo.wot.lv/wiki/doku.php?id=melbus
Using this code - GitHub - archi/melbus: Implementation of a node for MELBUS, as used in older Volvo cars.
I am able to read data from the radio unit but the problem is that I keep on getting different readings.
For example:
The radio unit sends a broadcast to all connected devices to query the kind of device connected.
To do that, the radio unit will send this sequence: 0x07, 0x1a, 0xee
The problem is that I am receiving all kinds of variations of this:
0x07, 0x1a, 0xef
or
0x07, 0x2a, 0xee
or
0x07, 0x2b, 0xee
or
0x07, 0x2b, 0xef

As you can see, the difference is usually around 1-2 bits. (Its weird that the first byte usually doesn't get screwed up..)
Since the data seems synced (bits are in the correct place and are not missed, a byte is read successfully), I don't think it has anything to do with the clock pin and because usually there seems to be extra 1 bits I am thinking that the logic level of the data pin is too high for my arduino.
Measuring the voltage on the pins from the radio unit I get a range of 0-4.7V which should be within the range the arduino will read 0 and 1.
Am I wrong here? Should I put a pull up or pull down resistor? A capacitor maybe? A regulator maybe?
Currently I connected the arduino directly to the radio unit pins without any electronics in between.

Has anyone had a similar problem? Where extra 1 bits appeared when reading data?

(It would be very helpful if someone could also explain why this is happening and why the solution would help)

Thanks alot in advance!

Shtutnik:
Should I put a pull up or pull down resistor? A capacitor maybe? A regulator maybe?
Currently I connected the arduino directly to the radio unit pins without any electronics in between.

Yeah.....maybe. Should certainly try pull-up resistors. Arduino does have software controlled pull-ups.

Also put a big electrolytic capacitor from the 5V pin of the arduino to the GND pin. This is all to cut down on noise issues.

Firstly post your code - you might have done something silly that's easy to spot.

Secondly without seeing 'scope traces its very hard to diagnose something like this. You are in
an automotive environment so noise and interference are likely to be harsh. You probably need
to terminate the signals correctly - which will depend on the nature of the bus, which unfortunately
that webpage says nothing about.

Your problem is not pullups I think you didn't get what happens.
You hold the busy line low for one sec then send what you are tape deck cd changer et,
If that didn't happen the radio just ask different ones till it does get a reply.

Set BUSY to low for 1000 ms to make the HU run its initialization routine
The HU init routine starts by sending three bytes: 0x07 0x1A 0xEE
Then two bytes per optional connection device (~30 of them), the first byte being the predefined ID of the device (ex. CD-CHGR = 0x8E), followed by either an empty byte 0xFF, if the device is not connected, or the answering ID of the device (CD-CHGR = 0xEE)

Example: External CD-CHGR: ID = 0x8E and its return ID is 0xEE
Example: Internal CD-player: ID = 0x80 and its return ID is 0x86
See list of predefined addresses and returns on bottom of this site.
I.e. to simulate a connected CD-CHGR we have to:
Trigger the HU init routine
Wait until HU is sending out our ID (0x8E)
Respond to that by sending back 0xEE
Now the HU has registered that we have a CD-CHGR and it is now available through the source-knob, and will listen to the Left and Right Audio pins on the DIN-plug.
Every time the car ignition is turned on, the HU will automatically run a secondary initialization routine:
Starting by sending four bytes: 0x00 0x00 0x1C 0xED
Then two bytes per already registered connection devices from the first init routine, the two bytes follows the same pattern as in the first init routine, first ID, than expecting the same answering byte as before.
If the HU won't get an answer from the CD-CHGR, the device will be removed, and we have to set BUSY low again to call the first init-routine.

Shtutnik:
For example:
The radio unit sends a broadcast to all connected devices to query the kind of device connected.
To do that, the radio unit will send this sequence: 0x07, 0x1a, 0xee
The problem is that I am receiving all kinds of variations of this:
0x07, 0x1a, 0xef
or
0x07, 0x2a, 0xee
or
0x07, 0x2b, 0xee
or
0x07, 0x2b, 0xef

Also, try to be specific about what you describe. If you say you are broadcasting 3 bytes, and then you say 'receiving' variations, then you should say WHAT is receiving....... ie... the broadcast unit receiving the responses? Or each of the other units are receiving variations of the transmitted message sequence? I'm assuming that you mean the remote (other) devices are receiving variations of the 3 bytes.

Thank you guys for your answers. I'll try to answer you all.

Southpark:
Yeah.....maybe. Should certainly try pull-up resistors. Arduino does have software controlled pull-ups.

Also put a big electrolytic capacitor from the 5V pin of the arduino to the GND pin. This is all to cut down on noise issues.

Thanks! Will try that, just wondering if from your experience you think that adding a capacitor will make that much of a difference in the data read?

MarkT:
Firstly post your code - you might have done something silly that's easy to spot.

Secondly without seeing 'scope traces its very hard to diagnose something like this. You are in
an automotive environment so noise and interference are likely to be harsh. You probably need
to terminate the signals correctly - which will depend on the nature of the bus, which unfortunately
that webpage says nothing about.

I am using the exact same code as here: GitHub - archi/melbus: Implementation of a node for MELBUS, as used in older Volvo cars.
I also tried different variations of code from other projects, all of them resulted in the same problem - I am receiving different readings.
You are probably very right about the noisy environment.. I wish there was better documentation of this bus. What kind of terminations can I try?

be80be:
Your problem is not pullups I think you didn't get what happens.
You hold the busy line low for one sec then send what you are tape deck cd changer et,
If that didn't happen the radio just ask different ones till it does get a reply.

Thanks, actually I am able to send back commands and it seems that it responds to my answers. The problem is that I get inconsistent readings which make it very difficult to work with.
I am working with code that wasn't written by me, but I have also gave it a try several times with different variations. I suspected that maybe something with the interrupt handling is incorrect, but I believe that its not that since the code seems to work for several people. I really think the problem is with the connections. Too bad no one supplied the wiring diagrams..

Southpark:
Also, try to be specific about what you describe. If you say you are broadcasting 3 bytes, and then you say 'receiving' variations, then you should say WHAT is receiving....... ie... the broadcast unit receiving the responses? Or each of the other units are receiving variations of the transmitted message sequence? I'm assuming that you mean the remote (other) devices are receiving variations of the 3 bytes.

Hi, the broadcasting is done by the radio unit, not me. I am receiving different readings of that broadcast (and everything else that the radio unit is sending).

Again, thank you all for helping! I appreciate it

Southpark:
Yeah.....maybe. Should certainly try pull-up resistors. Arduino does have software controlled pull-ups.

Also put a big electrolytic capacitor from the 5V pin of the arduino to the GND pin. This is all to cut down on noise issues.

So I tried doing this, but unfortunately it didn't help :frowning:
Also, pull-ups wouldn't be needed on the data pin right? I am a bit confused about the pull-ups. They are good if you need a constant logical 1 on the input pin of the arduino, right? But I don't think that is what I need here..

I am getting the feeling that the problem is that when the radio unit writes a logical 0 on the data pin, sometimes it gets over the maximal voltage for reading a logical 0, hence a logical 1 is read.
Could this be it? If so, how could I make sure that a logical 0 from the radio unit will read 0 by somehow lowering the voltage of the data pin?

The best thing to start with is make sure the supply to the Arduino is properly bypassed (both electrolytic and smaller ceramic caps), make sure the grounds are correctly connected to the radio ground not somewhere else in the car - you will get noise (the automotive environment is actually very noisy). Get a scope trace of what the signal from the radio looks like with DC coupling on the scope, not AC so that you can see just what a "1" and "0" look like. Without knowing what the signal looks like, it is just taking shots in the dark trying to solve the problem. Signal conditioning is key in something like the automotive environment - there can be all sorts of strange transients and garbage floating around and the grounds are somewhat suspect - the frame is NOT the same as the engine block which is NOT the same as the battery negative terminal etc. They may be connected, but there are all sorts of transients depending on loads etc. that will be present at those places which is why your ground needs to go to the radio ground to help eliminate some of the garbage.