Skip to content

Commit 736c0f8

Browse files
committed
verified
1 parent a100b73 commit 736c0f8

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

example/basic/src/main.cpp

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ constexpr int LIN_PIN_RX = RX1;
88
constexpr int LIN_PIN_TX = TX1;
99
constexpr int LIN_PIN_NSLP = 23;
1010

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
1616
LinFrameTransfer linMaster(linBus, Serial, 2);
1717

1818
// data to be filled by bus request
@@ -22,16 +22,6 @@ uint8_t Cap_Configured = 0;
2222
uint8_t CalibByte = 0x00;
2323
bool CalibrationDone = false;
2424

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-
3525
bool readLinData()
3626
{
3727
auto rawData = linMaster.readFrame(0x2C);
@@ -65,8 +55,14 @@ bool readLinData()
6555
return true;
6656
}
6757

68-
void loop()
58+
void setup()
6959
{
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+
7066
if (readLinData())
7167
{
7268
Serial.print("Data reveived:\n");
@@ -77,8 +73,15 @@ void loop()
7773
Serial.printf(" CalibrationDone = %d\n", CalibrationDone);
7874
}
7975

80-
delay(5000);
76+
delay(1000);
77+
78+
Serial.println("TJA1020: send to sleep");
8179

8280
//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);
8487
}

0 commit comments

Comments
 (0)