Hello everyone,
I've been working on a project where I'm trying to read data from a LIN bus using an Arduino Leonardo and a TJA1021 transceiver. I have written two programs to read the data: one using SoftwareSerial and the other using Serial1 (the hardware serial port).
Here's a simplified version of the two programs I used:
**Program using SoftwareSerial:
#include <Arduino.h>
#include <SoftwareSerial.h>
#define LIN_SERIAL_RX_PIN 14
#define LIN_SERIAL_TX_PIN 15
#define LIN_BAUD_RATE 9600
#define TJA_WAKEUP_PIN 7
SoftwareSerial linSerial(LIN_SERIAL_RX_PIN, LIN_SERIAL_TX_PIN);
void setup() {
Serial.begin(115200);
linSerial.begin(LIN_BAUD_RATE);
pinMode(TJA_WAKEUP_PIN, OUTPUT);
digitalWrite(TJA_WAKEUP_PIN, HIGH);
}
void loop() {
if (linSerial.available()) {
byte receivedByte = linSerial.read();
Serial.println(receivedByte, HEX);
}
}
**Program using Serial1:
#include <Arduino.h>
#define LIN_SERIAL_RX_PIN 0
#define LIN_SERIAL_TX_PIN 1
#define LIN_BAUD_RATE 9600
#define TJA_WAKEUP_PIN 7
void setup() {
Serial.begin(115200);
Serial1.begin(LIN_BAUD_RATE);
pinMode(TJA_WAKEUP_PIN, OUTPUT);
digitalWrite(TJA_WAKEUP_PIN, HIGH);
}
void loop() {
if (Serial1.available()) {
byte receivedByte = Serial1.read();
Serial.println(receivedByte, HEX);
}
}
I've noticed that the data I'm getting from the two programs seem to be different. I'm not sure why this is happening, as I believe the physical connections and the LIN signal are correct.
Data from first code:
80
80
0
2
0
80
80
80
21
68
60
0
80
80
0
2
0
80
80
10
0
10
0
E0
80
80
0
2
0
80
80
10
FE
80
80
0
2
0
80
80
10
0
10
0
E0
80
81
0
2
0
80
80
80
D0
79
18
7A
FE
80
81
0
2
0
80
80
7
0
10
0
E0
80
80
0
2
0
80
80
10
FE
80
80
0
2
0
80
80
11
84
10
0
E0
80
83
0
2
0
80
80
80
21
68
60
0
80
80
0
2
0
80
80
Data frome secound code:
FE
80
6
8
8
8
FB
80
FC
80
6
8
8
8
FB
80
D
8
8
8
58
80
6
4E
8
8
FF
80
FC
80
6
4E
8
0
FF
80
F0
80
6
4E
8
8
FF
80
FC
80
86
4E
8
8
FF
80
42
8
8
E8
FA
80
86
4E
8
5
FF
80
2C
8
84
8
FE
0
4
E
8
85
FF
80
F8
80
86
4E
8
5
FF
80
2C
8
4
8
F8
0
6
4E
8
85
FF
80
wpisz lub wklej tutaj kod
I'm having difficulty interpreting these data. I don't have a clear mapping of the identifier field to slave devices, and I'm not sure if the data are being correctly and fully received.
Could anyone provide some insight into why the data might be different between the two programs, and how I might interpret these data? Any help would be greatly appreciated.
Thank you in advance!