本文介绍了如何打开 STM32F1 GPIO 引脚 PA2 上的 LED?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用标准注册表配置打开 PA2 GPIO (STM32F103C8T6) 上的 LED.

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?

推荐答案

根据参考手册,GPIOA CRL 寄存器重置为 0x4444 4444(请参阅参考手册的第 9.2.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);

您将 PA2 的 MODE 位设置为 10(输出模式,最大速度 2 MHz).但由于初始寄存器初始化,CNF2位为01,为开漏配置.您应该使用以下内容初始化 PA2

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);

这可确保 MODE2 和 CNF2 均已设置,因此该引脚充当具有推挽配置的输出

This ensures that both MODE2 and CNF2 are both set so the pin acts as an output with a push-pull configuration

这篇关于如何打开 STM32F1 GPIO 引脚 PA2 上的 LED?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 14:12