gandrewstone / lin Goto Github PK
View Code? Open in Web Editor NEWThe LIN protocol implemented over Arduino APIs (Serial and Digital IO)
The LIN protocol implemented over Arduino APIs (Serial and Digital IO)
This is a LIN (http://en.wikipedia.org/wiki/Local_Interconnect_Network) protocol master implementation that supports LIN 1.X or LIN 2.X frame types. It is built on top of the "Arduino" Serial and digital IO APIs. These "underface" APIs form a useful abstraction layer for any chip. So its better to implement them for your new microcontroller and then get LIN for free using this library than to implement LIN over a raw register set. The library supports injection of immediate LIN frames, or a "skew heap" based schedule table. The skew heap schedule table differs from what is suggested by the LIN specification (which defines a linked list of LIN frames and time intervals between them). This implementation provides a similar "pile" of LIN frames, but instead of being a static list, the skew heap essentially dynamically sorts the frames to find the next scheduled frame. This allows frames to be easily inserted and removed from the schedule, and frame interval periods (the time between 2 issues of the same frame) to be changed dynamically. It also means that the frame interval period does not depend on the total length of the schedule table (as it does for the specced linked list implementation) which eliminates an unnecessary interaction between otherwise independent LIN devices. The library was tested on a Lightuino 5 (Arduino Duemilanove/Uno compatible board) using a LIN slave LED of unknown provenance. So you will have to change the test code to generate frames for whatever LIN device you have on hand.
The code in lin.h file should be surrounded by header guard like this:
#ifndef LIN_H_
#define LIN_H_
// Code goes here.
#endif // LIN_H_
This way it can be included from several files at the same time without having problems of "redeclarations".
Have a nice day! :-)
Chris
Hello, i want to use arduino to controll stepper motors by AMIS 30621. As LIN driver i using TJA1028t. Arduino Mega 2560 - uart 1.
With inicialization or send request i have no problem but when i want obtain actual motor position i cant read first byte from driver.
I using command GetActual Position what need to sesnd synchronization and ID from arduino and then immediately obtaining data from driver with checksum.
Data looks like this:
break sync , 0x55 , ID , 0x8C,0x00,0x00,0x00,0x00,checksum
break sync , 0x55 , ID - is from arduino
0x8C,0x00,0x00,0x00,0x00,checksum - response from driver
but i cant read first byte 0x8C and without it i cant do anything.
i trying to read faster but everytime i cant read it.
checksum without first bit is correct with error.
Thank you for response.
Radek
Hello,
is it possible to add the LIn Slave as a lib?
I think ist more tan jus removing the sync bit 0x55, right?
Thank's a lot
Alf
See pull request for fix
Hey all,
I tried making two Arduino megas communicate via the LIN bus using the given library, but when I try to print the frame in the serial monitor, it gives some extra garbage values at the beginning and then prints the correct data transmitted and received. I believe that is due to the conflict between the use of serial ports on the Arduino.
in the above image 170 is the data sent, and the rest is garbage.
in the above image, 1, 170 and 3 are the data and the intial U and the inverted "?" are garbage. Can anyone help me to remove these garbage values, please.
Hi, I tried your code but it keeps giving me this error when compiling: fatal error: lightuino5.h: No such file or directory
Help please
Calculated TBit is 1/10 the real value due to a missing zero. For 19200 baud TBit is 52ms not 5ms.
and 52 vs 50 isn't 40% different it's 4%. so the *14 to recover the missing resolution goes too far.
Probably shouldn't wait 2 frames for a response either.
A better timeout value would be:
timeout = (34+90)*1000000UL/serialSpd;
I am trying to convert you code to use software serial, so I can use it the the analyzer board I built based on Zapta's project (https://github.com/zapta/linbus/tree/master/analyzer)
It uses a ATA6631 Lin Transceiver with the RX pin hooked do D2 and TX hooked to C2 (Analog 2, but used at digital)
Goal is to be able send a full frame at a given time. I have already reverse engineered the frame that I need.
Could you maybe give me some pointers?
Lin(LIN_SERIAL& ser=Serial,uint8_t txPin=1);
I know I would change the TX pin to 16 (A2).
I tried defining a software serial by including the Library, and then
'Software Serial mySerial(2,16);'
and then changing ser=Serial to ser=mySerial, but it said mySerial was not not declared in this scope.
Hello, do I need to use a LIN transceiver (for example this one http://www.atmel.com/images/atmel-4916-lin-networking-ata6662c_datasheet.pdf ) with your library? I want to generate LIN 2.0 master frame with 8 bytes of data. I used your library to do that, my code looks like this:
void loop() {
uint8_t cmd1[] = { 0x47, 0x20, 0xF8, 0x73, 0x00, 0x00, 0xCF, 0xFF};
uint8_t cmd2[] = { 0x44, 0x10, 0xF0, 0x73, 0x00, 0x00, 0xCF, 0xFF};
uint8_t cmd3[] = { 0x23, 0xF0, 0xF0, 0x73, 0x00, 0x00, 0xCF, 0xFF};
uint8_t cmd4[] = { 0x5d, 0x47, 0xF0, 0x73, 0x00, 0x00, 0xCF, 0xFF};
uint8_t cmd5[] = { 0xE4, 0xD0, 0xF0, 0x73, 0x00, 0x00, 0xCF, 0xFF};
uint8_t cmd6[] = { 0x42, 0xE1, 0xF2, 0x73, 0x00, 0x00, 0xCF, 0xFF};
lin.send(0x30, cmd1,8,2);
delay(70);
lin.send(0x32, cmd2,8,2);
delay(70);
lin.send(0x33, cmd3,8,2);
delay(70);
lin.send(0x35, cmd4,8,2);
delay(70);
lin.send(0x36, cmd5,8,2);
delay(70);
lin.send(0x37, cmd6,8,2);
delay(70);
}
when i look at the TX through my saleae analyzer i see that data bytes are okay but there is something wrong with the checksum, i don't know what's the reason.
in lin.cpp, line 124 should be exchanged to accomplish this automatically:
// LIN diagnostic frame shall always use CHKSUM of protocol version 1.
uint8_t cksum = dataChecksum(message, nBytes, (proto == 1 || addr == 0x3C) ? 0 : addrbyte);
Line 182 accordingly ;-):
// LIN diagnostic frame shall always use CHKSUM of protocol version 1.
if (proto == 1 || addr == 0x3D) idByte = 0; // Don't cksum the ID byte in LIN 1.x
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.