c - 读取 GPIOB_IDR 寄存器时的值不正确

标签 c arm nucleo stm32f0

我在 atollic true studio ide 上对 stm32f030r8 arm 编程感到困惑。

我在从 idr 寄存器读取正确数据时遇到了一些问题。

我下拉了 GPIOB(0,1,2,3) 的 PUPR 寄存器。

GPIOB的其他引脚是我用MODER寄存器做的输出。

当我每次读取F值都在循环读取idr数据时,但没有任何输入。

请帮我解决这个问题[ You can see value that i read when debugging[1]

There is no any input It has to read 0x00

#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/

相关文章:

python - python 编译C函数的问题

c - UNS_32 在哪里定义的?

c++ - 使用缓冲区和溢出缓冲区将 IMU 数据写入 csv 文件?

c - 嵌入式C数据存储模块设计

c - 尝试使用 C 使 LED 闪烁

c - C 中的隐式函数声明

c++ - 为 Windows CE 编译的 FreeImage.dll?

exception - ARM9 Prefetch Abort Exception 可能是软件问题吗?

microcontroller - STMicro 是否错误地解释了术语 "shadow register"?

http - mbed:建立网络连接后访问 SD 卡时出现 HardFault 错误