Skip to content

Other stuff

domnulvlad edited this page Aug 6, 2024 · 6 revisions

Running diagnostics on more than one device

Recently, I've had someone ask me if it would be possible to decrease the time it takes to connect to a module, as they needed to diagnose multiple modules at the same time for their project.

Unfortunately, KWP1281 just isn't designed for something like this. Being made for simple diagnostics, there was no reason for the protocol to support multiple devices at once. And, by far, the most time-consuming part of a KWP1281 connection is the 5-baud initialization, which takes a full second. On top of this 1s, if you wish to disconnect from the current module and connect to another one, you have to let the bus settle for another ~1s. If you don't do this yourself, my library will just blindly try connecting and retrying upon failure. So it will probably try to connect, fail, wait one second, try again and connect. Which would take around 3 seconds to connect to another module.

Back to that user's request, their project involved reading measurements from the ECU module and also regularly polling the cluster, in order to get info about which doors are open and display this somewhere.

Their approach of disconnecting from the ECU, connecting to the cluster, disconnecting from the cluster, reconnecting to the ECU (over and over again) makes sense, that is pretty much the only way of doing it without modifications, but, as mentioned above, it will eat way too much time.

So, how could we get over the limitation imposed by the protocol, of only one connection at a time? I have thought about something simple: cutting the target module's K-line wire (cluster in this case), so that it's not connected to the "global" line anymore. Of course, this would mean a regular scan tool would no longer be able to reach it anymore until the wire is reconnected. This could be solved by a toggle switch hidden away somewhere.

Now that our module's K-line is free from the other modules' K-lines, what do we do with it? If you are using the ESP32 platform, it's pretty easy, provided you are comfortable working with FreeRTOS tasks. The example 07.Dual_K-line_test shows how to do exactly this (it has been moved to the KLineKWP1281Lib_ESP32 library).

If you are using a platform where you just can't do multitasking, the next best solution would be to get some other microcontroller which manages that separated module, and sends the processed data back to the main microcontroller using some other more reasonable protocol (Serial, I2C, SPI, etc.). All of this is left as an exercise for the reader.

In conclusion, the best solution for this particular user's project would be to separate their cluster from their car's K-line and change their sketch to implement multitasking, or get another microcontroller to manage the cluster. Then they can have basically instantaneous "door open" warnings while still reading measurements from their ECU.

Clone this wiki locally