2013-03-12 04:39 AM
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?THANKS2013-03-12 05:09 AM
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 !2013-03-12 05:18 AM
Thank you, your response are very satisfactory. So it is the same mode to turn on and off a led, isn't it?
2013-03-12 06:57 AM
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.
2013-03-12 01:52 PM
2013-03-13 12:44 AM
For a 5V relais, as stated by the OP, a cheap general-purpose BJT like the BC550 is IMHO more than sufficient.