2013-04-29 07:36 AM
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'2013-04-29 08:51 AM
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.
2013-04-30 11:33 PM
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 Huijben2013-05-01 03:19 AM
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.
2013-05-01 06:03 AM
''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...2013-05-01 07:56 AM
''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
2013-05-01 08:22 AM
''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...