vbgrigorev
vbgrigorev

Reputation: 11

stm32 board strange behaviour

could you help me?

This utility function I use to set kth bit of x zero or one.

#define zer(x, k) ((x) &= (~(1u << k)))
#define one(x, k) ((x) |= (1u << k))

I have stm32f407vet6 board. Something strange happens when I do

one(GPIOA->MODER, 12u);

led on pin PA6 turns on, like I use ODR register.

Furthemore, in my code

one(GPIOA->ODR, 6u);

turn off LED, but

zer(GPIOA->ODR, 6u);

turn it on.

Why is that so?

Why MODER register behave like ODR, and why I have ODR turn on and off inversed?

Thanks in advance.

I guess, if I out zero in port ODR, led tuns off. If I put one in port ODR, led turns on. But it behaves inversed. And setting one to moder turns on led. Why is that so?

Upvotes: 0

Views: 123

Answers (1)

0___________
0___________

Reputation: 67835

The explanation is very simple.

It is better to sink than source the current through GPIO pin. So board developers connect LEDs the way they will be light when pin becomes a logical zero. Like in below schematics:

enter image description here

one(GPIOA->MODER, 12u);

Sets pin 6 as output. As ODR by default is zero, pin is OV - the LED is ON.

Same explanation for the ODR behaviour.

Upvotes: 2

Related Questions