How can i switch on LED on STM32F1 GPIO pin PA2?

烂漫一生 提交于 2020-02-06 07:55:30

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/59920888/how-can-i-switch-on-led-on-stm32f1-gpio-pin-pa2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!