LIN BUS READ/WRITE - WRITE problem mcp2003, mcp2021

I've read couple of threads, but they are all closed now. It seems like it's ongoing struggle on arduino from time to time.
I've hooked MCP2003 to my arduino with LIN pull up so it's set as master.
I've manager to read some messages from my car LIN like

0B5C090B328FC
0B5C090B328FC
0B5C090AD28FC
0B5C080B328FC

Where 0 I am assuming is sync break. B5 - is that Sync byte ? normally it's 0x55 but I can't see that anywhere in my read dump.
C0 - could be slave address
90 - keeps changing beetween 90/80
B2 - is a colour selection - B1-B5
68 - that's brightness of the color.
and then checksum

Now reading looks correctm but I am struggling to send anything. I mean I want to light it up on my bench but all the slaves is reporting is FF

So I've read that the 0 break sync has to be very specific and found something like that

void syncBreak(){
  Serial.end(); //End Serial1
  digitalWrite(TX_PIN,LOW); // Force the Tx pin LOW
  delayMicroseconds(1400); // LIN spec says Sync Break should be >=13 bit length (1354.16usec)
  Serial.begin(9600,SERIAL_8E1); // Re-enable Serial1 (in my case 8N1 rqd)
  delayMicroseconds(100); // Allow Serial to pull Tx High - sync break delay
}

I am using HardwareSerial

#define RX_PIN 0
#define TX_PIN 1
#define FAULT_PIN 13
#define CS_PIN 8

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.begin(9600 , SERIAL_8E1);
  pinMode(CS_PIN, OUTPUT);
  digitalWrite(CS_PIN, HIGH);
  pinMode(FAULT_PIN, OUTPUT);
  digitalWrite(FAULT_PIN, HIGH);
  frame = LinFrame();
}

void loop() {
  sendMessage();
}

void sendMessage(){
  byte message[] = { 0xB5, 0xC0, 0x90, 0xB2, 0x68, 0xFC };
  syncBreak();
  Serial.write(message, sizeof(message));
}

does that makes sense at all, or I am doing something obviously wrong ?

Hi,
have you read his datasheet?

Yes I have. Are you suggesting that Ive done something wrong according to documentation ?

No.

I've change module to mcp2021, read articles and check libraries, and everywhere it's pretty simply explained,
fou have break frame 0x00, then sync frame 0x55 and then PID frame. But what I am getting looks nothing alike and I just can't figure it out

So I have LIN in my car for ambient lighting and LED modules. It constantly sends loads of messages but they are same messages.
I think it should be something similar to APGRD004/apgrd004.cpp at main · MarkusLange/APGRD004 · GitHub

so I've used your library and id didn't really give me an answer either.

While I understand I should have break 0x00 and sync 0x55 I can't seem to figure out what I am receiving

Here is an example

0x00 0x20 0x18 0xE6 0x06 0x26
0x00 0x20 0x18 0xE6 0x06 0x26 0x 0x06 0x26
0x00 0x20 0x18 0xE6 0x06 0x26 0x06 0x26
0x00 0x20 0x18 0xE6 0x06 0x26 0xE6 0x26
0x00 0x20 0x1E 0xE6 0x26
.
.
.
0x00 0x20 0x1E 0xE6 0x26 0x18 0xF8 0x26
0x00 0x20 0x1E 0xF8 0x26
.
.
.
0x00 0x20 0x1E 0xF8 0x26 0xE6 0x26
0x00 0x20 0x1E 0xE6 0x26
.
.
.
0x00 0x20 0x1E 0xE6 0x26 0x18 0xF8 0x26
0x00 0x20 0x1E 0xF8 0x26
.
.
.
0x00 0x20 0x1E 0xF8 0x26 0xF8 0xF8 0x26
0x00 0x20 0x00 0xF8 0x26 0xE6 0xC6 0x26
0x00 0x20 0x00 0xE6 0xE0 0x26
.
.
.
0x00 0x20 0x00 0xE6 0xE0 0x26 0x1E 0x26
0x00 0x20 0x00 0x18 0x26
.
.
.
0x00 0x20 0x00 0x18 0x26 0xE6 0xC6 0x26
0x00 0x20 0x00 0xE6 0xE0 0x26
.
.
.
0x00 0x20 0x00 0xE6 0xE0 0x26 0xE6 0x18 0x26
0x00 0x20 0x18 0xE6 0x06 0x26
.
.
.
0x00 0x20 0x18 0xE6 0x06 0x26 0xE6 0x26
0x00 0x20 0x1E 0xE6 0x26
.
.
.
0x00 0x20 0x1E 0xE6 0x26 0xE6 0x18 0x26
0x00 0x20 0x18 0xE6 0x06 0x26
.
.
.

So when I was playing in the car and changing colors, it was sending longer message which looks like repeat of previous state plus new state request (?)
dots in example are just repeated previous line (it's spamming those lines so I think it could be slaves sending current state ?)

since 0x00 is my break byte, does that mean 0x20 is my sync byte ? then next byte would be PID or ID ?
Also last byte should be CRC but that does not make sense either since last byte is always 0x26
My goal is so I can trigger LED module from my car on my bench, but I am getting nowhere.

Are you looking at complemented data and or have the wrong baud rate? What error flags are you getting from the LIN control module? This information should be in the data sheets.

I've assumed standard baud rate for LIN of LinBus.begin(19200, SERIAL_8N1);
I've had LIN sniffer from microchip for a moment, and that detected 10417 baud, but I've read that baud rate is fine within some tolerance. also that sniffer gave also way different readings.

all I am reading is just each byte coming on RX from MCP2021.
There is nothing about error responses on mcp2021 datasheet https://docs.rs-online.com/3298/0900766b8137ee46.pdf

However, the fact that messages changes when I am playing with LIN network on the car, tells me that it reads something of the car.
But it's just nothing alike I was reading about LINE, every article mentioned that SYNC byte is always 0x55 but I am not getting that at all, ever.

On My car there is ambient light modules which also have mcp2021 on it, that's why I went with 2021 to exclude module differences (just in case).
When I power module on the workbench, it transmits nothing, but I assume I supposed to wake it up with master, so with break byte and sync byte.

I do not have a lin network set up. You properly troubleshoot you need to have a known good quality signal or a network analyzer. You could get some of the inexpensive 24Mhz logic analyser generally in the $7.00 range and see what you get with them. I believe they will decode LIN, they do fine on SPi, CAN, I2C for me.

Thank you for that, I was looking for way of debugging sygnal cheaper than an oscilloscopes with LIN support, so I will deffinitely try one of those analyser.
CAN is fairly easy, there is plenty of libraries and known mcp2515 and all you need to know is baud rate of your network.
Didnt exoect so much trouble with LIN. I have teansciver as above, and it seems to be reading something, but it just doesnt make sense to me

i been down this road. its all about bound rate when it comes to LIN BUS. For example GM uses 10,417 on everything. if you don't set your LINSerial to that, it will come over with bunch of junk.

When it comes to LIN bound rates, following cover 99% of cars.. 19200, 10417, 9600, 4800, 2400, 1200.

GitHub - nuriC0/gm-lin-bus: Using Arduino to interact with 2021 Corvette C8 LIN BUS. << here is my little project i started, just need to finish writing it up.

ah, that makes total sense. I think I've seen 10417 one I had a LIN analizer for 5min to mess with it messages were coming and it detected 10417 baudrate, but I thought it's not true since most of them have 19200, but now when you mentioned that .... Great stuff Thanks. I will have a go again

Just have a side question - how to distinguish between 0x00 in a data, and 0x00 break ? I mean it's easier if I know message length and then I can try to look for a pair 0x00 0x55, but maybe there is something smarter ?

it depends on transceiver, sometimes they will remove x00

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.