Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 24 of 24

Thread: LIN bus

  1. #1
    Junior Member
    Join Date
    Sep 2015
    Posts
    4

    LIN bus

    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.

  2. #2
    Junior Member
    Join Date
    Jan 2017
    Posts
    17
    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.

  3. #3
    Junior Member
    Join Date
    Mar 2019
    Posts
    2
    Did it worked?Actually i was also facing similar issue and i tried above link..But in vain.Any alternative solution to it?

  4. #4

  5. #5
    Junior Member
    Join Date
    Mar 2019
    Posts
    2
    Hey skpang,thank you for providing me with alternative solutions..Will try it and report back if i dont get any solution..I hope it works bcoz i tried everything and now i m frustrated a bit.Thanks mybkexperience

  6. #6

  7. #7
    Senior Member
    Join Date
    Apr 2013
    Posts
    171
    Quote Originally Posted by Markus_L811 View Post
    New Link

    https://github.com/MarkusLange/Teens..._LC_LIN_Master

  8. #8
    Senior Member
    Join Date
    Apr 2013
    Posts
    171
    with support for Teensy 4.x

  9. #9
    Junior Member
    Join Date
    Nov 2021
    Posts
    3
    Quote Originally Posted by Markus_L811 View Post
    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.

  10. #10
    Senior Member
    Join Date
    Apr 2013
    Posts
    171
    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.

  11. #11
    Junior Member
    Join Date
    Nov 2021
    Posts
    3
    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;
      
      _stream->read(); /* Dummy read added by Geek493 */
      
      //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.

  12. #12
    Senior Member
    Join Date
    Apr 2013
    Posts
    171
    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.

  13. #13
    Senior Member
    Join Date
    Apr 2013
    Posts
    171
    Atm, I'm thinking this Beast, is to fast

  14. #14
    Senior Member
    Join Date
    Apr 2013
    Posts
    171
    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.

  15. #15
    Junior Member
    Join Date
    Nov 2021
    Posts
    3
    Quote Originally Posted by Markus_L811 View Post
    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!

  16. #16
    Senior Member
    Join Date
    Apr 2013
    Posts
    171
    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?

  17. #17
    Senior Member
    Join Date
    Apr 2013
    Posts
    171
    I have now a library for the NCV7430 and APGRD004 in my repositiy if someone want to give it a try

  18. #18
    Junior Member
    Join Date
    May 2022
    Posts
    1
    Quote Originally Posted by Markus_L811 View Post
    I have now a library for the NCV7430 and APGRD004 in my repositiy if someone want to give it a try
    Hi there I would like a copy if possible .
    I canít seem to get the teensy 4.0 to read the raw lin .
    I tried a few libraries but Iím struggling
    Thanks in advance .

  19. #19
    Senior Member
    Join Date
    Apr 2013
    Posts
    171
    Quote Originally Posted by Skuppy069 View Post
    Hi there I would like a copy if possible .
    I canít seem to get the teensy 4.0 to read the raw lin .
    I tried a few libraries but Iím struggling
    Thanks in advance .
    Take a look https://github.com/MarkusLange/Teens..._LC_LIN_Master

  20. #20
    Junior Member
    Join Date
    Aug 2022
    Posts
    1
    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

  21. #21
    Senior Member
    Join Date
    Apr 2013
    Posts
    171
    Quote Originally Posted by responder99 View Post
    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

  22. #22
    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

  23. #23
    Senior Member
    Join Date
    Apr 2013
    Posts
    171
    Quote Originally Posted by Dimitri View Post
    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

  24. #24
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •