LIN bus

Support forum for users of the M1 Build

LIN bus

Postby aNinjaneer on Tue Jun 30, 2020 3:03 pm

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?
aNinjaneer
 
Posts: 27
Joined: Tue Apr 05, 2016 4:57 am

Re: LIN bus

Postby MalcolmG on Thu Jul 02, 2020 10:47 am

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.
MalcolmG
Pro User
 
Posts: 77
Joined: Fri Dec 18, 2015 1:34 pm
Location: Auckland, NZ

Re: LIN bus

Postby aNinjaneer on Thu Jul 02, 2020 1:03 pm

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.
aNinjaneer
 
Posts: 27
Joined: Tue Apr 05, 2016 4:57 am

Re: LIN bus

Postby MalcolmG on Fri Jul 03, 2020 6:25 pm

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.
MalcolmG
Pro User
 
Posts: 77
Joined: Fri Dec 18, 2015 1:34 pm
Location: Auckland, NZ


Return to M1 Build

Who is online

Users browsing this forum: No registered users and 3 guests