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.
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;
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