mestrode / Lin-Interface-Library

Provide LIN-Master functions (write and request LIN-Frames via hardware UART
GNU General Public License v2.0
34 stars 11 forks source link

Please Help. #1

Closed gbkwiatt closed 1 year ago

gbkwiatt commented 1 year ago

Hey, I was reading a lot about LIN and trying to find some libraries and examples. But nothing matches to what I am receiving, and I am pulling my hair on that. I wonder if you could maybe help me, I know It's been a year since you've pushed to that repo but worth a shot.

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 https://github.com/MarkusLange/APGRD004/blob/main/src/apgrd004.cpp

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. And all examples over the internet are nothing alike to what I am getting.

mestrode commented 1 year ago

You're trying to reverse engineering the bus messages. First step should be to verify the baud rate. Since LIN has a standardized protocol, you should look for the common sync byte an plausible byte blocks. A scope will help you to identify that. If you don't have one available, may a high sample record will do the trick (Take a look into audio / wave record for signal analysis). Guess there is a periodic status message. and by changing the configured color, there will be send an additional config message. But in my point of view there are just three options: Lucky shot (by varying the rate until you have success), take a deeper look into the transient signal and analyse it or try to auto identify the correct baud rate by using information like all rising (and/or falling) edges of the sync byte.

The 8 bit Sync field has a predefined value of 0x55 (in binary, 01010101). This structure allows the LIN nodes to determine the time between rising/falling edges and thus the baud rate used by the master node. This lets each of them stay in sync. Source: https://www.csselectronics.com/pages/lin-bus-protocol-intro-basics

gbkwiatt commented 1 year ago

I've finally figure it out. Crucial here was correct baud rate and as everywhere states, usually 9200 is default and "most common" but wasn't in my case. I think VAG group has 10417 and this was correct in my case. Once I've got correct baud, I've started receiving correct messages with 0x55 as a sync. I was also able to successfully send a message