Page 1 of 1

LIN bus

PostPosted: Tue Jun 30, 2020 3:03 pm
by aNinjaneer
I am attempting to send some LIN messages, and it seems I'm either not doing it correctly, or it isn't working correctly. This is effetely what I have so far. It seems to be sending some sort of message (looking at the oscilloscope), but my LIN analyzer is not able to even detect the packets. I followed the example of the only LIN snippet I could find on here. The documentation isn't very clear on sending LIN messages.

local h = Serial.GetTransmitHandle(true);
local dataOffset = Serial.SetLinHeader(h, 0, 4, [message_id], true, true);
offset = Serial.SetUnsignedInteger(h, offset, 4, [data]);
offset = Serial.SetUnsignedInteger(h, offset, 1, ~Serial.Sum8(h, dataOffset - 1, 5)); // is this even necessary?
Serial.Transmit(h, 1, offset);

Any insight into the proper way to send LIN messages?

Re: LIN bus

PostPosted: Thu Jul 02, 2020 10:47 am
by MalcolmG
Have you included a LIN serial port class object in the project, and used that to configure the baud rate and protocol for the port?

Looking at your code and what I have working in a project, I use Serial.GetHandle rather than Serial.GetTransmitHandle, but otherwise it seems to match (I guess you may have used my example).

As far as I know the checksum calculation is necessary, how a bad checksum is treated probably depends on the receiver but my LIN analyser (picoscope) would highlight the checksum as being wrong if it were omitted or incorrect.

Re: LIN bus

PostPosted: Thu Jul 02, 2020 1:03 pm
by aNinjaneer
Yes, I have a Serial Port object and have the baud set to the correct speed. It is transmitting *something* just not properly formed LIN messages.

Re: LIN bus

PostPosted: Fri Jul 03, 2020 6:25 pm
by MalcolmG
What are you using for the LIN analyser? Does it have any settings for things like baud rates, trigger thresholds etc that could be wrong? Does it have the choice between enhanced and classic checksums?

I notice in the help for the GetTransmitHandle function that you have used, it says this is deprecated and you should use GetHandle. It's possible GetTransmitHandle doesn't work correctly with LIN comms.