Skip to content

Commit b899d63

Browse files
committed
Basic example added
1 parent 61db63f commit b899d63

File tree

3 files changed

+76
-2
lines changed

3 files changed

+76
-2
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ The HardwareSerial UART of an ESP32 is used. (But in the past I used a software
77
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
88

99
# example
10-
Take a look into this repo to see, how this works: https://github.com/mestrode/IBS-Sensor-Library
10+
Need a basic example: Take a look into the example folder.
11+
12+
More complex example: Take a look into this repo to see, how this works: https://github.com/mestrode/IBS-Sensor-Library
1113

1214
This code calls some methods of BatSensor which utilizes the Lin-Interface
1315

@@ -56,7 +58,6 @@ The aktual data handling looks like this:
5658

5759
bool IBS_Sensor::readFrameCapacity()
5860
{
59-
6061
bool chkSumValid = LinBus->readFrame(IBS_FrameID[_SensorNo][IBS_FRM_CAP]);
6162
if (chkSumValid)
6263
{

example/basic/platformio.ini

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
; PlatformIO Project Configuration File
2+
;
3+
; Build options: build flags, source filter
4+
; Upload options: custom upload port, speed and extra flags
5+
; Library options: dependencies, extra library storages
6+
; Advanced options: extra scripting
7+
;
8+
; Please visit documentation for the other options and examples
9+
; https://docs.platformio.org/page/projectconf.html
10+
11+
[env:esp32doit-devkit-v1]
12+
platform = espressif32
13+
board = esp32doit-devkit-v1
14+
framework = arduino
15+
lib_deps =
16+
https://github.com/mestrode/Lin-Interface-Library.git

example/basic/src/main.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#include <Arduino.h>
2+
#include <Lin-Interface.hpp>
3+
4+
// using UART 1 for LinBus
5+
Lin_Interface LinBus(1);
6+
7+
// data to be filled by bus request
8+
float Cap_Max = 0.0;
9+
float Cap_Available = 0.0;
10+
uint8_t Cap_Configured = 0;
11+
uint8_t CalibByte = 0x00;
12+
bool CalibrationDone = false;
13+
14+
void setup()
15+
{
16+
Serial.begin(115200);
17+
18+
// configure baud rate
19+
Serial.print("configure Lin-Bus to 19200 Baud\n");
20+
LinBus.baud = 19200;
21+
}
22+
23+
bool readLinData()
24+
{
25+
bool chkSumValid = LinBus.readFrame(0x2C);
26+
if (chkSumValid)
27+
{
28+
// Data now avaliabele in LinBus.LinMessage
29+
30+
// decode some bytes (incl. rescaling)
31+
Cap_Max = (float((LinBus.LinMessage[1] << 8) + LinBus.LinMessage[0])) / 10;
32+
Cap_Available = (float((LinBus.LinMessage[3] << 8) + LinBus.LinMessage[2])) / 10;
33+
34+
// receive a single byte
35+
Cap_Configured = LinBus.LinMessage[4];
36+
37+
// decode flags within a byte
38+
CalibByte = LinBus.LinMessage[5];
39+
CalibrationDone = bitRead(LinBus.LinMessage[5], 0);
40+
}
41+
return chkSumValid;
42+
}
43+
44+
void loop()
45+
{
46+
if (readLinData())
47+
{
48+
Serial.print("Data reveived:\n");
49+
Serial.printf(" Cap_Max = %f\n", Cap_Max);
50+
Serial.printf(" Cap_Available = %f\n", Cap_Available);
51+
Serial.printf(" Cap_Configured = %d\n", Cap_Configured);
52+
Serial.printf(" CalibByte = %02Xh\n", CalibByte);
53+
Serial.printf(" CalibrationDone = %d\n", CalibrationDone);
54+
}
55+
56+
delay(5000);
57+
}

0 commit comments

Comments
 (0)