# Using a GPIO pin as a power source

I have an STM32F2 (reference manual here) which is connected to a GPS receiver through 5 pins. One of these pins is a power supply pin for the GPS.

All pins on the micro-controller are GPIO pins that need to be configured. (E.g. configure as input, output, floating, open-drain, push-pull, etc.) The ARM reference manual does not discuss GPIO pins as power sources.

What GPIO configurations do I need to apply to a power supply pin?

-
Check the power consumption of the GPS receiver, and the source capability of the GPIO pins. It probably won't be enough. – clabacchio Apr 27 '12 at 9:39
If your load consumed only a bit more than what one GPIO pin is able to provide (with a usable voltage after the drop), and you were really really space constrained, you could tie N GPIO pins together, and drive them all equal, to sum their currents. I've done this for light loads, but a GPS receiver is not the case. – Telaclavo Apr 27 '12 at 11:51
@Telaclavo, I've done this and it works, but be sure to check the microcontroller's maximum total current spec as well as the individual pin current spec. – markrages Apr 27 '12 at 16:22
@markrages Sure, I always check that. – Telaclavo Apr 27 '12 at 17:04

Note:
This answer was originally written before we knew anything about the receiver, like its 1.8V power supply. Telaclavo's answer is good. As a more general answer the PNP/MOSFET solution remains; you don't want to power parts of your circuit from a microcontroller's I/O pin.

You don't want to do that! You'd configure the pin as output and make it high to provide power to the GPS receiver, but microcontrollers I/Os can only supply limited current, 25mA for the STM32F205xx (page 62 of the datasheet), which will be too low for powering your (and any other) GPS receiver (34 to 38 mA, as stated in the datasheet)

Use the I/O pin to drive a PNP transistor which will supply the required current.

Note that using a PNP inverses your logic: a logic low will turn the receiver on.

I would not use an NPN for this. In common emitter it would mean that the receiver's ground is a few hundred mV above ground, and a circuit should have one single ground which is the same for every component. In common collector you would lose too much of your 3.3V power supply.

edit
Wouter would use a MOSFET instead of a BJT, and that's a good alternative. Just make sure you choose a logic-level FET, which will give you enough current at a $V_{GS}$ of -3.3V. The Rohm RZE002P02 is a suitable type. It will also have a lower voltage drop if your receiver needs less than about 200mA.

edit 2 (re clabacchio's addition of a datasheet)
This device operates at 1.8V, the STM32 at 3.3V. You can use an LDO with an enable input and control that from your microcontroller. No transistor needed. (Thanks for the suggestion, markrages.) You'll also need level shifters for the data.

-
I'd suggest a logic-level P MOSFET, but the principle is the same. – Wouter van Ooijen Apr 27 '12 at 9:56
If you have an LDO, the PNP/P-channel transistor is built-in. Just choose an LDO with an enable input and drive that with the micro. – markrages Apr 27 '12 at 13:08
Any particular reason why you suggest a PNP over an NPN? – Saad Apr 27 '12 at 13:17
@Saad - come to think of it: in the common collector the output voltage at the emitter will be 0.7V lower than the base voltage, so you have a higher voltage drop, which also means higher dissipation in the transistor. – stevenvh Apr 27 '12 at 13:52
@Telaclavo - You can have multiple power supplies, but you have only one single ground in your system! – stevenvh Apr 28 '12 at 6:17