LIN Sensor reading trouble

Dear Reader

I am trying to read any kind of feedback from a LIN sensor. I am using an MCP2003B click shield with an Arduino mega as it allows you to communicate via hardware serial on tx1 and rx1. I send a break field, sync and id to the sensor as stated on it's datasheet every 200ms at 19200 baud as it needs. However, when I try to print the values, I simply receive the sync and ID I sent it? When i disconnect the sensor from power Serial.available() no longer runs and It return no response, very confusing I tested the Voltage of the LIN bus I read 12V (power supply). I believe this should be low when the LIN bus is communicating? Any help would be greatly appreciated.

#define LIN_SERIAL Serial1 //tx1 rx1
#define REQUEST_INTERVAL 200 // 200ms
#define LIN_REQUEST_ID 0x27
#define LIN_FRAME_SIZE 8

unsigned long lastRequestTime =0; // Time tracking for response interval
uint8_t linResponse[LIN_FRAME_SIZE]; //array of size 8 buffer for linresponse

void sendLINHeader() {
//send break signal(13+ bits of low)

Serial.flush();
Serial.begin(12000);
Serial.write(0x0);
Serial.flush(); // send 0x00 at lower baud rate to give the break character
Serial.begin(19200);

Serial1.write(0x55);// sync byte
Serial1.write(0x0E);// ID

}

void setup() {

Serial.begin(115200);

Serial1.begin(19200); //specified baud

delay(1000);

digitalWrite(53,HIGH); // CS high to put mcp2003b in ready mode (datasheet)

}

void loop() {

unsigned long currentTime = millis();

if (currentTime - lastRequestTime >= 200) {
lastRequestTime = currentTime;

sendLINHeader(); //send header every 200ms

Serial.print("RAW LIN RESPONSE ");
int count =0;
while(Serial1.available()) {
uint8_t byteRead = Serial1.read();
if(byteRead < 0x10) Serial.print("0");
Serial.print(byteRead,HEX);
Serial.print(" ");
count ++;
}

if(count ==0) {
Serial.println(" No response");
}

else {
Serial.println();
}

}

}

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination

https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum

Please post your full sketch, using code tags when you do

Posting your code using code tags prevents parts of it being interpreted as HTML coding and makes it easier to copy for examination

In my experience the easiest way to tidy up the code and add the code tags is as follows

Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.

It is also helpful to post error messages in code tags as it makes it easier to scroll through them and copy them for examination

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.