@@ -12,75 +12,80 @@ Need a basic example: Take a look into the example folder.
1212More complex example: Take a look into this repo to see, how this works: https://github.com/mestrode/IBS-Sensor-Library
1313
1414This code calls some methods of BatSensor which utilizes the Lin-Interface
15+ ``` cpp
16+ // LIN Bus Interface provided viy TJA1020
17+ #include " TJA1020.hpp"
18+ // IBS Batterie Sensor
19+ #include " IBS_Sensor.hpp"
1520
16- // LIN Bus Interface provided viy TJA1020
17- #include "TJA1020.hpp"
18- // IBS Batterie Sensor
19- #include "IBS_Sensor.hpp"
20-
21- #define LIN_SERIAL_SPEED LIN_BAUDRATE_IBS_SENSOR /* Required by IBS Sensor */
22- #define lin_NSLP_Pin 32
23-
24- // utilize the TJA1020 by using UART2 for writing and reading Frames
25- // but keep in mind: the Lin_TJA1020 is only a extension of this library.
26- Lin_TJA1020 LinBus(2, LIN_SERIAL_SPEED, lin_NSLP_Pin); // UART_nr, Baudrate, /SLP
27-
28- // Hella IBS 200x "Sensor 2"
29- IBS_Sensor BatSensor(2);
30-
31- void setup()
32- {
33- // tell the BatSensor object which LinBus to be used
34- BatSensor.LinBus = &LinBus;
35- }
21+ #define LIN_SERIAL_SPEED LIN_BAUDRATE_IBS_SENSOR /* Required by IBS Sensor * /
22+ #define lin_NSLP_Pin 32
3623
37- void showSensorData() {
38- // read data from sensor (method request data by using several
39- // Lin-Frames)
40- BatSensor.readFrames();
41-
42- // may you using a Bus-Transceiver like the TJA1020 which should
43- // go to sleep after transmission (depends on your HW)
44- LinBus.setMode(LinBus.Sleep);
45-
46- // use received data
47- Serial.printf("Calibration done: %d &\n",
48- BatSensor.CalibrationDone);
49- Serial.printf("Voltage: %.3f Volt\n", BatSensor.Ubat);
50- Serial.printf("Current: %.3f Ampere\n", BatSensor.Ibat);
51- Serial.printf("State of Charge: %.1f %\n", BatSensor.SOC);
52- Serial.printf("State of Health: %.1f &\n", BatSensor.SOH);
53- Serial.printf("Available Capacity: %.1f &\n", BatSensor.Cap_Available);
54- }
24+ // utilize the TJA1020 by using UART2 for writing and reading Frames
25+ // but keep in mind: the Lin_TJA1020 is only a extension of this library.
26+ Lin_TJA1020 LinBus (2, LIN_SERIAL_SPEED, lin_NSLP_Pin); // UART_nr, Baudrate, /SLP
27+
28+ // Hella IBS 200x "Sensor 2"
29+ IBS_Sensor BatSensor(2);
30+
31+ void setup()
32+ {
33+ // tell the BatSensor object which LinBus to be used
34+ BatSensor.LinBus = &LinBus;
35+ }
36+
37+ void showSensorData() {
38+ // read data from sensor (method request data by using several
39+ // Lin-Frames)
40+ BatSensor.readFrames();
5541
42+ // may you using a Bus-Transceiver like the TJA1020 which should
43+ // go to sleep after transmission (depends on your HW)
44+ LinBus.setMode(LinBus.Sleep);
45+
46+ // use received data
47+ Serial.printf("Calibration done: %d &\n",
48+ BatSensor.CalibrationDone);
49+ Serial.printf("Voltage: %.3f Volt\n", BatSensor.Ubat);
50+ Serial.printf("Current: %.3f Ampere\n", BatSensor.Ibat);
51+ Serial.printf("State of Charge: %.1f %\n", BatSensor.SOC);
52+ Serial.printf("State of Health: %.1f &\n", BatSensor.SOH);
53+ Serial.printf("Available Capacity: %.1f &\n", BatSensor.Cap_Available);
54+ }
55+ ```
5656The LinBus is provided to the BatSensor and is used internaly.
57- The aktual data handling looks like this:
5857
59- bool IBS_Sensor::readFrameCapacity()
58+ The actual data handling looks like this:
59+
60+ ```cpp
61+ bool IBS_Sensor::readFrameCapacity()
62+ {
63+ bool chkSumValid = LinBus->readFrame(IBS_FrameID[_SensorNo][IBS_FRM_CAP]);
64+ if (chkSumValid)
6065 {
61- bool chkSumValid = LinBus->readFrame(IBS_FrameID[ _ SensorNo] [ IBS_FRM_CAP ] );
62- if (chkSumValid)
63- {
64- // decode some bytes (incl. rescaling)
65- Cap_Max = (float((LinBus->LinMessage[ 1] << 8) + LinBus->LinMessage[ 0] )) / 10;
66- Cap_Available = (float((LinBus->LinMessage[ 3] << 8) + LinBus->LinMessage[ 2] )) / 10;
67- // receive a single byte
68- Cap_Configured = LinBus->LinMessage[ 4] ;
69- // decode flags within a byte
70- CalibByte = LinBus->LinMessage[ 5] ;
71- CalibrationDone = bitRead(LinBus->LinMessage[ 5] , 0);
72- }
73- return chkSumValid;
66+ // decode some bytes (incl. rescaling)
67+ Cap_Max = (float((LinBus->LinMessage[1] << 8) + LinBus->LinMessage[0])) / 10;
68+ Cap_Available = (float((LinBus->LinMessage[3] << 8) + LinBus->LinMessage[2])) / 10;
69+ // receive a single byte
70+ Cap_Configured = LinBus->LinMessage[4];
71+ // decode flags within a byte
72+ CalibByte = LinBus->LinMessage[5];
73+ CalibrationDone = bitRead(LinBus->LinMessage[5], 0);
7474 }
75-
75+ return chkSumValid;
76+ }
77+ ```
7678# configuration Frames
7779See description of Frame 0x3C and 0x3D in the doc folder of this project.
80+
7881Don't know if this is valid in general, but at least in the Project IBS-Sensor-Library it worked.
7982
8083# see also
8184Lin Specification provided by Microchip
8285https://microchipdeveloper.com/local--files/lin:specification/LIN-Spec_2.2_Rev_A.PDF
86+
8387IBS-Sensor-Library
8488https://github.com/mestrode/IBS-Sensor-Library
89+
8590Lin-Transceiver-Library (TJA1020)
86- https://github.com/mestrode/Lin-Transceiver-Library
91+ https://github.com/mestrode/Lin-Transceiver-Library
0 commit comments