Author Topic: What is wrong with this circuit? Will it cause damage?  (Read 1146 times)

0 Members and 1 Guest are viewing this topic.

Offline shakedownTopic starter

  • Contributor
  • Posts: 25
  • Country: gb
What is wrong with this circuit? Will it cause damage?
« on: November 20, 2025, 09:10:06 pm »
I am not sure if this is the right place to ask but please advise me on what is wrong with this circuit.

I have attached the circuit, I got this circuit from GitHub and recalculated the base resistor values for the transistors. It is meant to request and read vehicle data by converting a single wire signal (K-Line @ 12V) from car's OBD2 port to microcontroller (3.3V - 4.0V) RX/TX for UART. It also has a buck converter which converts 12V to 3.3V to supply the microcontroller.

I am told this will fry my car's ECU but not told what I have done wrong. Could you please advise me what is wrong with this circuit and if it will damage my car's ECU? I looked on the oscilloscope as the communication was taking place and on the K line, the voltage is steady within 0-11V and it just looked like a normal UART/digital signal. The MCU GPIO is meant to help pull the K line low and high for 25ms for initialisation (called fast init). After initialisation or communication with ECU is established, the GPIO pin does not do anything.
« Last Edit: November 21, 2025, 11:41:38 am by shakedown »
 

Online moffy

  • Super Contributor
  • ***
  • Posts: 2908
  • Country: au
Re: What is wrong with this circuit? Will it cause damage?
« Reply #1 on: November 20, 2025, 09:42:11 pm »
Maybe a small resistor in series with K_LINE, to limit any fault currents, but as long as the K_LINE is an open collector style bus, like I2C, it looks OK.
P.S. +12V can be anywhere between 10V-15V.
« Last Edit: November 20, 2025, 09:45:23 pm by moffy »
 
The following users thanked this post: shakedown

Offline shakedownTopic starter

  • Contributor
  • Posts: 25
  • Country: gb
Re: What is wrong with this circuit? Will it cause damage?
« Reply #2 on: November 20, 2025, 10:18:10 pm »
Maybe a small resistor in series with K_LINE, to limit any fault currents, but as long as the K_LINE is an open collector style bus, like I2C, it looks OK.
P.S. +12V can be anywhere between 10V-15V.

My electronics knowledge is very limited. From what I can understand, open-collector means a transistor's collector pin left floating or open. Internet says K line is open-collector. Is there a way to confirm this using a multimeter or otherwise? The one thing I could find is, in an open collector configuration the line stays high at idle and low when active. This is true.
« Last Edit: November 20, 2025, 10:21:17 pm by shakedown »
 

Online moffy

  • Super Contributor
  • ***
  • Posts: 2908
  • Country: au
Re: What is wrong with this circuit? Will it cause damage?
« Reply #3 on: November 20, 2025, 10:25:51 pm »
Maybe a small resistor in series with K_LINE, to limit any fault currents, but as long as the K_LINE is an open collector style bus, like I2C, it looks OK.
P.S. +12V can be anywhere between 10V-15V.

My electronics knowledge is very limited. From what I can understand, open-collector means a transistor's collector pin left floating or open. Internet says K line is open-collector. Is there a way to confirm this using a multimeter or otherwise? The one thing I could find is, in an open collector configuration the line stays high at idle and low when active. This is true.

Then you are fine, just put a 50R resistor in series with the K_LINE for test purposes. What is the purpose of the MCU_GPIO, is that for initiating a message?
 

Offline shakedownTopic starter

  • Contributor
  • Posts: 25
  • Country: gb
Re: What is wrong with this circuit? Will it cause damage?
« Reply #4 on: November 20, 2025, 10:36:47 pm »
Maybe a small resistor in series with K_LINE, to limit any fault currents, but as long as the K_LINE is an open collector style bus, like I2C, it looks OK.
P.S. +12V can be anywhere between 10V-15V.

My electronics knowledge is very limited. From what I can understand, open-collector means a transistor's collector pin left floating or open. Internet says K line is open-collector. Is there a way to confirm this using a multimeter or otherwise? The one thing I could find is, in an open collector configuration the line stays high at idle and low when active. This is true.

Then you are fine, just put a 50R resistor in series with the K_LINE for test purposes. What is the purpose of the MCU_GPIO, is that for initiating a message?

Ok I will use a 50R resistor but is the only way to confirm something is open-colllector to check it is high at idle and low when active? Does that mean UART is also in an open-collector config? Because it is also always high at idle and low when active on STM32.

Yes, the purpose of MCU_GPIO is to pull the K line low and high for 25ms each. This is how you begin to initialise communication with my car (ISO 14230). On my MCU I have set this pin to be PB6 (STM32).
« Last Edit: November 20, 2025, 10:38:28 pm by shakedown »
 

Online moffy

  • Super Contributor
  • ***
  • Posts: 2908
  • Country: au
Re: What is wrong with this circuit? Will it cause damage?
« Reply #5 on: November 20, 2025, 10:39:17 pm »
The 50R resistor is a safety, only for faults to limit the current, bu shouldn't affect normal operation.
 
The following users thanked this post: shakedown

Offline PGPG

  • Super Contributor
  • ***
  • Posts: 1214
  • Country: pl
Re: What is wrong with this circuit? Will it cause damage?
« Reply #6 on: November 21, 2025, 11:10:07 am »
My electronics knowledge is very limited. From what I can understand, open-collector means a transistor's collector pin left floating or open.

If it is OC (open collector) then there are 2 possibilities:
1. there is pull-up resistor in car,
2. there is not pull-up resistor in car.

More probably it is 2, but you can check it.

In case 1 measuring voltage at K_LINE (versus GND) with multimeter you will always get 0V (or close to 0 - just floating wire).
If you get 12V than certainly (provided it is OC) you have pull-up there.

It looks you are sure you are allowed to short K_LINE to GND with transistor. If so you are also allowed to short it with ammeter (if you are not sure it is OC you can use small resistor in serie with ammeter). The measured current (I expect 2..12mA) will tell you what is the in-car pull-up resistor.
Knowing it tells you what will be your output transistor current. Your output transistor will have to drive this current + 4mA for your R7. I suppose R7 is not needed, but can be - just car OC (and your output transistors (you have 2 of them)) will have to drive both in car pull-up current + your R7 current.

Surprising is that you drive your one output transistor base with (12V-0.7V)/(5.1k+1k) = about 2mA and the second one with (3.3-0.7)/220 = about 12mA while they both work at the same (don't known yet) output current.

If I were doing this circuit I would not have this transistor driven by R1 assuming R6 driven transistor will also do the job of this transistor.
To minimize collision risk in RS485 communication we use, uC needs to notice that bus is busy just when first start bit is issued and not after the whole byte is received and my brother (he writes code for our devices) never asked me to drive with RX signal two uC pins. I believe in each microcontroller code can temporarily disconnect UART from TX and issue initial pulse, but we have never used STM32. Maybe it is an exception.
« Last Edit: November 21, 2025, 11:18:58 am by PGPG »
 
The following users thanked this post: shakedown

Offline nigelwright7557

  • Frequent Contributor
  • **
  • Posts: 722
  • Country: gb
    • Electronic controls
Re: What is wrong with this circuit? Will it cause damage?
« Reply #7 on: November 21, 2025, 11:19:25 am »
I would be worried about damaging the cars ECU which could be very expensive.

I bought a ECU reader a couple of months back for less than £15.
It works very well.

Not worth the risk of doing it yourself.
 

Offline shakedownTopic starter

  • Contributor
  • Posts: 25
  • Country: gb
Re: What is wrong with this circuit? Will it cause damage?
« Reply #8 on: November 21, 2025, 11:33:51 am »
My electronics knowledge is very limited. From what I can understand, open-collector means a transistor's collector pin left floating or open.

If it is OC (open collector) then there are 2 possibilities:
1. there is pull-up resistor in car,
2. there is not pull-up resistor in car.

More probably it is 2, but you can check it.

In case 1 measuring voltage at K_LINE (versus GND) with multimeter you will always get 0V (or close to 0 - just floating wire).
If you get 12V than certainly (provided it is OC) you have pull-up there.

It looks you are sure you are allowed to short K_LINE to GND with transistor. If so you are also allowed to short it with ammeter (if you are not sure it is OC you can use small resistor in serie with ammeter). The measured current (I expect 2..12mA) will tell you what is the in-car pull-up resistor.
Knowing it tells you what will be your output transistor current. Your output transistor will have to drive this current + 4mA for your R7. I suppose R7 is not needed, but can be - just car OC (and your output transistors (you have 2 of them)) will have to drive both in car pull-up current + your R7 current.

Surprising is that you drive your one output transistor base with (12V-0.7V)/(5.1k+1k) = about 2mA and the second one with (3.3-0.7)/220 = about 12mA while they both work at the same (don't known yet) output current.

If I were doing this circuit I would not have this transistor driven by R1 assuming R6 driven transistor will also do the job of this transistor.
To minimize collision risk in RS485 communication we use, uC needs to notice that bus is busy just when first start bit is issued and not after the whole byte is received and my brother (he writes code for our devices) never asked me to drive with RX signal two uC pins. I believe in each microcontroller code can temporarily disconnect UART from TX and issue initial pulse, but we have never used STM32. Maybe it is an exception.


When I connect a voltmeter between K line and ground, I get +12V.

I am not sure if I am *allowed* to short K line to ground. I will do some more research.

So once I figure out the car's internal pull up resistor (V = IR, R = V/I) then I should recalculate the base resistor for the Q3 transistor? I should have labelled the transistors too. Edit: I have now labelled the transistors.

The reason why the signal is driven by Q1 transistor is because I need to specifically pull the K line low and high for 25ms. I could do it with MCU UART TX but I will need to check exactly how many bits to send to keep it low for 25ms. With GPIO I can just keep it low and hold/delay MCU for 25ms.

I am not sure if STM32 can do what you suggest, I will check. Is collisions bad for the ECU?
« Last Edit: November 21, 2025, 11:43:53 am by shakedown »
 

Offline shakedownTopic starter

  • Contributor
  • Posts: 25
  • Country: gb
Re: What is wrong with this circuit? Will it cause damage?
« Reply #9 on: November 21, 2025, 11:37:19 am »
I would be worried about damaging the cars ECU which could be very expensive.

I bought a ECU reader a couple of months back for less than £15.
It works very well.

Not worth the risk of doing it yourself.


Generic OBD readers cannot always get manufacturer specific data because they only use the standard PIDs (request codes). The generic OBD readers also cannot really be customised to give you certain alarms or flashing LEDs when you exceed certain numbers.

So I want to make this monitor for myself and not fry my ECU.
 

Offline tooki

  • Super Contributor
  • ***
  • Posts: 15549
  • Country: ch
Re: What is wrong with this circuit? Will it cause damage?
« Reply #10 on: November 21, 2025, 01:16:50 pm »
I have attached the circuit, I got this circuit from GitHub
Source, please?

and recalculated the base resistor values for the transistors.
For what reason?

I am told this will fry my car's ECU
By whom?


P.S. It is customary to draw schematics with signal flow from left to right, the opposite of how you’ve done it. Also, give symbols room to breathe. The ground symbol needs a stem, it’s not supposed to collide with e.g. the arrow on the transistor, resistors shouldn’t be right at a wire intersection, etc.
« Last Edit: November 21, 2025, 01:21:20 pm by tooki »
 

Offline aeg

  • Frequent Contributor
  • **
  • Posts: 399
  • Country: us
Re: What is wrong with this circuit? Will it cause damage?
« Reply #11 on: November 21, 2025, 01:17:54 pm »
You don't need one transistor for GPIO and another for TX. Just reconfigure the I/O pin as a GPIO, send your init, then configure it back to UART.

Consider just getting an OBDLink SX. If your car uses plain KWP2000 with vendor specific PIDs, it will do the job. On the other hand, it won't work with unusual L2 protocols like KWP71.

If you're worried about frying your car's ECU, start by getting a cheap ECU at a junkyard or eBay and testing on the bench.
 
The following users thanked this post: tooki

Offline shakedownTopic starter

  • Contributor
  • Posts: 25
  • Country: gb
Re: What is wrong with this circuit? Will it cause damage?
« Reply #12 on: November 21, 2025, 01:34:37 pm »
I have attached the circuit, I got this circuit from GitHub
Source, please?

and recalculated the base resistor values for the transistors.
For what reason?

I am told this will fry my car's ECU
By whom?


P.S. It is customary to draw schematics with signal flow from left to right, the opposite of how you’ve done it. Also, give symbols room to breathe. The ground symbol needs a stem, it’s not supposed to collide with e.g. the arrow on the transistor, resistors shouldn’t be right at a wire intersection, etc.

Source:
https://github.com/brucemack/hello-obd2
I think this person made this for ISO-9141 but I need it for ISO14230. Same thing except different initialisation and frame.

I have been working on this on and off for a while, I do not remember why I recalculated the base resistors, it might have been because I used different transistors or one of the values was wrong. Not sure. Sorry.

I have been told by an experienced electrical engineer I know that this circuit will fry my car's ECU.

Thanks for the advice, I will try to make better schematics, not an electrical engineer so I don't know these things.


« Last Edit: November 21, 2025, 01:47:53 pm by shakedown »
 

Offline shakedownTopic starter

  • Contributor
  • Posts: 25
  • Country: gb
Re: What is wrong with this circuit? Will it cause damage?
« Reply #13 on: November 21, 2025, 01:40:22 pm »
You don't need one transistor for GPIO and another for TX. Just reconfigure the I/O pin as a GPIO, send your init, then configure it back to UART.

Consider just getting an OBDLink SX. If your car uses plain KWP2000 with vendor specific PIDs, it will do the job. On the other hand, it won't work with unusual L2 protocols like KWP71.

If you're worried about frying your car's ECU, start by getting a cheap ECU at a junkyard or eBay and testing on the bench.

That is a good idea, I could just reconfigure the pin once communication has been initiated.

I have looked at OBDLINKs and others before but I dont think you can buzz alarms or set different coloured indications on your phone for different numbers. It also seems to use a phone or laptop which is not what I want. I want to have a permanent screen attached somewhere in my car. Later if I can figure out how to control radiator fan speed from my controller then I want to do that too or other vehicle body functions. And its just more fun to make your own thing (without breaking my ECU).

I do have a cheap junk ECU from a completely different car but which also uses K line for testing this circuit. I have had it connected for like 12-15 hours straight with and without testing (idling) so I don't know what/if anything is wrong with the circuit I posted.

« Last Edit: November 21, 2025, 01:45:36 pm by shakedown »
 

Offline tooki

  • Super Contributor
  • ***
  • Posts: 15549
  • Country: ch
Re: What is wrong with this circuit? Will it cause damage?
« Reply #14 on: November 21, 2025, 02:47:31 pm »
Source:
https://github.com/brucemack/hello-obd2
I think this person made this for ISO-9141 but I need it for ISO14230. Same thing except different initialisation and frame.

I have been working on this on and off for a while, I do not remember why I recalculated the base resistors, it might have been because I used different transistors or one of the values was wrong. Not sure. Sorry.

I have been told by an experienced electrical engineer I know that this circuit will fry my car's ECU.

Thanks for the advice, I will try to make better schematics, not an electrical engineer so I don't know these things.
Thanks, having the original helps see what you changed.

It may be wise to add some input protection (TVS diodes or similar) to the MCU and to the. DC-Dc converter’s input, just because automotive power is so notoriously dirty, full of spikes and noise that can easily significantly exceed the average voltage.

I would change the 10k/20k ohm (i.e. 1/3 divider) voltage divider for RX to 22k/68k ohms (a ~1/4 divider, at lower current), so that you remain much closer to the 3.3V of the MCU. Even though many STM32s have 5V-tolerant inputs, I don’t see any reason to tempt fate, especially if voltage spikes occur.

Since the transistors are all acting as switches, there’s likely no reason to use different base currents. Presumably you started recalculating for 3.3V instead of the 5V original.

I don’t see any way your circuit would fry the ECU, either, though I’m no expert on automotive electronics.
 
The following users thanked this post: shakedown

Offline PGPG

  • Super Contributor
  • ***
  • Posts: 1214
  • Country: pl
Re: What is wrong with this circuit? Will it cause damage?
« Reply #15 on: November 21, 2025, 08:02:55 pm »
When I connect a voltmeter between K line and ground, I get +12V.

So if it is OC then there is also pull-up resistor in the car. That means that your circuit can work without pull-up resistor at your side. But there is nothing against having it also.

I am not sure if I am *allowed* to short K line to ground. I will do some more research.

But you 'short' it to GND with your transistors. If you are afraid of doing it with ammeter than use 1k resistor to GND and measure voltage on it. It will allow you to calculate pull-up resistor value.

So once I figure out the car's internal pull up resistor (V = IR, R = V/I) then I should recalculate the base resistor for the Q3 transistor? I should have labelled the transistors too. Edit: I have now labelled the transistors.
Practical rule is that knowing the collector current (we don't know it yet) you should drive base with 1/20 to 1/10 of it.

The reason why the signal is driven by Q1 transistor is because I need to specifically pull the K line low and high for 25ms. I could do it with MCU UART TX but I will need to check exactly how many bits to send to keep it low for 25ms. With GPIO I can just keep it low and hold/delay MCU for 25ms.

I was writing about disconnecting UART temporarily from the pin so using it as GPIO and not using UART to issue long pulse, but each way to get what you need is ok.

Is collisions bad for the ECU?

I mentioned collisions (in RS485) only to describe why we need to notice start bit beginning (what from UART you can't get) and that we don't use second pin to get it so I suggest also to use one uC pin (I am frugal by nature) and not two to drive your output.
In your case collisions are not danger for hardware in any way as outputs not fight with each other (both drive signal line to GND). Only software can be confused seeing two transmissions mixed.
« Last Edit: November 21, 2025, 08:09:01 pm by PGPG »
 
The following users thanked this post: shakedown

Offline shakedownTopic starter

  • Contributor
  • Posts: 25
  • Country: gb
Re: What is wrong with this circuit? Will it cause damage?
« Reply #16 on: November 23, 2025, 08:13:14 pm »
Source:
https://github.com/brucemack/hello-obd2
I think this person made this for ISO-9141 but I need it for ISO14230. Same thing except different initialisation and frame.

I have been working on this on and off for a while, I do not remember why I recalculated the base resistors, it might have been because I used different transistors or one of the values was wrong. Not sure. Sorry.

I have been told by an experienced electrical engineer I know that this circuit will fry my car's ECU.

Thanks for the advice, I will try to make better schematics, not an electrical engineer so I don't know these things.
Thanks, having the original helps see what you changed.

It may be wise to add some input protection (TVS diodes or similar) to the MCU and to the. DC-Dc converter’s input, just because automotive power is so notoriously dirty, full of spikes and noise that can easily significantly exceed the average voltage.

I would change the 10k/20k ohm (i.e. 1/3 divider) voltage divider for RX to 22k/68k ohms (a ~1/4 divider, at lower current), so that you remain much closer to the 3.3V of the MCU. Even though many STM32s have 5V-tolerant inputs, I don’t see any reason to tempt fate, especially if voltage spikes occur.

Since the transistors are all acting as switches, there’s likely no reason to use different base currents. Presumably you started recalculating for 3.3V instead of the 5V original.

I don’t see any way your circuit would fry the ECU, either, though I’m no expert on automotive electronics.

Should I add this TVS diode to the first main connection to the K line?

I will change the RX voltage divider but should I recalculate the base resistors for all transistors to have the same base currents or can I leave it as is? Like PGPG said, I could find the actual current of the K line and use that for calculation.

Thank you for your help.




When I connect a voltmeter between K line and ground, I get +12V.

So if it is OC then there is also pull-up resistor in the car. That means that your circuit can work without pull-up resistor at your side. But there is nothing against having it also.

I am not sure if I am *allowed* to short K line to ground. I will do some more research.

But you 'short' it to GND with your transistors. If you are afraid of doing it with ammeter than use 1k resistor to GND and measure voltage on it. It will allow you to calculate pull-up resistor value.

So once I figure out the car's internal pull up resistor (V = IR, R = V/I) then I should recalculate the base resistor for the Q3 transistor? I should have labelled the transistors too. Edit: I have now labelled the transistors.
Practical rule is that knowing the collector current (we don't know it yet) you should drive base with 1/20 to 1/10 of it.

The reason why the signal is driven by Q1 transistor is because I need to specifically pull the K line low and high for 25ms. I could do it with MCU UART TX but I will need to check exactly how many bits to send to keep it low for 25ms. With GPIO I can just keep it low and hold/delay MCU for 25ms.

I was writing about disconnecting UART temporarily from the pin so using it as GPIO and not using UART to issue long pulse, but each way to get what you need is ok.

Is collisions bad for the ECU?

I mentioned collisions (in RS485) only to describe why we need to notice start bit beginning (what from UART you can't get) and that we don't use second pin to get it so I suggest also to use one uC pin (I am frugal by nature) and not two to drive your output.
In your case collisions are not danger for hardware in any way as outputs not fight with each other (both drive signal line to GND). Only software can be confused seeing two transmissions mixed.

I understand what you mean now, I can reconfigure the one of the UART pins as GPIO at initialisation then put it back as a UART pin. Thank you for your help.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf