Two control signals one GPIO

I have two active low signals (CHRG and STDBY) from a single li-ion battery charger IC TP4056 Datasheet.

CHRG is high impedance when charging is not taking place and Low when charging is taking place
STDBY is high impedance when charging is not complete and low when charging is complete.

I am using this IC within an embedded circuit controlled by ESP32, but I only have one GPIO left and I want to detect whether charging is taking place and if the battery is fully charged.
Kindly suggest some solutions
ESP32 logic signals are 3.3V

Do you really mean high impedance or are you referring to a logic level HIGH?

high impedance not logic high. attaching the pin description for your reference:


Datasheet Picture above

So, I have attached a pullup, this way now the CHRG is low when batt is charging and high otherwise, and STDBY is low when the battery is fully charged and high otherwise.
So using this can anyone suggest a solution?

Please, post a picture of your ESP32 Dev Board.

How about creating a voltage divider and connect the single GPIO pin to the ADC and sample the voltage.

If both are at the high impedance state voltage will be VCC
if CHRG gets low, the voltage will be pulled to 66%VCC
if STDBY gets low the voltage will be pulled to 50% VCC

In case it's needed, if both get low it will be pulled further down, below 50% of VCC.

so with the pull-ups that's that status of your pins

LOW HIGH
CHRG Charging Not Charging
STDBY Complete Not Complete

You want to detect whether charging is taking place and if the battery is fully charged.

Another way to represent this is

CHRG STDBY state
LOW LOW impossible (can't be both charging and complete)
LOW HIGH Charging, not fully charged
HIGH LOW Not Charging, fully charged
HIGH HIGH impossible (can't be both not charging and not complete)

so if the components can never be in the impossible situation then just looking at one of them you'll know what's the status.

eg if CHRG is LOW then you know it's Charging, not fully charged and if CHRG is HIGH then you know it's Not Charging which means fully charged

1 Like

Low Low is possible if the battery is not present, or (I think) if a battery protection function has kicked in.

And depending on what the pullup resistors are connected to, High High could occur if there is no, or insufficient, power coming into the charger.

I think the voltage divider suggestion would work. It would give a different result for all four possibilities.

OK if they are possible then as you can't get 4 possibilities with only 1 bit, you either need 2 bits (2 GPIOs) or indeed move to the analog representation

Yes, but it depends on what he really needs to know. Will he be doing something different depending on whether the battery is charging or is fully charged? Or does he just need to know that one or the other is true, and that no "impossible" is taking place. In that case a SN74LVC1G86 would work. But as you say, a second GPIO is really the answer if he can find one.

I just want to know if charging is taking place or not and if the battery if fully charged

This is indeed a way to know. I was trying to make out a solution with a MOSFET. I think I would need to use a PMOS. just need to figure out the configuration

This is helpful. Thanks.

If you have an analog pin free you can use it as a digital I/O.

I did not take consideration of the fact that battery not present or faulty would also be one of the states, moreover I also need to take care of low battery State. My circuit contains an LCD which would show all these status i.e.
Charging
Fully charged
Battery fault/ not present
Low battery

can you go for a different MCU with more pins ? Which esp32 are you using?

I dug out my supply of TP4056 modules, and found that when there is no battery present, the charging LED flashes, and the fully-charged LED is on solid. I suspect that behavior may vary from one manufacturer to another.

I have never tried it, but my suspicion is that if the battery discharges to the point that the protection circuit kicks in, it would behave like no battery present. That's because the protection circuit disconnects the negative battery terminal from the circuit ground. But I've never tested it.

My memory from trying to get the TP4056 to work with solar panels is that at certain intermediate voltages both LEDs may light up solid. But that should not happen if you are charging from 5V USB power.

What if you just measure the battery voltage on an ESP32 analog pin through a resistive divider, and show that number on the display. Then the user could draw his own conclusions about the state of the battery. Of course the divider would draw current, which is not ideal.

no. mcu has to remain same

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.