Toyota / Lexus use a protocol called BEAN (Body Electronics area Network) to communicate between various ECU's in the vehicle. I want to intercept this data. This is because I have an engine from a Lexus that I am putting in a boat, and most of the "Dash" information, eg Engine temp is available in this data stream.
I have found enough information on the net to understand what the protocol looks like. Basically it has one start bit and then up to about 15 bytes of data. The baud rate is supposed to be 10K.
So my first approach was to write a program that used a Hardware interrupt (INT0) to capture the edge of the start bit. This then installed a timer1 interrupt that was set to expire in 1.5 bits time, this should be about smack in the middle of the first data bit.
When the timer interrupt occurs the timer interval is changed to 1 bit width, and the status of the data pin is recorded. It continues in this fashion until I detect the end of data, currently I am just looking for a couple of zero bytes.
From there the stored data is currently sent out the serial port.
All of that worked fine in theory but the captured data wasn't making sense so out came the scope. From this I determined that the Baud rate of the data stream was actually a little less than 10K, so I made adjustments to counter that. I also modified the Timer1 interrupt routine to turn on a DO so that I could compare the incoming data stream to when the interrupt routine was sampling.
I have the luxury of a digital scope and have discovered the BEAN datastream has a bit of jitter in the bit width and this causes the sync to drift out over a couple of bytes. I have spent ages playing with the timing but cannot get it to the point where it doesn't drift out.
I had a couple of scope pictures to put here but the system wont let me.
So my new plan was to keep the hardware interrupts enabled and use this to "re-sync" the timer on every "1". The protocol incorporates "bit stuffing" and so in theory there should not be more than 5 bit periods before a "1" comes along to resync off of.
But I can't get the Timer1 routines to achieve this, the stop/restart/start methods all seem to generate false interrupts so I am about to dive into direct control of Timer1 but I thought I would ask if anyone had any better ideas about how to approach this before I start.
