Arduino + L9637 K-Line reader - getting 10400 baud on SoftwareSerial

Hi,

So I know this question has been asked many times before, but all of the threads I have found seem to pre-date the current SoftwareSerial library, in which afaik any baud rate is possible unlike before.

So I currently have the L9637 Monolithic Bus Driver connected to pins D0 and D1 of my Arduino Uno. I am trying to create an ECU reader to communicate with my car over the KW1281 protocol, and from testing I have discovered I need to do the 5 Baud Init and then communicate at 10,400 baud.

First off I want to say I have successfully managed to run the 5 baud init. Now, I realise the pins (D0 & D1) are capable of Hardware Serial, however when trying to use the hardware serial I couldn't get any connection to the car. So I have decided to use the SoftwareSerial library for the following 10,400 baud communication.

With this library I successfully receive three (incorrect) response bytes from the ECU when setting a baud rate of 9600, however the response bytes - despite being correct in the number of them (3) - are wrong in terms of their value and seem to just be zero values.

Now as my car requires 10,400 baud communication, I instead setup the serial port to 10,400 baud (serialinstance.begin(10400)). I know from experience that using 9600 baud will give incorrect response bytes and 10400 baud solves this. So I expected this would work, however it didn't, I still got 3 bytes containing 0. Just to be clear the three correct values should be: 55 01 8A

So I was wondering:

  1. Am I right in assuming the SoftwareSerial library will work for any baud rate, even 10,400?
  2. If yes to point 1, can anyone suggest why I might be getting data bytes containing 0 instead of the correct values?

Thanks,
James

P.S. The full code I am using is attached, it's a bit messy at the moment as I'm just trying to get it working, but basically I have some code in the KWPReceiveBlock function (called from the connect function after the 5 baud init is completed) that prints the data returned by the ECU to my TFT display.

obd_reader.ino (26.4 KB)

  1. Am I right in assuming the SoftwareSerial library will work for any baud rate, even 10,400?

Yes, the SoftwareSerial library tries to match almost any baud rate but if your device is picky about baud rates don't use the software emulation because the actual baudrate will vary considerably when using it.
The hardware serial interface is also capable of using almost any baudrate but it is much more exact in holding that rate. So it's a very bad idea to use the crippled SoftwareSerial instead of the hardware interface if you're not forced to that.

  1. If yes to point 1, can anyone suggest why I might be getting data bytes containing 0 instead of the correct values?

I guess that you don't get any answer from the ECU. Did you check with a scope or a logic analyzer that you really get an anything?

Thanks for your reply, and with regards to the software serial functions I'll bear that in mind.

However for the ECU response I have now changed the code to communicate with the address of the engine rather than the instrument cluster and now I do get a response it's just he ECU seems to reply with the wrong values.

The ECU responds with 3 bytes exactly (as it should) of 0x00 0x00 0x55. However the correct values should be 0x55 0x01 0x8A. So I do know that the hardware is fine and the signals are being transmitted. I imagine my problem now is more of a K-line specific problem...

Okay so just some more information and an update. I don't think this is a problem with my hardware setup or communication code. I believe my issue is due to the software serial not getting an 'exact' baud of 10400, because I have read somewhere if the baud is too high I will get 0x00 or 0xFF bytes.

I have tried using the hardware serial however with this I get no response, and I have verified the correct settings of RX/TX by trying both possibilities in terms of the wiring. I'm not sure why this happens but I believe it's because I have to change the pin mode of the TX pin to an output to do the initial 5 baud init, prior to then setting it to a serial port at 10400 baud. I believe the hardware serial pins don't like the pin modes to be changed.

And so I have decided the next thing I will try is to use the NewSoftwareSerial header provided by the original author of the k-line obd code in which they have hard coded timing values for 10400 baud which they have confirmed work for them. Hopefully I can test this tomorrow and see if this implementation of software serial works.

1 Like