LIN Bus communication Uno to Due

Hi All,

I’m trying to get a LIN Bus functioning, actually to listen to messages on a vehicle, but I’ve setup a test bus between a Due and an Uno using MCP2004-E/P Transceivers. (rs Part 715-4549)

The Uno is sending 4 bytes, the Due only ever receives 4 zeros.
If I disconnect the 12v battery supply to the LIN transceivers (turning them off), I get nothing at all
If I connect the Uno and due directly (Serial Tx to Serial Rx, bypassing the LIN transceivers), it works as expected.

Electrically, I’ve tried to keep it similar to the outcome of thisthread. So !Fault/Tx is always High so is CS

The LIN Bus wire itself has a 1K Pullup to 12v

Uno Tx Code

//Attempt to interface with MCP2004-e/p LIN Transceiver
//Uno project, Transmit

#define PIN_TXE 4 //Tx !Error pin of the MCP2004
#define PIN_CS 5 //Chip Select Pin of the MCP2004


uint8_t dataSend[4] = {0x03, 0x04, 0x55, 0x56};
uint8_t bytesToSend = 4;

void setup() {
pinMode(PIN_TXE,OUTPUT);
pinMode(PIN_CS,OUTPUT);
digitalWrite(PIN_TXE,HIGH);
digitalWrite(PIN_CS,HIGH);
Serial.begin(9600, SERIAL_8E1); //LIN Tx, 8E1 is BMW iBus standard
}

void loop() {
  // put your main code here, to run repeatedly:
delay(2000);

for (uint8_t i=0; i<bytesToSend; i++){
  Serial.write(dataSend[i]);

}

}

Due Rx Code

//Arduino Due Board, Programming Port, LIN Test
//Attempt to interface with MCP2004-e/p LIN Transceiver
//Due project, Receive

#define PIN_TXE 22
#define PIN_CS 24

uint8_t rxByte[4];

void setup() {
  // put your setup code here, to run once:
pinMode(PIN_TXE,OUTPUT);
pinMode(PIN_CS,OUTPUT);
digitalWrite(PIN_TXE,HIGH);
digitalWrite(PIN_CS,HIGH);
Serial1.begin(9600, SERIAL_8E1); //LIN Serial Rx, 8E1 is BMW iBus standard
Serial.begin(9600); //debug serial
Serial.println("Due debug Comms");

delay(100);
}

void loop() {
while(Serial1.available()) {
  delay(5);
  Serial1.readBytes(rxByte,4);//Read 4 bytes
  for (uint8_t i=0; i<4; i++){
    Serial.print(rxByte[i],HEX);
  }
  Serial.println();
} 
}

Any ideas ! :o

  Serial1.readBytes(rxByte,4);//Read 4 bytes

That comment is wrong. The function will read UP TO 4 bytes, AND it will tell you how many it read. Why do you ignore that value?

Thanks for the tip. If I increase rxByte to [5] and adjust the output loop

  Serial1.readBytes(rxByte,4);//Read 4 bytes
  for (uint8_t i=0; i<5; i++){
    Serial.print(rxByte[i],HEX);
  }

I now get

Due debug Comms
00000
00000
00000
00000

rather than before

Due debug Comms
0000
0000
0000

So I guess this means it’s not reading anything?
I’m a bit unsure why I get Serial.available()…but there’s no data :confused:

Serial.read() also returns zero when using the LIN Bus.

Both functions return the expected values when connected directly Uno tx to Due rx

If I increase rxByte to [5]

Why would you need a 5 element array to hold 4 bytes?

My suggestion was to change the call to:

   byte actuallyRead = Serial1.readBytes(rxByte, 4); //Read UP TO 4 bytes
   if(actuallyRead > 0)
   {
      for (uint8_t i=0; i<actuallyRead; i++)
      {
         Serial.print("Byte ");
         Serial.print(i);
         Serial.print(": ");
         Serial.println(rxByte[i], HEX);
      }
   }

PS: Your space key needs to be pounded more often. Thereisnoreasontojamcodeandcommentstogether.

actuallyRead returns 1

Now returning 4 bytes of zero..... hmmm.

Various pull-ups and caps on the LIN change the number of bytes received but I've not had a single non-zero byte!

I'll borrow a scope and take a look at the LIN bus

Aha! Now working. The Due Serial Rx Line required a 4k7 pull-up to 3v3 ! In the datasheet but needed to be deleted in the thread I read on here earlier....odd

All's well now though. Thanks

Hi, thanks at all, I'm using your code for read the Lin Bus on my car. My car is a Toyota and I want to command the blowers inside the seats whith Arduino DUE. I use a TJA1027 transceiver. I have some questions: I read the traffic when the car is on but when the car is off and the Lin Bus wire is disconnect I recive again messages "A ". It is correct? It happens to you too? I did not modify the BMW iBus standard "SERIAL_8E1" but it olso work with Toyota. I haven't problem because I read only? Thanke you very much!

Hello guys,

is it possible to only read LIN bus data using arduino pro mini with no external hw / transciever?