cancel
Showing results for 
Search instead for 
Did you mean: 

diode

Sax
Associate III

HelIo,

I connected the anode from a diode to the operating voltage and the cathode to a pinx. I need ground to make the diode glow.  How can this be implemented?

13 REPLIES 13

Well you'd need a resistor to limit current through the LED, as if you simply gate it to ground you'll get whatever the transistor will permit.

 

PINX ----[ R ]----|/|-- VCC
               LED|\|

 

Configure GPIO as PP or OD OUTPUT, LOW to illuminate

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

I already have a resistor in the hardware. Unfortunately, these settings don't work.

Perhaps draw what you've built

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

I've also tried this CLEAR_BIT(GPIOF->ODR, GPIO_ODR_OD3);
CLEAR_BIT(GPIOF->ODR, GPIO_ODR_OD5); NMOS transistor to force the I/O pin to ground.

HAL_GPIO_WritePin(GPIOF, GPIO_PIN_3,GPIO_PIN_SET);

HAL_GPIO_WritePin(GPIOF, GPIO_PIN_5,GPIO_PIN_SET);

 

Unfortunately, to no avail. Something is still missing in the setting.

Below is the circuit:

Sax_0-1704545091289.png

 

To drive the pin low, just define it as a output , then set this low.

AScha3_0-1704550762821.png

( here pb12 , just to show )

 

 

HAL_GPIO_WritePin(GPIOF, GPIO_PIN_3, GPIO_PIN_RESET);	// LED ON

 

 

If you feel a post has answered your question, please click "Accept as Solution".
Sax
Associate III

Thank you very much for your reply.

I've tried everything, unfortunately doesn't work. I always measure a voltage at the cathode. I usually need ground on the pin.

So try : set in cubeMX  (-> xx.ioc) GPIO pin as output and at low level.

-> generate code , -> compile , -> debug --- and led is on.  If not : your on the wrong pin (number or name).

AScha3_0-1704553016868.png

( here pb12 , just to show )

If you feel a post has answered your question, please click "Accept as Solution".
Sax
Associate III

I did exactly the same. I'm using pin 14 and pin 16. On stm32 are the PF3 and PF5. I'm still measuring 1.9V voltage at the cathode.

Sax_0-1704557386123.pngSax_1-1704557414990.png

Sax_2-1704557603908.png

 

 

But you wrote: HAL_GPIO_WritePin(GPIOF, GPIO_PIN_5,GPIO_PIN_SET);

this sets pin high.

Test:  write NO progam, nothing, let only Cube make the init.

Just generate code, compile, debug -> pins are low.

Can you debug ? Then check gpio setting in SFRs view.

If you feel a post has answered your question, please click "Accept as Solution".