zoukankan      html  css  js  c++  java
  • GD32 ------ 使用外部中断,中断函数需要延时才能读到真正电平

    MCU:GD32F103RCT6

    中断引脚没有外界上拉电阻

     

    中断配置如下:

        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC|RCC_APB2Periph_AFIO, ENABLE);
        GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU;
        GPIO_InitStructure.GPIO_Pin=GPIO_Pin_9;
        GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
        GPIO_Init(GPIOC, &GPIO_InitStructure);
        GPIO_EXTILineConfig(GPIO_PortSourceGPIOC,GPIO_PinSource9);
        
        EXTI_InitStructure.EXTI_Line=EXTI_Line9;
        EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;    
        EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
        EXTI_InitStructure.EXTI_LineCmd = ENABLE;
        EXTI_Init(&EXTI_InitStructure);

    中断函数如下:

    void EXTI9_5_IRQHandler(void)
    {
        BaseType_t xHigherPriorityTaskWoken = pdFALSE;
        
        
        if(EXTI_GetITStatus(EXTI_Line9) != RESET)
        {
            debug("%d",GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_9));
            debug("%d",GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_9));
            debug("%d",GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_9));
            if(GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_9) != 0)
            {
                debug("relay power on, device_power_on is 1");
                xTaskNotifyFromISR( xTaskHandleLoadDatatoServerBuf, g_flag_event[RELAY_POWER_ON], eSetBits, &xHigherPriorityTaskWoken );
                g_data_info.power_on = 1;
            }else
            {
                debug("relay power off, device_power_on is 0");
                xTaskNotifyFromISR( xTaskHandleLoadDatatoServerBuf, g_flag_event[RELAY_POWER_OFF], eSetBits, &xHigherPriorityTaskWoken );
                g_data_info.power_on = 0;
            }
            EXTI_ClearITPendingBit(EXTI_Line9);
        }
        portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
    }

    当检测到上升沿,在中断函数中,第一次读电平是0,之后读的几次都是1

  • 相关阅读:
    MyEclipse Servers视窗出现“Could not create the view: An unexpected exception was thrown”错误解决办法
    eclipse 安装git
    使用Maven构建Web项目
    Maven仓库构建
    JAX-WS:背后的技术JAXB及传递Map
    CXF WebService 开发文档
    eclispse 中集成多个tomcat
    Myeclipse 主题下载
    html textarea 获取换行
    jqurey click和blur执行时间冲突
  • 原文地址:https://www.cnblogs.com/god-of-death/p/9272691.html
Copyright © 2011-2022 走看看