LIN bus

old_junior

New member
Hello,

I would like to use Teensy 3.5 as a LIN bus Master.
Could anybody know if there is any library for LIN bus?

Thanks.
 
Hello,

maybe this can help
https://github.com/macchina/LIN

The code seems to be for some kind of Arduino Due clone, but it's using only Serial and digitalWrite. So modification for a Teensy should be possible.

Don't forget to use a LIN transceiver chip for interfacing.
 
Did it worked?Actually i was also facing similar issue and i tried above link..But in vain.Any alternative solution to it?
 

Hello everyone!

I tried LIN communication using Teensy 4.0.
I created software with reference to the above library and tried it.
The break signal cannot be sent by the send_break () function, and when I checked it, it seems that there is an error in the setting register.

(install directory) / hardware / teensy / avr / cores / teensy4 below
According to HardwareSerial1.cpp ~ HardwareSerial8.cpp, it seems that they are assigned as follows.

Serial1 LPUART6
Serial2 LPUART4
Serial3 LPUART2
Serial4 LPUART3
Serial5 LPUART8
Serial6 LPUART1
Serial7 LPUART7
Serial8 LPUART5

After making the above corrections, the Break signal was transmitted correctly.

thank you.
 
Big thanks for solving this, it was on my list but atm. I'm a little busy. Changed the Register in the Repository, please check if everything is fine now.
 
Thank you for your reply and update.

The break signal is OK.

I found one more point to be worried about ...

It seems that the position of the 1-byte buffer shifts when waiting for the response data with read ().

I was able to receive correctly by inserting a dummy recieve in read line as shown below.
(However, I don't know if it is a phenomenon peculiar to Teensy 4.0. .. .. Please check it.)

Code:
int LIN::read(byte PID, byte* data, int length, int checksumtype) {
  byte CRC, send_pid;
  // +3 for Break, Sync and CRC after the Data
  byte tmp[length+3];
  uint8_t i = 0;
  
  send_pid = ((PID&0x3F) | addrParity(PID)<<6);
  
  _stream->write(send_pid);
  _stream->flush();
  //Serial.println("-----------------------");
    
/*
  unsigned long actuall = micros();
  
  while ( i < (length+4) ) {
    if ( _stream->available() ) {
      tmp[i] = _stream->read();
      Serial.println(tmp[i], HEX);
      i++;
    }
	if ( (actuall+response_maximalspace) > micros() ) {
	  break;
	}
  }
   */
  
  elapsedMicros waiting;
  
 [COLOR="#FF0000"] _stream->read(); /* Dummy read added by Geek493 */[/COLOR]
  
  //Serial.println(response_maximalspace);
  //Serial.println(waiting);
  while ( i < (length+4) ) {
    if ( _stream->available() ) {
      tmp[i] = _stream->read();
      //Serial.println(tmp[i], HEX);
      i++;
    }
    if ( response_maximalspace < waiting ) {
      //Serial.println(waiting);
      break;
     }
  }
  //Serial.println(waiting);
  
  for (int i=3; i<length+3; i++)
    data[i-3] = tmp[i];
  
  if (checksumtype == 1)
    CRC = dataChecksum(data, length, 0);
  else
    CRC = dataChecksum(data, length, send_pid);
  
  //Serial.println(CRC,HEX);
  //Serial.println(tmp[length+3],HEX);
  
  if (CRC == tmp[length+3])
    return CRC;
  else
    return -1;
}

Thank you.
 
Yes it seems to be an specific T4.x problem, I testet it against an LC, 3.x and T4.0 only the T4.0 finds a byte between the transmitting of the Lin-ID and the Slave response, atm I have no idea how, and what he is reading.
 
So with some more analysis its the following Problem.

With the Lin-Driver (what shortcuts Rx & Tx) the Transmit Register fills the Recieve Register, what for some reason not happend with the other Teensys, and with the first "read" the Register value is put in the array, so the Line from Geek493 is also the workaround for the T4.x (I can't clear the Register as far as I read the manual, still reading).

Code:
#if defined(__IMXRT1062__) // Teensy 4.0 & 4.1
  _stream->read();
#endif

This lines clear the RX Register and will only appear with the T4.x, an update will follow next with some other Stuff.
 
So with some more analysis its the following Problem.

With the Lin-Driver (what shortcuts Rx & Tx) the Transmit Register fills the Recieve Register, what for some reason not happend with the other Teensys, and with the first "read" the Register value is put in the array, so the Line from Geek493 is also the workaround for the T4.x (I can't clear the Register as far as I read the manual, still reading).

Code:
#if defined(__IMXRT1062__) // Teensy 4.0 & 4.1
  _stream->read();
#endif

This lines clear the RX Register and will only appear with the T4.x, an update will follow next with some other Stuff.

Markus

Thank you for your great support!
 
I have to correct me it looks like the last Byte inside the uart Buffer stays inside the Buffer after sending and then it is read. So the Buffer stays, and ist not empty also the bit that says the Buffer is filled is also aktiv.

So a read will clear it but why did the T4 differ from the T3 can someone explain?
 
Hello,

I am using a Teensy 4.0 from SKPANG with LIN and CAN support. I would like to simulate a LIN slave that can read headers from the master and respond back. Would this library support something like this, and if so could you provide a brief code example?

Thanks
 
Hello,

I am using a Teensy 4.0 from SKPANG with LIN and CAN support. I would like to simulate a LIN slave that can read headers from the master and respond back. Would this library support something like this, and if so could you provide a brief code example?

Thanks

Hi,

unfortunately not atm, I'm trying to get someting like that to work but atm its paused, SKPANG has a Slave lib for this try this maybe it fits your needs.

BR
Markus
 
Hi Markus,

Is the LIN library you have on Github capable of detecting a LIN break? I see in your source files that the break length selection is available, however no where in the library do I see where the break is detected, to trigger the Start of LIN Frame.

Thank You
 
Hi Markus,

Is the LIN library you have on Github capable of detecting a LIN break? I see in your source files that the break length selection is available, however no where in the library do I see where the break is detected, to trigger the Start of LIN Frame.

Thank You

Hello Dimitri,

this is a LIN-Master library, so the lib initiates the Lin-break for the communication, LIN is an Master-(many)Slave bus, so there is no need for the Master to detect.

BR Markus
 
Hi Markus,

Haha, wow I am dense.... have you any experience with detecting the LIN break? I have tried a lot of things but cannot successfully detect the break.
 
Back
Top