cancel
Showing results for 
Search instead for 
Did you mean: 

How to write set of bits in ODR?

sreejithu4u
Associate II
Posted on November 08, 2012 at 16:15

hello , im a newbie to stm32 and im just starting with stm32f4 discovery,

i have to write an 8 bit value to GPIOA ODR from bit2 to bit9 while not altering bit0 and bit1

how can i do that?

it`s a noob question but i want learn

kindly help

regards

#set-bits-in-odr
1 REPLY 1
Posted on November 08, 2012 at 17:24

hello , im a newbie to stm32 and im just starting with stm32f4 discovery, i have to write an 8 bit value to GPIOA ODR from bit2 to bit9 while not altering bit0 and bit1 how can i do that?

 

*((__IO uint32_t *)&GPIOA->BSRRL) = ((x & 0xFF) << 2) | ((~x & 0xFF) << (2 + 16)); // Set the 1 bits, Clear the 0 bits, QED

or

GPIOA->ODR = (GPIOA->ODR & ~(0xFF << 2)) | ((x & 0xFF) << 2);
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..