//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.
CodePudding user response:
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.
CodePudding user response:
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. I.e. 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. E.g: instead of
RCC->AHBENR |= 0x20000;
write
RCC->AHBENR |= RCC_AHBENR_IOPAEN;