I'm trying to design a circuit to switch power supply from USB +5V to battery when the USB is disconnected. This circuit will power a WeMos D1 mini board, which needs a 3.3V input voltage, so the USB 5V voltage is converted to 3.3V through a LDO regulator, while battery voltage is already 3.3V.
I'm trying to select the power source through a FDN340P p-mosfet, like in the diagram below, but it doesn't work because when USB is disconnected, and the battery power is applied to Vcc, it goes backwards into the voltage regulator and Vin rises to 3V, switching off the p-mosfet.
I've tried also putting a 1N4004 diode between Vin and the mosfet gate, but voltage doesn't drop across the diode (probably because current is too low?).
How can I keep the mosfet switched on when USB is disconnected?