本帖最后由 STM32F89C51 于 2024-3-31 15:14 编辑
芯片是GD32F103C8T6, 用的STM32的标准固件库函数, 遇到一个奇怪的问题: 先贴出代码
- #include "stm32f10x.h" //STM32头文件
- #include "sys.h"
- #include "delay.h"
- #include "NVIC.h"
- void GPIOB_init(){
- // 初始化GPIO端口和引脚
- GPIO_InitTypeDef GPIO_InitStructure;
- // 开启GPIOB时钟
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
- // 配置GPIOB的PB2引脚为推挽输出,输出速率为50MHz
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
-
- /// 配置PB1为输入后就无法控制PB2写1或写0,
- // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; // 选择端口号PB1
- // GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; // 上拉输入
- // GPIO_Init(GPIOB,&GPIO_InitStructure);
- }
- int main (void){//主程序
- RCC_Configuration(); //时钟设置
- GPIOB_init();
- while(1){
- // 切换PB2引脚的状态
- GPIO_SetBits(GPIOB, GPIO_Pin_2); // PB2输出高电平
- delay_ms(1000);
- GPIO_ResetBits(GPIOB, GPIO_Pin_2); // PB2输出低电平
- delay_ms(1000);
- }
- }
如注释所说,为什么配置PB1为输入后就不能控制PB2的高低,万用表测PB2的电平一直为0;注释掉PB1的配置函数,程序正常。。。。。换新的芯片一样的问题,手头上没有ST的芯片。不然可以试试ST的。
-----------------------------我是分割线------------------------------
后面买了一片STM32的,换上去后问题消失
|