OBD/K-Line Buffer Circuit

Status
Not open for further replies.
I'm also wondering if i need to change the resistor values used in the TX portion of the circuit...
 
I believe that circuit will work. When the line is high (at 12V), the 10K resistor will pull the Teensy3 pin to approx 3.9 volts, and inject about 0.81 mA. The Teensy 3.0 pins can handle up to 10 mA of injected current, so 0.81 mA should be fine.

If you're feeling really cautious, you could increase R2 to 47K and probably still receive the data.
 
I'm also wondering if i need to change the resistor values used in the TX portion of the circuit...

We're talking about this circuit, right?

obdii_avr.gif

The TX part looks fine. The 3.3V output from Teensy 3.0 will result in less current through R1 and Q1's base, but it should still be plenty. If you're really concerned, you could lower R1 to 4.7K.
 
yep thats the one.

Okay cool, thanks for the guidance!

And thanks for putting together such an awesome little dev board!
 
The transistors are not critical -- if you are in the US, 2N2222's from Radio Shack will work -- nearly any NPN will do, but consider one with BVCEO (breakdown votlage) above 40 V (you get nasty spikes in a car). For more robustness, break the 10k R2 into two 4.7k's and connect a 4.7 V zener between the junction and GND.

If you want the most robust implementation, this does work well: http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=MC33662 -- you can interface directly from the Teensy's 3.3 V inputs and ouptuts by driving its EN pin also from a T3 output !
 
Last edited:
I believe that circuit will work. When the line is high (at 12V), the 10K resistor will pull the Teensy3 pin to approx 3.9 volts, and inject about 0.81 mA. The Teensy 3.0 pins can handle up to 10 mA of injected current, so 0.81 mA should be fine.

If you're feeling really cautious, you could increase R2 to 47K and probably still receive the data.

Hey Paul,

I have very similar problem to solve:

Currently on teensy 2.0++ I have the Lin bus connected to Teensy Uart RX via diode and with 10k pull up resistor from Teensy 5v pin. The Uart is used for receiving only and the diode is connected so that it pulls down the UART so no 12v positive will be injected. It works very well on Teensy 2.0. Now when I use the same circuit on teensy 3.0 and the pull up is connected to 3V the Uart receiving stops after few seconds. When debugging with Serial1.print it just does not send any data. When I unplug the Lin bus and reconnect it it continues to work and freezes again. Is this problem related to hardware or it could be software(teensyduino and arduino related)?
UART speed is 9600 and the code is frome Teensy examples:

if (Uart.available() > 0) {
incomingByte = Uart.read();
Serial1.print("UART received: ");
Serial1.println(incomingByte, DEC);


Second question is about detecting uart frame error on Teensy 3.0:

On teensy 2.0++ I can use following code:

if (1<<FE1) {

delayMicroseconds(frameerrordelay); //after Frame Error Tbit to Sync Field

while(!Uart.available()) { delayMicroseconds(1);}
if (Uart.available()) sync= Uart.read();


On teenys 3.0 this obviously does not compile because FE1 is for ATMEGA chip. Is there an alternative for Teensy 3.0?

Regards,

Jaanus
 
Last edited:
It's probably like this:
LIN.PNG

That might be OK, although I assume you really connected the R to 3.3 V, not 3 V ? With a diode your logic '0' is only 0.7 V, but this should be OK
Note this circuit could damage the T3 if qrounds are not good -- best to also add at least 100 ohm in series with the LIN bus line. Use ~ 1k for the pullup.
 
It's probably like this:
View attachment 1131

That might be OK, although I assume you really connected the R to 3.3 V, not 3 V ? With a diode your logic '0' is only 0.7 V, but this should be OK
Note this circuit could damage the T3 if qrounds are not good -- best to also add at least 100 ohm in series with the LIN bus line. Use ~ 1k for the pullup.

The circuit is the same as on picture. The R is connected to pin which is next to teensy 3.0 GND pin and it is marked as 3v. So i should choose 1k pull-up not the 10k i am using?

Jaanus
 
10k should be OK.

That pin is 3.3 V -- http://www.pjrc.com/teensy/pinout.html -- no problem with that.

Is there any way you could be pulling the bus line below ground level on the T3 ?

So i did some modifications:

Now i have the pull-up from 3,3v pin with the value 1,2Kohms and series resistor before BAT85 diode is 120 ohms.
I receive data but some two initial bytes sent by Lin master are missing...

Is the pull-up now two strong and the master won´t pull it down or the series resistor is not allowing it to pull down to 0,7V?


So the current summary:
Arduino 1.05 and Tduino 1.16

Teensy 2.0++
Pull-up from 5v pin and Lin to Uart RX via BAT85
is able to monitor the bus properly

Teensy 3.0
1,2K Pull-up from 3,3V pin and Lin to Uart RX via BAT85 and 1,2R
looses two first bytes(Sync and PID) -


Both circuits are tested with same bus. Unfortunately I don,t have the oscilloscope to do the troubleshooting. May be I should try the circuit with resistor and zener...

I have tested the circuit with T2.0++ and MCP201 and it worked well but the additional chip requires another pcb which is not a good solution.
 
Last edited:
Those values should be OK. The BAT85 is a schottky diode, so the voltage drop is only about 0.3 V which is even better.

If you don't have a 'scope, just program the pin to be a standard input, and write a small loop to read and print the value. Then adjust the V on the bus (manually & read with a voltmeter) and see that you can easily get '1's and '0's. The T3 has a small amount of hysteresis on the input pin, so the voltage required to change from a 0 to a 1 is a little higher than tant required from a 1 to a 0.
 
As nearly as I can tell, LIN bus signal levels are zero to Vbat (12V), with the recommended detection threshold at 50% (6V) with 0.1V hysteresis.

Here's what I'd recommend to try receiving this signal: just 2 resistors.

lin_receive.png

Do not use less than 22K between the RX1 pin and the LIN bus. Teensy3 can handle a small current injected into the pin, so 22K should limit the current to a save level. You might try experimenting with the 10K resistor. A slightly lower value might work better, perhaps 8.2K or 6.8K?

I would NOT recommend using the diode circuit above. If there is a negative spike on the LIN bus, it will probably destroy the Teensy3. Automotive systems are terribly noisy, so I wouldn't risk connecting such a signal to any pin on Teensy through anything other than a fairly high value resistor (like 22K) or a proper transceiver chip, like that MCP201.
 
I will try this circuit. The teensy 20++ has survived the diode circuit 6 months now:)

One more questions is related to teensy bootloader - does it completely protects the code inside the chip? If would like to make a small production with teensy and later provide firmware updates is it possible to write some id number to eeprom at first and later provide the firmware update so that it works only with these teensys which have the id in eeprom?
 
What about Lin break detection in Teensyduino? Freescale datasheet even mentions that it is possible to sed the FE and Lin break detection:
Framing Error Flag
FE is set when a logic 0 is accepted as the stop bit. FE does not set in the case of an overrun or while the
LIN break detect feature is enabled (S2[LBKDE] = 1). FE inhibits further data reception until it is cleared.
To clear FE, read S1 with FE set and then read D. The last data in the receive buffer represents the data
that was received with the frame error enabled. Framing errors are not supported when 7816E is set/
enabled. However, if this flag is set, data is still not received in 7816 mode.Framing errors are not
supported in 709 mode.
0 No framing error detected.
1 Framing error.
 
The transistors are not critical -- if you are in the US, 2N2222's from Radio Shack will work -- nearly any NPN will do, but consider one with BVCEO (breakdown votlage) above 40 V (you get nasty spikes in a car). For more robustness, break the 10k R2 into two 4.7k's and connect a 4.7 V zener between the junction and GND.

If you want the most robust implementation, this does work well: http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=MC33662 -- you can interface directly from the Teensy's 3.3 V inputs and ouptuts by driving its EN pin also from a T3 output !

Necrothreading a bit, but I'm pretty new to all this and I'm trying to do something similar to what OP did by interfacing the teensy with the iso k-line in my subaru. I have it working with the circuit shown in post 4 but would like to use the IC you mention in case there's any interest from friends in me building these for them.

Reading the datasheet for this, I'm a bit confused about what should be hooked up where (as I said, I'm new). I would want to attach the teensy tx to the mc33662 rxd pin, but the datasheet for the mc33662 has that pin labeled as an output. Do I connect tx-txd and rx-rxd (teensy-mc33662)?

Thanks
 
On the MC33662, RXD (pin 1) is LIN received data -- connect that pin (output on MC33662) to an input on Teensy. Similarly, TXD on the MC33662 (pin 4) is an input on that IC -- drive it with an output on Teensy.
 
On the MC33662, RXD (pin 1) is LIN received data -- connect that pin (output on MC33662) to an input on Teensy. Similarly, TXD on the MC33662 (pin 4) is an input on that IC -- drive it with an output on Teensy.

Thanks for the quick response, and for helping instead of telling me to RTFM (too many forums out there with that attitude towards newbies...). So the Teensy will be powered through a 5v regulator hooked up to the car's acc circuit (on when car is acc+run). 12v comes from the car, 3.3v comes from teensy output. Does this seem correct?
bH7jCJQ.png
 
Was anyone able to read anything from a car with the first circuit?
I'm trying to read from a KWP2000 car, although unsure if slow (5 kbaud) or fast (10.4 kbaud) and the Echoboth example on Serial1.
Not receiving anything yet and have nowhere to buy a STN1110 or ELM327 chip.

I have also been playing around with this library https://github.com/stanleyhuangyc/Freematics but I think that requires data interfaced through an ELM327 (AT commands etc.).

I can't however be sure that the car is KWP2000, it could be ISO 14230-4, but since its made in 2002, lists of protocols show both, I guess they went from KWP to ISO some time during that year.
 
Last edited:
So it's been just about a year since I worked on this at all (wow :O) I dug everything back out today and got it working with the 2-way k-line buffer similar as post 4 (in response to Foyd - I got it working but it required transistors on both the send and receive sides... i can't find the diagram I followed but it did work). I then hooked up the mc33662 as shown in my previous post and got nothing. I don't even know how to trouble shoot - can anyone point me in the right direction?

Thanks!
 
About a month ago I was experimenting with reading data from an OBD-II bus, ISO 1941-2 to be precise. I have no experience with the chip you are using, but I can point out some alternatives, you have probably come across the MC33290, which seems to be the most commonly used chip in other projects on the internet, this chip is not manufactured anymore. You can still order it on Ebay, as an alternative you might try the sn65hvda100 (or sn65hvda195) chips from TI.
I have used all three of these with success, I just used the typical application circuit from the datasheet. (I put the code I wrote to read from the ISO 1941-2 bus on github, but I'm not able to provide any support for it at the moment.)
 
Status
Not open for further replies.
Back
Top