cancel
Showing results for 
Search instead for 
Did you mean: 

open drain GPIO output

evert2
Associate II
Posted on April 29, 2013 at 16:36

Dear all,

A question about configuring GPIO outputs,

I've connected a Led to 3v3 and the other side via a resistor to the STM32F051.

I want to switch on the led with the GPIO_SetBits() function

However my led is by default 'on' and goes 'off' when I enter GPIO_SetBits() function.

This is my configuration setting:

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;

GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;

GPIO_Init(GPIOC, &GPIO_InitStructure);

I was expecting that in an open drain configuration, the output should be enabled when the set function is entered. What is wrong with my configuration and is it possible to resolve this? Or do I have to use the GPIO_SetBits() function to disable to led after configuration and use the GPIO_ResetBits() to enable the led?

#gpio-open-drain #active-low'
6 REPLIES 6
Posted on April 29, 2013 at 17:51

Well if one end of the LED is connected to 3V3, then the other end needs to be closer to ground potential for it to illuminate. ie Zero, or via ClearBits(). Imagine how the current flows.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
evert2
Associate II
Posted on May 01, 2013 at 08:33

Hi,

I see in the datasheet the internal N-MOS is zero activated, so that makes sense.

However it is not logical that a LED is switched on by writing a zero.

Is there another GPIO setting possible to resolve this? or does the ST library provide a solution for this?

Otherwise I have to write my own interface,

Regards,

Evert Huijben

John F.
Senior
Posted on May 01, 2013 at 12:19

What's to stop you connecting the LED Cathode to 0V and the LED Anode via a current limiting resistor to the GPIO port pin configured as push-pull? Then writing '1' to the pin will cause the LED to illuminate which seems to be what you want.

Posted on May 01, 2013 at 15:03

''it is not logical that a LED is switched on by writing a zero''

 

Says who??!!

So-called ''Active-Low'' logic is very common and very widely used indeed!

''Is there another GPIO setting possible to resolve this?''

 

A so-called ''push-pull'' output can both source & sink current.

However, the sink capability is often greater than the source capability - which is (one reason) why it

is

  so common to see LEDs (among other things) with Active-

Low

  drivers...

emalund
Associate III
Posted on May 01, 2013 at 16:56

''it is not logical that a LED is switched on by writing a zero''

 

Says who??!!

So-called ''Active-Low'' logic is very common and very widely used indeed!

However, the sink capability is often greater than the source capability - which is (one reason) why it

is

  so common to see LEDs (among other things) with Active-

Low

  drivers..

please give me a 'logical' level for ''the cup is empty''

anyhow it is standard practice to connect LEDs from Vdd to the pin.

the 'logical' solution is quite simple

#define LED_OFF (whatever your particular compiler wants for bit I/O)

Erik

Posted on May 01, 2013 at 17:22

''So-called 'Active-Low' logic is very common and very widely used indeed!''

A significant number of the switches & sensors in a car are ''Active-Low''; ie, they switch to the chassis...