cancel
Showing results for 
Search instead for 
Did you mean: 

Writing to a memory location

vicvicvar
Associate II

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

1 REPLY 1

The peripheral registers aren't going to work unless you enable the clock, here for GPIOA

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..