Skip to main content
thannara123
Associate III
October 4, 2023
Question

Can i write to the entire port to data

  • October 4, 2023
  • 7 replies
  • 4050 views

Hai experts .

Can i wrte data to the  entire Port as follows

GPIOB->ODR |= 0x0000;
HAL_Delay(1000);
GPIOB->ODR |=0xffff;

Whenever i write like wise the SFR register shows correct value in Debug mode 

But in Hardware its not working .whats the wrong with me ?

This topic has been closed for replies.

7 replies

AScha.3
Super User
October 4, 2023

or 0x0 -> GPIOB->ODR |= 0x0000; = nonsense.

need: GPIOB->ODR &= 0x0000;

"If you feel a post has answered your question, please click ""Accept as Solution""."
thannara123
Associate III
October 4, 2023

which also not working bro

TDK
October 4, 2023

> But in Hardware its not working .whats the wrong with me ?

Why don't you think it's working? You are probably misinterpreting something, or there is another issue.

 

"If you feel a post has answered your question, please click ""Accept as Solution""."
thannara123
Associate III
October 4, 2023

Just gives led to the port .not blingking

TDK
October 4, 2023

This code doesn't blink an LED. It does nothing (first line), waits a second then sets all outputs to high.

GPIOB->ODR |= 0x0000;
HAL_Delay(1000);
GPIOB->ODR |=0xffff;

There is no loop which would be needed to blink. It doesn't configure any pins as output which would also be needed to blink an LED. It doesn't configure any ports. It is also missing a second delay, which, if in a loop, would be needed to blink an LED.

Maybe you do these somewhere else in the program, maybe not.

"If you feel a post has answered your question, please click ""Accept as Solution""."
Tesla DeLorean
Guru
October 4, 2023

The clocks for GPIOB need to be enabled, and the pin suitably configured.

You don't show any of that code. Suggest you use libraries until you've got a better mastery of this.

ORing ZERO is not how you clear bits.

You could use ODR or BSRR.  GPIOB->ODR &= ~GPIO_PIN_12; or GPIOB->BSRR = GPIO_PIN_12 << 16; // Clear

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
Tesla DeLorean
Guru
October 4, 2023

Which STM32 are you actually using? How is the LED wired up? Show a schematic. Show code.

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
thannara123
Associate III
October 5, 2023

GPIOB->ODR = 0x0000;
HAL_Delay(1000);
GPIOB->ODR = 0xffff;
HAL_Delay(1000);

 

Changed as per above . 

GPIOB perpheral clock enabled ,GPIOB enabled as output .

external 8mhz clock is used . 

In debug mode the ODR 1,2,3 bit of PORT B changing as per programm 

But not refflect in hardware .

I think GPIOB->ODR canot write entire data 

thannara123
Associate III
October 5, 2023
Danish1
Lead III
October 5, 2023

Which bit or pin in the port is your LED connected to?

Looking at the video I suspect the processor is stm32f103. But it would be useful if you could confirm that.

Is this a board that you designed and built? Or a commercial one (if so, please tell us which one)?

Do you have access to a voltmeter, so you can look at the voltage on the pins? That would help you to know if the problem is the software or the hardware (e.g. pin not soldered, LED the wrong way round).

TDK
October 5, 2023

> I think GPIOB->ODR canot write entire data 

> Here can see the data change in ODR regiter 

Aren't these statements at odds with each other? You can keep thinking that, but the issue is elsewhere. Still not seeing your full code.

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