Reputation: 621
How can i switch on the LED on PA2 GPIO (STM32F103C8T6), using standard registry configuration.
RCC-> APB2ENR |= (1<<2);
GPIOA->CRL |= (1<<9);
GPIOA->ODR |= (1<<3);
Does not work for me. Could you please advice where i make mistake?
Upvotes: 0
Views: 643
Reputation: 36
As per the reference manual, the GPIOA CRL registers resets as 0x4444 4444 (See section 9.2.1 of the reference manual). When you execute the following command:
GPIOA->CRL |= (1<<9);
you are setting the MODE bits of PA2 to 10 (Output mode, max speed 2 MHz). But due to the inital register initialization, the CNF2 bits are 01, which is open-drain configuration. You should initialize PA2 with the following instead
GPIOA->CRL &= ~(0b0000<<8);
GPIOA->CRL |= (0b0010<<8);
This ensures that both MODE2 and CNF2 are both set so the pin acts as an output with a push-pull configuration
Upvotes: 2