How to detect serial break

I am planning to use teensy uart for LIN recepition but I have not seen any good examples how to detect 13 bit long serial break. Should I use uart and wait until 0x00 is received or should I use pinmode and count bit low times with delays?

Regards,

Jaanus

You might be interested in: GitHub - gandrewstone/LIN: The LIN protocol implemented over Arduino APIs (Serial and Digital IO)

Hi James!

Do you know how the code in the link works? There are some parts of the code that i don't understand and could really use some help!

I tried a few thing and found that this worked out alright for me to detect a serial break on the hardware serial

#include <TimerOne.h>

volatile unsigned long tmr1,baud1;
volatile uint8_t n;

void timeout_1(){
  Timer1.StopTimer();
  if(digitalRead(0)==HIGH){
    Serial.begin(baud1);
    Serial.println("Data Byte"+String(n));    
  }
  else{
    Serial.begin(baud1);
    Serial.println("Serial Break"+String(n)); 
  }
}

void setup() {

  baud1=9600;

  pinMode(0,INPUT);
  
  Serial.begin(baud1);
  tmr1 = 500000/baud1; //timer1 period in microseconds

  Serial.println("READY!");
}

void loop() {
  if(Serial.available()) {
    n  = Serial.read();
    Serial.end();
    Timer1.EnableTimerInterrupt(timeout_1,tmr1); //set timer interrupt(period=1/(2*Baud)). Call 'timeout_1' on interrupt
  }
}