Trying to read signals from Jaguar XK8 (ISO 9141-2)

Hi,
I can’t get my head around this. For the last few days i tried to read the signals for my jaguar but i don’t get any signals back.

I’m using the library OBD9141 from Iwanders, heres the link for it https://github.com/iwanders/OBD9141.

And the code i found att Macchina website which i have changed a little bit so i do not need to use the samNonDuePin library.

Here is the code.

/*
 *  Example based on code found here.
 * https://github.com/iwanders/OBD9141
 * 
 * Put the "OBD9141 in Libraries folder.
 * 
*/

#include "OBD9141.h"


// The RX pin of the Serial1 connected to 9141 K RX of tranciever.
#define RX_PIN LIN_KRX

// The Tx pin of the Serial1 connected to 9141 K TX of tranciever.
#define TX_PIN LIN_KTX

// The Enable pin connected to 9141 SLP pin of tranciever.
#define EN_PIN LIN_KSLP

#define OBD9141_DEBUG

OBD9141 obd;

void setup(){
    SerialUSB.begin(115200);
    delay(2000);

    pinMode(EN_PIN, OUTPUT);
    digitalWrite(EN_PIN, HIGH);

    obd.begin(Serial1, RX_PIN, TX_PIN);
}
    
void loop(){
    SerialUSB.println("Looping");

    obd.set_port(false);
    bool init_success =  obd.init();
    SerialUSB.print("init_success:");
    SerialUSB.println(init_success);

    // init_success = true;
    // Uncomment this line if you use the simulator to force the init to be
    // interpreted as successful. With an actual ECU; be sure that the init is 
    // succesful before trying to request PID's.
    

    if (init_success){
        
        bool res = true;
        while(res){
            SerialUSB.println(obd.readUint8());
            res = obd.getCurrentPID(0x11, 1);
            if (res){
                SerialUSB.print("Result 0x11 (throttle): ");
                SerialUSB.println(obd.readUint8());
            }
            
            res = obd.getCurrentPID(0x0C, 2);
            if (res){
                SerialUSB.print("Result 0x0C (RPM): ");
                SerialUSB.println(obd.readUint16()/4);
            }


            res = obd.getCurrentPID(0x0D, 1);
            if (res){
                SerialUSB.print("Result 0x0D (speed): ");
                SerialUSB.println(obd.readUint8());
            }
            SerialUSB.println();

            delay(200);
        }
    }
    delay(3000);
}

I do not really know what i’m doing wrong here. But the init function doesn’t seem to work for me, it’s probably something I’m missing.
Any help is really appreciated.

Hey @dag, looks like you have the right code for this project. Couple things to check right away:

  1. Double check you need ISO9141. What year is your Jag anyway?

  2. Make sure your M2 hardware has the TJA1027 transceiver on it. Learn more about that issue here:

If you have a TJA1021, get in touch and we’ll swap it out for you.

Once you get it working, it should look like this:

My Jaguar is from 1998 and it should be the protocol 9141, at least according to this manual at page 60-61 http://www.jagrepair.com/images/Training%20Guides/682%20Adv%20Electrical%2002-20-02.pdf. It does say it has multiple protocols for some reason but I’m only interesting in the serial data link (9141), because that’s were the ac module is hooked up to.

I check the chip and it’s the TJA1027.

I also installed the “SamNonDuePin.h” library and selecting board “Arduino Due (Native USB Port)” and used the code from here

But that didn’t do any different.

I added this

 #define OBD9141_DEBUG
 #define ARDUINO_SAM_DUE

to the “OBD9141.h” library this see the debug log.
What i get then is this

Looping
Before magic 5 baud.
Before setting port.
After setting port.
Timeout on read 0x55.
init_success:0

it’s like it doesn’t get any connection to the k-line at all.

I starting to think that the k-line is broken on the obd2 port, i should probably test and see if i actually get any voltage from the k-line.

We did a little testing on this today. With “Macchina M2” board selected, I was only able to get the below code to work after changing lines 23, 30 in “ODB9141.cpp” and line 77 in “OBD9141.h” to:

#ifdef MACCHINA_M2

For some reason, adding “#define ARDUINO_SAM_DUE” to the main sketch and not changing the original library didn’t work. Anyone have any ideas here?

I got similar result.
In case of Macchina hardware, 9141 K TX line is connected to Port A11 of SAM3X8EA. The definition in SamNonDuePin.h, line 55 is “static const uint8_t PIN_EMAC_ETX1 = 18;”. In SamNonDuePin.cpp index 18 is declared as “{ PIOB, PIO_PB3A_ETX1, ID_PIOB, PIO_PERIPH_A, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // ETX1”
as Port B3. That means slow init procedure will not work as input TXD of U7, TJA1027 remains untouched.
@josh and dag, can you confirm?
Rgds
J.

I manage to drive the 9141KTX-line by adding " { PIOA, PIO_PA11, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // TXD1, 9141KTX, Macchina J3 Pin 26 " in SamNonDuePin.cpp and “static const uint8_t PIN_9141KTX = 26;” in SamNonDuePin.h.

" pinModeNonDue(PIN_9141KTX, OUTPUT);
digitalWriteNonDue(PIN_9141KTX, HIGH);"

Above lines drive pin 26, 9161KTX, connector J3 at Macchina interface to high level.

OBD9141 lib is not ready for K-Line macchina-hardware.
Rgds
J.