求教STM32F103 RCC和GPIO遇到的一点问题
依然冷暖 2017-01-11 04:10:49 描述:目的是GPIOE2 GPIO3 两个按键控制GPIOC口的LED,
使用寄存器直接控制代码:
RCC->APB2ENR = 0x00000050;
GPIOE->CRL = 0x00088800;
GPIOE->ODR |= (0x07 << 2);
GPIOC->CRL |= 0x33333333;
打开E C 口的时钟 设置E 2 3 口为输入上拉 C口为推挽输出
使用库函数直接控制代码:
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOE, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOE, &GPIO_InitStructure);
我遇到的问题是 当寄存器和库函数混合使用时候出现的问题代码如下:
RCC->APB2ENR = 0x00000050;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOE, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOE, &GPIO_InitStructure);
也就是使用库函数设置IO口状态 使用寄存器打开对应时钟 通过调试模式观察没发现不同 但是 实际出现的问题是 混合使用的时候LED会出现拖尾灯效果 也就是分别单独使用时候都没问题 但是在一起就出现LED灯出现拖尾效果
我要问的就是难道RCC->APB2ENR = 0x00000050;和
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE);
有区别么 为什么会不一样呢!