This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Writing 32 bit values to 16 bit register

I have to write 16 bit value in a 16 bit register, & variable which holds that value is 32 bit.
I have STM32, BSRRL register which is 16 bit, so if I write

Like
uint32_t x = 255;
BSRRL = x;

What will happen will compiler only take lower 16 bits of variable or will take entire 32 bitys & write upper 16 bits to BSRRH.
If yes then what is correct way to do that, manually typecast it:

BSRRL = (uint16_t)x;

STM32
typedef struct
{ __IO uint32_t MODER; /*!< GPIO port mode register, Address offset: 0x00 */ __IO uint32_t OTYPER; /*!< GPIO port output type register, Address offset: 0x04 */ __IO uint32_t OSPEEDR; /*!< GPIO port output speed register, Address offset: 0x08 */ __IO uint32_t PUPDR; /*!< GPIO port pull-up/pull-down register, Address offset: 0x0C */ __IO uint32_t IDR; /*!< GPIO port input data register, Address offset: 0x10 */ __IO uint32_t ODR; /*!< GPIO port output data register, Address offset: 0x14 */ __IO uint16_t BSRRL; /*!< GPIO port bit set/reset low register, Address offset: 0x18 */ __IO uint16_t BSRRH; /*!< GPIO port bit set/reset high register, Address offset: 0x1A */ __IO uint32_t LCKR; /*!< GPIO port configuration lock register, Address offset: 0x1C */ __IO uint32_t AFR[2]; /*!< GPIO alternate function registers, Address offset: 0x24-0x28 */
} GPIO_TypeDef;

0