zoukankan      html  css  js  c++  java
  • 2-gpioe event 寄存器配置方式(nrf52832)

    实验目的: 

    (1)按下按键,产生外部中断,由中断服务函数使LED翻转

    实验原理:

    (1)GPIOE 寄存器:

     (2)设置GPIOE的CONFIG寄存器,实现GPIOE与普通GPIO绑定

    实验代码:

    (1)External Interrupt Init function

    //event
    void EXIT_KEY_Init(void)
    {
         nrf_gpio_cfg_input(13,NRF_GPIO_PIN_PULLUP);//key 1
         nrf_gpio_cfg_input(14,NRF_GPIO_PIN_PULLUP);//key 2
        
        NVIC_EnableIRQ(GPIOTE_IRQn);//Enable External Interrupt
        
        //key1
        NRF_GPIOTE->CONFIG[0] = (13 << GPIOTE_CONFIG_PSEL_Pos)  //IO port 
                                  | (GPIOTE_CONFIG_MODE_Event << GPIOTE_CONFIG_MODE_Pos)//Mode -> event or task or disable
                                |(GPIOTE_CONFIG_POLARITY_HiToLo << GPIOTE_CONFIG_POLARITY_Pos);//POLARITY  HiToLo
        NRF_GPIOTE->INTENSET  = GPIOTE_INTENSET_IN0_Set << GPIOTE_INTENSET_IN0_Pos;// enable INT
        
        
        //key2
        NRF_GPIOTE->CONFIG[1] =  (GPIOTE_CONFIG_POLARITY_HiToLo << GPIOTE_CONFIG_POLARITY_Pos)
                               | (14<< GPIOTE_CONFIG_PSEL_Pos)  
                               | (GPIOTE_CONFIG_MODE_Event << GPIOTE_CONFIG_MODE_Pos);
        NRF_GPIOTE->INTENSET  = GPIOTE_INTENSET_IN1_Set << GPIOTE_INTENSET_IN1_Pos;
    }

    (2)

    void GPIOTE_IRQHandler(void)
    {
     if ((NRF_GPIOTE->EVENTS_IN[0] == 1) &&       //judge Interrupt event
            (NRF_GPIOTE->INTENSET & GPIOTE_INTENSET_IN0_Msk))//meanwhile, enable INT0
        {
            NRF_GPIOTE->EVENTS_IN[0] = 0; //clear INT flag 
                  nrf_delay_ms(10);    //key shake off
                 if(nrf_gpio_pin_read(13)== 0)
                 {
                  nrf_gpio_pin_toggle(17);//led   toggle
                 }
         }
     if ((NRF_GPIOTE->EVENTS_IN[1] == 1) && 
            (NRF_GPIOTE->INTENSET & GPIOTE_INTENSET_IN1_Msk))
        {
            NRF_GPIOTE->EVENTS_IN[1] = 0; //clear INT flag 
                nrf_delay_ms(10);    //key shake off
                  nrf_gpio_pin_toggle(18);
        }
    }

    实验视频:

    https://www.bilibili.com/video/BV1Mp4y1k7Hh/

  • 相关阅读:
    文件查找和压缩
    shell脚本编程基础
    [模板]数据生成与对拍
    Codeforces Round #746 (Div. 2)
    Codeforces Round #712 (Div. 2)
    Codeforces Round #715 (Div. 2)
    Codeforces Round #752 (Div. 2)
    提高模拟赛Day8T3树上跑步
    提高模拟赛Day8T2最大匹配
    提高模拟赛Day8T1求中位数
  • 原文地址:https://www.cnblogs.com/darren-pty/p/13902244.html
Copyright © 2011-2022 走看看