@@ -8,11 +8,11 @@ constexpr int LIN_PIN_RX = RX1;
8
8
constexpr int LIN_PIN_TX = TX1;
9
9
constexpr int LIN_PIN_NSLP = 23 ;
10
10
11
- // using a TJA1020 chip
12
- // using UART 1 for LinBus
13
- // configure 19200 Baud
14
- // using GPIO 23 for /NSLP pin of TJA1020
15
- Lin_TJA1020 linBus (LIN_UART_NO, LIN_BAUD, LIN_PIN_RX, LIN_PIN_TX, LIN_PIN_NSLP);
11
+ // Hardware Abstraction Layer for TJA1020 and UART
12
+ Lin_TJA1020 linBus (LIN_UART_NO, LIN_BAUD, LIN_PIN_RX, LIN_PIN_TX, LIN_PIN_NSLP, Lin_TJA1020::Mode::LowSlope);
13
+
14
+ // Lin Stack
15
+ // debug messages on serial, 2 = verbose
16
16
LinFrameTransfer linMaster (linBus, Serial, 2 );
17
17
18
18
// data to be filled by bus request
@@ -22,16 +22,6 @@ uint8_t Cap_Configured = 0;
22
22
uint8_t CalibByte = 0x00 ;
23
23
bool CalibrationDone = false ;
24
24
25
- void setup ()
26
- {
27
- // Serial represents Serial(0)
28
- Serial.begin (115200 );
29
-
30
- // configure slope rate
31
- Serial.print (" configure low slope rate of TJA1020\n " );
32
- linBus.setSlope (Lin_TJA1020::Mode::LowSlope);
33
- }
34
-
35
25
bool readLinData ()
36
26
{
37
27
auto rawData = linMaster.readFrame (0x2C );
@@ -65,8 +55,14 @@ bool readLinData()
65
55
return true ;
66
56
}
67
57
68
- void loop ()
58
+ void setup ()
69
59
{
60
+ // Serial represents Serial(0)
61
+ Serial.begin (115200 );
62
+
63
+ // configure slope rate
64
+ Serial.print (" configure low slope rate of TJA1020\n " );
65
+
70
66
if (readLinData ())
71
67
{
72
68
Serial.print (" Data reveived:\n " );
@@ -77,8 +73,15 @@ void loop()
77
73
Serial.printf (" CalibrationDone = %d\n " , CalibrationDone);
78
74
}
79
75
80
- delay (5000 );
76
+ delay (1000 );
77
+
78
+ Serial.println (" TJA1020: send to sleep" );
81
79
82
80
// shut TJA1020 down, this also releases the INH pin.
83
- linBus.setSlope (Lin_TJA1020::Mode::Sleep);
81
+ linBus.setMode (Lin_TJA1020::Mode::Sleep);
82
+ }
83
+
84
+ void loop ()
85
+ {
86
+ delay (5000 );
84
87
}
0 commit comments