GPIO

输出测试

进行GPIO输出测试,请按照以下步骤操作:

  1. 选择GPIO引脚,并设置为输出模式

    GPIO_InitStruct.GPIO_Pin = GPIO_Pin;
    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
    
  2. 使用上述参数初始化硬件

    GPIO_Init(GPIO_InitTypeDef *GPIO_InitStruct);
    
  3. 向指定的输出端口引脚写入逻辑值

    GPIO_WriteBit(u32 GPIO_Pin, u32 Pin_State);
    

输入测试

进行GPIO输入测试,请按照以下步骤操作:

  1. 选择GPIO引脚,并设置为输入模式

    GPIO_InitStruct.GPIO_Pin = GPIO_Pin;
    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN;
    
  2. 使用上述参数初始化硬件

    GPIO_Init(GPIO_InitTypeDef *GPIO_InitStruct);
    
  3. 读取指定的输入端口引脚

    GPIO_ReadDataBit(u32 GPIO_Pin);
    

中断测试

进行GPIO中断测试,请按照以下步骤操作:

  1. 选择GPIO引脚,设置为中断模式,无上拉/下拉,并配置中断触发类型、极性、消抖

    GPIO_InitStruct.GPIO_Pin = GPIO_Pin;
    GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_INT;
    GPIO_InitStruct.GPIO_ITTrigger = trigger_type;
    GPIO_InitStruct.GPIO_ITPolarity = polarity;
    GPIO_InitStruct.GPIO_ITDebounce=GPIO_INT_DEBOUNCE_ENABLE(or GPIO_INT_DEBOUNCE_DISABLE);
    
  2. 使用上述参数初始化硬件

    GPIO_Init(GPIO_InitTypeDef *GPIO_InitStruct);
    
  3. 注册并启用GPIO中断

    InterruptRegister(GPIO_INTHandler,GPIO_DEV_TABLE[port].IrqNum, (u32)GPIO_DEV_TABLE[por t].GPIOx, 10);
    InterruptEn(GPIO_DEV_TABLE[port].IrqNum, 10);
    
  4. (可选)配置GPIO中断模式

    GPIO_INTMode(u32 GPIO_Pin, u32 NewState, u32 GPIO_ITTrigger, u32 GPIO_ITPolarity, u32 GPIO_ITDebounce);
    
  5. 注册用户处理函数

    GPIO_UserRegIrq(GPIO_Pin, gpio_test_irq_handler, (&GPIO_InitStruct_Temp));
    
  6. 启用指定的GPIO引脚中断

    GPIO_INTConfig(GPIO_Pin, ENABLE);