cancel
Showing results for 
Search instead for 
Did you mean: 

Control of a MOSFET by STM32F4 DISCOVERY

Gigli.Dario
Associate II
Posted on March 12, 2013 at 12:39

Hello, 

I'm using the STM32F4 discovery and I need to control the state of a MOSFET to enable a relè. Precisely if the USART1 receives a particular comand a pin has to generate a high tension level to set the MOSFET ON and enable so a relè (5V). 

Is there a example to set a tension level by pin?

THANKS 
5 REPLIES 5
frankmeyer9
Associate II
Posted on March 12, 2013 at 13:09

Your request is somehow imprecise, but as I understand it, you want to switch a relais from digital output. As far as the MCU is concerned, a standard GPIO functionality is all you need, i.e. set the GPIO high or low.

However, the GPIO output will only reach 3.0V high level with the F4 discovery, and can probably not drive a relais directly. You can use a MOSFET to drive the relais, but you will a hardl time to find a type with the gate threshold voltage small enough. That means, you probably can't drive a MOSFET fully on (assuming an enhancement type).

Instead, I suggest a bipolar (BJT) transistor (npn type), which requires just about 0.7V.

And don't forget the flyback diode across your relais !

Gigli.Dario
Associate II
Posted on March 12, 2013 at 13:18

Thank you, your response are very satisfactory. So it is the same mode to turn on and off a led, isn't it?  

frankmeyer9
Associate II
Posted on March 12, 2013 at 14:57

So it is the same mode to turn on and off a led, isn't it? 

 

For the MCU, or logically, yes.

But electrically, you need to take the required currents into account. Signaling LEDs need about 1mA ... 20mA to light up. The 20mA figure is often too much for a GPIO, so you would need a driver here, too.

For your relais, you need to check the datasheet, it specifies the current required. I'm pretty sure it exceeds the capability of a stm32 GPIO pin.

donald2
Associate II
Posted on March 12, 2013 at 21:52

Driving a relay is pretty easy.  Use a logic level MOSFET, with a regular GPIO pin.

We run our STM32 at 3.3V, and use a SI9926 or IRL6372.

In some cases you'll need external diode protection on the relay coil.  Some automotive relays have the diode built in, while other relays don't recommend freewheel diode because they slow the drop-out.

You can also use a purpose-built relay driver chip for more robustness, but they are a bit more expensive.

frankmeyer9
Associate II
Posted on March 13, 2013 at 08:44

For a 5V relais, as stated by the OP, a cheap general-purpose BJT like the BC550 is IMHO more than sufficient.