2023-07-12 06:13 PM
Hi all, I want to modify the MODER register of GPIOA using memory addresses.
I have the following code but it doesnt work. I think its the derefence of the variables where my problem is.
I'm using the STM32L053R8 with the nucleo-l053 board
#include <stdint.h>
#define PERIPHERAL_BASE_ADDRESS 0x40000000
#define IOPORT_ADDRESS (PERIPHERAL_BASE_ADDRESS + 0x10000000)
#define GPIOA_BASE_ADDRESS (IOPORT_ADDRESS + 0x00000000)
//GPIOA REGISTERS
#define GPIOA_MODER (GPIOA_BASE_ADDRESS + 0x00000000)
#define GPIOA_OTYPER (GPIOA_BASE_ADDRESS + 0x00000004)
#define GPIOA_OSPEEDR (GPIOA_BASE_ADDRESS + 0x00000008)
int main(void)
{
uint32_t *gpioa_moder = GPIOA_MODER;
*gpioa_moder |= 1<<1;
/* Loop forever */
for(;;);
}
Thanks for providing solutions
2023-07-12 06:33 PM
The peripheral registers aren't going to work unless you enable the clock, here for GPIOA