简体   繁体   中英

STM32 Blinking an LED using CMSIS

//setup
    RCC->AHBENR |= 0x20000; //bit 17
    GPIOA->MODER |= 0x100000; // MODER10 (PA10)
    GPIOA->OTYPER |= (1<<10); // bit 10
// main
      GPIOA->BSRR = 0x400; LED HIGH
      HAL_Delay(1000);
      GPIOA->BRR = 0x400; LED LOW
      HAL_Delay(1000);

I am having trouble blinking an external led using PA10. I read the datasheet and used the corresponding registers.

The code is supposed to make an external LED blink using registers only (CMSIS) and this LED is connected on PA10. I am using Nucleo-F303RE board.

I think you are configuring PA10 to be an open drain (OD) output by setting its OTYPER bit to 1. You forgot to say how your LED is connected, but if you have to drive the I/O pin high to turn on the LED, then you don't want it to be an open drain output. Try removing the line that sets the OTYPER bit.

OTYPER registers selects output type, where 0 in a bit means push-pull mode on the corresponding pin, and 1 - open-drain .

Open-drain means that port is connected to the GND when output value is 0, and left floating when output value is 1. This mode is intended to use with a pull-up resistor (internal or external).

If your LED is connected between the output and GND, you should use push-pull mode. Ie you need to keep zero value in the bit in MODER register.

And also my advice: try to avoid "magic numbers" use bit names from CMSIS. Eg: instead of

RCC->AHBENR |= 0x20000;

write

RCC->AHBENR |= RCC_AHBENR_IOPAEN;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM