我在 atollic true studio ide 上对 stm32f030r8 arm 编程感到困惑。
我在从 idr 寄存器读取正确数据时遇到了一些问题。
我下拉了 GPIOB(0,1,2,3) 的 PUPR 寄存器。
GPIOB的其他引脚是我用MODER寄存器做的输出。
当我每次读取F值都在循环读取idr数据时,但没有任何输入。
请帮我解决这个问题[
#include "main.h"
int main(void)
{
volatile static uint16_t PortDataInput=0x00;
RCC->CR|=(uint32_t)0xF1; //set hsi clock source and with max speed
GPIOB->PUPDR|=0xAA; //set firt 4 bit of gpiob as pull down
GPIOB_RCC->AHBENR|=(1<<18); //enable gpiob clock source
GPIOB->MODER|=0x55555500; //set firt 4 bit of gpiob as input
GPIOB->OTYPER|=0x00000000; //set output pins of gpiob as push pull
while (1)
{
PortDataInput=GPIOB->IDR;
PortDataInput&=0xF;
}
最佳答案
您尝试在启用外设时钟之前设置 gpio 寄存器。所以你不能写入它的任何寄存器。
关于c - 读取 GPIOB_IDR 寄存器时的值不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56828145/