I know nothing about LIN but feel like your logic may not be syncing properly ( I admit I didn't go over it with a fine tooth comb...)
(EDIT: N/M I see what you're doing now. Probably better than my code since you look for the break...)
Any chance this does anything different?
#include <SoftwareSerial.h>
// https://github.com/zapta/linbus/tree/master/analyzer/arduino
#include "lin_frame.h"
#define SYN_FIELD 0x55
// Pins we use for MCP2004
const uint8_t pinRX = 10;
const uint8_t pinTX = 11;
const uint8_t pinFault = 14;
const uint8_t pinCS = 8;
enum eLINStates
{
SEEK_SYNC = 0,
GET_ID_DATA_CS
};
SoftwareSerial LINBusSerial( pinRX, pinTX );
byte
b, i, n;
LinFrame frame;
void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
// Open serial communications to host (PC) and wait for port to open:
Serial.begin(9600, SERIAL_8E1);
Serial.println("LIN Debugging begins");
LINBusSerial.begin(19200);
pinMode( pinCS, OUTPUT );
digitalWrite( pinCS, HIGH );
pinMode( pinFault, OUTPUT );
digitalWrite( pinFault, HIGH );
frame = LinFrame();
}//setup
void loop()
{
static uint8_t
stateLIN = SEEK_SYNC;
if( LINBusSerial.available() )
{
b = LINBusSerial.read();
switch( stateLIN )
{
case SEEK_SYNC:
//not sure if we can detect a break using SoftwareSerial so all we can do is just check
//for the sync byte (0x55)
if( b == SYN_FIELD )
{
frame.reset();
stateLIN = GET_ID_DATA_CS;
}//if
break;
case GET_ID_DATA_CS:
if( frame.num_bytes() > LinFrame::kMaxBytes )
{
stateLIN = SEEK_SYNC;
}//if
else
{
frame.append_byte(b);
if( frame.isValid() )
{
digitalWrite(LED_BUILTIN, HIGH);
dump_frame();
stateLIN = SEEK_SYNC;
digitalWrite(LED_BUILTIN, LOW);
}//if
}//if
break;
}//switch
}//if
}//loop
void dump_frame()
{
uint8_t
b;
for (i = 0; i < frame.num_bytes(); i++)
{
b = frame.get_byte(i);
if( b <= 0xf )
Serial.write( '0' );
Serial.print( b, HEX);
Serial.write( ' ' );
}//for
Serial.println();
}//dump_frame