GPIO Read/Write Multiple Bits at once

I was trying to read/write a 8 byte value directly to the GPIO port.
Is it possible to do that with one call rather than have to do it bit-by-bit.
Something like PORTA = PORTB | MASK?
AVR Based arduinos would probably do that.

Here you can see how to read the entire port that the pin you want is on:

And here is how to write individual bits:

To write the whole port you need to write to the ODR (Output Data Register), so it should be something like this:
PIN_MAP[pin].gpio_peripheral->ODR = 0xFFFF;

Except this still seems like it might be missing something… so keep us updated on what you dig up.

You might want to take a look at :spark: STM32F Reference Manual (RM0008) (9.2MB)


This is absolutely possible @lbarrosoneto. You will find though that the ARM processor is both more powerful than the AVR chips you’re used to, and a little more complicated to deal with.

Get the reference manual for the STM32F103CBT6. You can just read chapter 9 on GPIO to see exactly how it’s done.

Some educational snippets from :spark: firmware:

In particular you’ll want to read from the IDR (input data register) and write to the ODR (output data register) for a particular port after the port is configured…

Aaaaaand I see @BDub just beat me to the punch, with an even better answer. :thumbsup:

Happy hacking!


Damnit, I had a long ass reply typed up, got sidetracked, come back annnd I’m beaten like Rihanna
at the Grammies.

@BDub even included pretty pictures!


I have an idea… next time we are thinking of making a long-winded detailed reply, we should post a temporary reply stating we are working on a reply!

That way we can spread out the awexomeness to other topics :smile:


Good call. I’ve had the same issue a few times before as well. I just need to figure out how to make that work with e-mail as well. :wink:

Thank you very much, Guys!

1 Like

Looks like a great answer. It could be improved by updating the broken links! :slight_smile: