Skip to main content
sreejithu4u
Associate II
November 8, 2012
Question

How to write set of bits in ODR?

  • November 8, 2012
  • 1 reply
  • 781 views
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
    This topic has been closed for replies.

    1 reply

    Tesla DeLorean
    Guru
    November 8, 2012
    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 VenmoUp vote any posts that you find helpful, it shows what's working..