macchina/LIN

LIN TX on Channel 1 not working?

Opened this issue · 4 comments

From @rocketjosh on August 10, 2017 15:13

It appears as though LIN1.write( may not be working? LIN2.write( does appear to work. Tested using this example.

RX on both channels does work as verified using this example.

Copied from original issue: macchina/m2-libraries#3

Hello,
I encounterd the same problem and I have found the problem. It is a typo in the source code there is an assignment instead of a comparison in the if clause which causes this problem.

Here the corresponding code snipped.

// PRIVATE METHODS
int lin_stack::serial_pause(int no_bits){
// Calculate delay needed for 13 bits, depends on bound rate
unsigned int del = period*no_bits; // delay for number of bits (no-bits) in microseconds, depends on period
if(ch=2){
PIOA->PIO_PER = PIO_PA13; // enable PIO register
PIOA->PIO_OER = PIO_PA13; // enable PA13 as output
PIOA->PIO_CODR = PIO_PA13; // clear PA13
delayMicroseconds(del); // delay
PIOA->PIO_SODR = PIO_PA13; // set pin high
PIOA->PIO_PDR = PIO_PA13; // clear configuration for PIO, needs to be done because Serial wont work with it
}else if(ch=1){

Also I did a fork on your project doing some changes and extensions.

The link is: https://github.com/duronflo/LIN

So far I did:

  • correct checksum calculation, removed +1
  • inserted parity calculation in writeRequest method
  • implemented parity calculation
  • implemented bus wake up for proper lin bus waking up
  • Changed default baudrate to 19200 which is more common in automotive applications

If you'd like, issue a pull request and I'll look it over and merge it. Otherwise, I can go to your link and do the changes myself. Thanks for working on it either way!

I just merged your changes. They seem reasonable to me. Can someone else who uses LIN confirm that things are improved?