Skip to content

Commit 61db63f

Browse files
committed
Initial commit
1 parent f700c07 commit 61db63f

File tree

6 files changed

+501
-0
lines changed

6 files changed

+501
-0
lines changed

README.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# LIN-Interface-Library
2+
Send and Sends and Request data by compiling a LIN Frames and transmission via Serial (as a Bus Master)
3+
4+
The HardwareSerial UART of an ESP32 is used. (But in the past I used a software serial and therefore I derived this class in a prior version from the class SoftwareSerial)
5+
6+
# Transceiver
7+
I've used a TJA1020 Transceiver on HW side in my project. The chip contains a statemachine, which needs to be controlled before you will be able to write or receive data. To keep thinks easy, I created a derived class (from this one) which consider the statemachine every time using the bus: https://github.com/mestrode/Lin-Transceiver-Library
8+
9+
# example
10+
Take a look into this repo to see, how this works: https://github.com/mestrode/IBS-Sensor-Library
11+
12+
This code calls some methods of BatSensor which utilizes the Lin-Interface
13+
14+
// LIN Bus Interface provided viy TJA1020
15+
#include "TJA1020.hpp"
16+
// IBS Batterie Sensor
17+
#include "IBS_Sensor.hpp"
18+
19+
#define LIN_SERIAL_SPEED LIN_BAUDRATE_IBS_SENSOR /* Required by IBS Sensor */
20+
#define lin_NSLP_Pin 32
21+
22+
// utilize the TJA1020 by using UART2 for writing and reading Frames
23+
// but keep in mind: the Lin_TJA1020 is only a extension of this library.
24+
Lin_TJA1020 LinBus(2, LIN_SERIAL_SPEED, lin_NSLP_Pin); // UART_nr, Baudrate, /SLP
25+
26+
// Hella IBS 200x "Sensor 2"
27+
IBS_Sensor BatSensor(2);
28+
29+
void setup()
30+
{
31+
// tell the BatSensor object which LinBus to be used
32+
BatSensor.LinBus = &LinBus;
33+
}
34+
35+
void showSensorData() {
36+
// read data from sensor (method request data by using several
37+
// Lin-Frames)
38+
BatSensor.readFrames();
39+
40+
// may you using a Bus-Transceiver like the TJA1020 which should
41+
// go to sleep after transmission (depends on your HW)
42+
LinBus.setMode(LinBus.Sleep);
43+
44+
// use received data
45+
Serial.printf("Calibration done: %d &\n",
46+
BatSensor.CalibrationDone);
47+
Serial.printf("Voltage: %.3f Volt\n", BatSensor.Ubat);
48+
Serial.printf("Current: %.3f Ampere\n", BatSensor.Ibat);
49+
Serial.printf("State of Charge: %.1f %\n", BatSensor.SOC);
50+
Serial.printf("State of Health: %.1f &\n", BatSensor.SOH);
51+
Serial.printf("Available Capacity: %.1f &\n", BatSensor.Cap_Available);
52+
}
53+
54+
The LinBus is provided to the BatSensor and is used internaly.
55+
The aktual data handling looks like this:
56+
57+
bool IBS_Sensor::readFrameCapacity()
58+
{
59+
60+
bool chkSumValid = LinBus->readFrame(IBS_FrameID[_SensorNo][IBS_FRM_CAP]);
61+
if (chkSumValid)
62+
{
63+
// decode some bytes (incl. rescaling)
64+
Cap_Max = (float((LinBus->LinMessage[1] << 8) + LinBus->LinMessage[0])) / 10;
65+
Cap_Available = (float((LinBus->LinMessage[3] << 8) + LinBus->LinMessage[2])) / 10;
66+
// receive a single byte
67+
Cap_Configured = LinBus->LinMessage[4];
68+
// decode flags within a byte
69+
CalibByte = LinBus->LinMessage[5];
70+
CalibrationDone = bitRead(LinBus->LinMessage[5], 0);
71+
}
72+
return chkSumValid;
73+
}
74+
75+
# configuration Frames
76+
See description of Frame 0x3C and 0x3D in the doc folder of this project.
77+
Don't know if this is valid in general, but at least in the Project IBS-Sensor-Library it worked.
78+
79+
# see also
80+
Lin Specification provided by Microchip
81+
https://microchipdeveloper.com/local--files/lin:specification/LIN-Spec_2.2_Rev_A.PDF
82+
IBS-Sensor-Library
83+
https://github.com/mestrode/IBS-Sensor-Library
84+
Lin-Transceiver-Library (TJA1020)
85+
https://github.com/mestrode/Lin-Transceiver-Library

doc/diagnosisFrame.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
2+
# Description of 0x3C and 0x3D Frames
3+
Source: discussion in a german forum, contains the breaf information below
4+
https://www.kastenwagenforum.de/forum/threads/diy-hella-ibs-batteriecomputer.31724/
5+
6+
alle Frames ohne Header und Checksumme
7+
8+
jeweils erste Zeile ist die Anfrage (header 3C)
9+
jeweils zweite Zeile die Antwort (header 3D)
10+
11+
Sensor Nr
12+
| Data Länge
13+
| | CMD Config Lesen
14+
| | | ConfigTyp (0x00=Hersteller ID und Funktion)
15+
| | | | Wildcard für Hersteller und Funktion
16+
| | | | |
17+
| | | | |-----------------|
18+
0x02,0x06,0xB2,0x00,0xFF,0x7F,0xFF,0xFF
19+
0x02,0x06,0xF2,0x36,0x00,0x0A,0xF1,0x03
20+
| | | | ------| |-------| |
21+
| | | | | Variante
22+
| | | | Funktion
23+
| | | Hersteller
24+
| | 0xB2+0x40 Data OK / 7F Fehler
25+
s.o. s.o.
26+
27+
Beispiel Fehler Frame (auslesen Seriennummer)
28+
29+
0x02,0x03,0x7F,0x01,0x12,0xFF,0xFF,0xFF
30+
| | | | | |------------|
31+
| | | | | Füllbytes
32+
| | | | FehlerTyp (0x12=vermutlich "nicht
33+
| | | | implementiert")
34+
s.o s.o s.o angefragter Wert
35+
36+
37+
0x02,0x06,0xB2,0x10,0xFF,0x7F,0xFF,0xFF
38+
0x02,0x04,0xF2,0x32,0x10,0x76,0xFF,0xFF
39+
40+
0x02,0x06,0xB2,0x11,0xFF,0x7F,0xFF,0xFF
41+
0x02,0x04,0xF2,0x21,0x10,0xE7,0xFF,0xFF
42+
43+
0x02,0x06,0xB2,0x12,0xFF,0x7F,0xFF,0xFF
44+
0x02,0x04,0xF2,0x22,0x10,0xA8,0xFF,0xFF
45+
46+
0x02,0x06,0xB2,0x13,0xFF,0x7F,0xFF,0xFF
47+
0x02,0x04,0xF2,0x23,0x10,0xE9,0xFF,0xFF
48+
49+
0x02,0x06,0xB2,0x14,0xFF,0x7F,0xFF,0xFF
50+
0x02,0x04,0xF2,0x24,0x10,0x6A,0xFF,0xFF
51+
52+
0x02,0x06,0xB2,0x15,0xFF,0x7F,0xFF,0xFF
53+
0x02,0x04,0xF2,0x25,0x10,0x2B,0xFF,0xFF
54+
55+
0x02,0x06,0xB2,0x16,0xFF,0x7F,0xFF,0xFF
56+
0x02,0x04,0xF2,0x26,0x10,0xEC,0xFF,0xFF
57+
58+
0x02,0x06,0xB2,0x17,0xFF,0x7F,0xFF,0xFF
59+
0x02,0x04,0xF2,0x30,0x10,0xB4,0xFF,0xFF
60+
61+
0x02,0x06,0xB2,0x18,0xFF,0x7F,0xFF,0xFF
62+
0x02,0x04,0xF2,0x31,0x10,0xF5,0xFF,0xFF
63+
64+
0x02,0x06,0xB2,0x19,0xFF,0x7F,0xFF,0xFF
65+
0x02,0x04,0xF2,0x33,0x10,0x37,0xFF,0xFF
66+
67+
0x02,0x06,0xB2,0x1A,0xFF,0x7F,0xFF,0xFF
68+
0x02,0x04,0xF2,0x11,0x10,0x92,0xFF,0xFF
69+
70+
0x02,0x06,0xB2,0x39,0xFF,0x7F,0xFF,0xFF Batterie
71+
0x02,0x02,0xF2,0x50,0xFF,0xFF,0xFF,0xFF Kapazität
72+
73+
0x02,0x06,0xB2,0x3A,0xFF,0x7F,0xFF,0xFF Batterie
74+
0x02,0x02,0xF2,0x14,0xFF,0xFF,0xFF,0xFF Typ

library.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "Lin-Interface",
3+
"version": "0.0.1",
4+
"description": "send and request LIN-Frames via UART (Break, Sync, ID, Data, Checksum)",
5+
"keywords": [
6+
"LIN",
7+
"Lin-Bus"
8+
],
9+
"repository": {
10+
"type": "git",
11+
"url": "https://github.com/mestrode/Lin-Interface-Library"
12+
},
13+
"authors": [
14+
{
15+
"name": "mestrode",
16+
"maintainer": true
17+
}
18+
],
19+
"license": "GPL-2.0-only",
20+
"dependencies": []
21+
}

library.properties

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=Lin-Interface
2+
version=0.0.1
3+
author=mestrode <[email protected]>
4+
maintainer=mestrode <[email protected]>
5+
sentence=Use serial interface (UART) for LIN-Bus communication
6+
paragraph=send and request LIN-Frames via UART (Break, Sync, ID, Data, Checksum)
7+
category=sensors
8+
url=https://github.com/mestrode/Lin-Interface-Library
9+
license=GPL-2.0-only

0 commit comments

Comments
 (0)