2026-02-06 8:48 PM
Hey team,
I am working on a project using the STM32F103CB MCU. The device operates from both USB and battery power. The battery configuration consists of four 1.5 V alkaline cells arranged as 2S2P, providing a nominal 3 V supply. USB power is provided at 5 V.
When both power sources are connected simultaneously, the PCB is designed to prioritise USB power.
However, when the USB cable is unplugged while the battery remains connected, the MCU core resets and the LCD connected to the PCB hangs, resulting in no further operation.
I am using the Arduino IDE for development. During debugging, I observed that the setup() function executes when the USB is unplugged, confirming that a reset occurs even though the battery supply is present. This indicates that the USB-to-battery transition is causing a reset condition rather than a seamless power handover.
I monitored the MCU supply voltage (VDD) during the USB disconnect event. Initially, the voltage dropped to around 2.0 V. After adding bulk capacitors, the voltage dip has been reduced, and VDD now drops to approximately 2.7–2.8 V, as measured using a multimeter.
To mitigate this issue, I enabled the Programmable Voltage Detector (PVD) with the threshold set to [2:0] = 001; however, the hanging issue still persists.
Could someone suggest a reliable solution or best practice to handle USB-to-battery power switching on the STM32F103CB, ensuring a clean transition without resets or peripheral lockups?
Thanks in advance for your support.
2026-02-07 12:18 AM
Hi,
so it looks like : the switching to batt supply is too slow, when removing the USB.
Try simple test: turn around AO3401 : exchange 3 -2 , D - S .
Now internal mosfet back diode is conducting, even if mosfet is off, giving always > 2.6V to the mcu3v3.
2026-02-07 8:10 AM
Your description is a little unclear. I understand that your alkaline batteries are connected to BAT_VDD and are switched to MCU_3V3 via MOSFET when the USB voltage is lost, correct?
In that case, MOSFET and R30/31 are not necessary because such a switchover can also be achieved using a simple Schottky diode in an OR circuit. Instead of MOSFET, you simply connect the anode of that Schottky to BAT_VDD and the cathode to MCU_3V3.
In such an OR circuit, the higher voltage always has priority. Many decades ago, my professor taught me: "A Schottky is the fastest thing on earth," which is still true today. In this respect, the OR would switch to battery operation almost immediately as soon as the voltage from U1 fails or is lower than BAT_VDD.
Regards
/Peter
2026-02-07 9:21 AM
Thank you for your clarification and update.
Your understanding is correct. I would like to add a few more points for better clarity. We have connected four 1.5V batteries in a series–parallel configuration, which provides 3V to the circuit.
The reason for adding the MOSFET is to manage the power‑source priority. When the battery is connected, and a USB source is also connected (to the MOSFET gate), the priority shifts to the USB supply. When the USB is not present, the circuit operates from the battery power.
I also have one clarification regarding replacing the Schottky diode for the priority-selection process. Yes, your professor’s explanation is 100% correct.
If we connect the anode of the Schottky diode to BAT_VDD and the cathode to MCU_3V3, the MCU will receive around 3.1V to 2.7V from this path. Below 2.7V, the battery will not be used since our system stops operation at the low‑battery threshold. Since we already included a diode (D1) in the circuit to prevent reverse current, even though U1 provides a stable 3.3V, after D1, the available voltage will be around 3.08V to 3.15V. So, we thought of going with a MOSFET circuit here.
Anyway, we will check and evaluate this option and update you.
Thank you very much for your input.