cancel
Showing results for 
Search instead for 
Did you mean: 

What is wrong with my registers` definition in this code?

Malaa.1
Associate II

Hello , I`m newbie to STM32 processors , i was working on AVR .....

It has been 3 days since i was trying to find out what is wrong with my registers` definition .. in this photo i defined RCC_APB2ENR and i did try to set a specific bit , but the result is that the bit is not set .. can anyone help me with that?

0690X00000Buco5QAB.png

4 REPLIES 4
Piranha
Chief II

It should work. Debugger problems?

Another question. Register definitions are probably the only useful "code" from ST. Why you are redefining those?

Malaa.1
Associate II

Well it is not working and i flashed the code onto the controller and the led connected to a specific GPIOD Pin didn`t turn on ...

and i am redefining these again to get my hand used to it

berendi
Principal

Welcome to pointer arithmetic in C. And operators precedence.

Casting a value to another type is an unary operator, it has higher precedence as binary operators like addition. So 0x40023800 is converted to a pointer to uint32_t first, and 0x44 gets added to this pointer. By the rules of C pointer arithmetic, you'll get 0x40023800 + 0x44*sizeof(uint32_t).

To fix it, just ensure that the offset gets added to the base first by the rules of integer arithmetic, and cast to pointer afterwards.

((volatile uint32_t *)(0x40023800 + 0x44))

Thank youuuuuu <3 , I had a doubt about that .... thank youuu again <3