Reputation: 621
I am not sure, if this forum is right place to post such questions, but me as a beginner in STM32 facing the following problem. I have connected LED to PA0 pin in nucleo STM32L073RZ board. This is a main.c code, which I compile and flash board:
#include “stm32l0xx_hal.h”
int main(void){
volatile uint32_t *GPIOA_MODER=0x0, *GPIOA_ODR=0x0;
GPIOA_MODER = (uint32_t*)0x50000000; //GPIOA MODER Address
GPIOA_ODR = (uint32_t*)(0x50000000+0x14); //GPIOA ODR register 0x14 offset
HAL_Init();
__HAL_RCC_GPIOA_CLK_ENABLE();
*GPIOA_MODER = *GPIOA_MODER | 0x1; // Set MODER[1:0] =0x1 Output Mode
*GPIOA_ODR = *GPIOA_ODR | 0x1; // Set ODR[0]=0x1, Pulls PA0 high
while(1);
}
Kindly advice , what I am doing wrong as LED doesn’t go HIGH.
BR
Upvotes: 1
Views: 1212
Reputation: 8069
In the STM32L0 and STM32L4 series, GPIO pins are initialized to analog mode at reset.
Therefore you should clear some bits first:
*GPIOA_MODER = (*GPIOA_MODER & ~0x03) | 0x1; // Set MODER[1:0] =0x1 Output Mode
Upvotes: 1