NORDIC nRF52840 输入引脚初始化及中断操作

硬件: NORDIC nRF 52840 SoC

软件: NORDIC nRF SDK Ver 15.2

硬件中断触发: 低电平触发


Step 1: 正确配置 GPIOTE Driver 通道数

NORDIC nRF52840 输入引脚初始化及中断操作_第1张图片


Step 2: GPIO 引脚初始化

#define	RX8010_IRQ1			16
#define	RX8010_IRQ2			17
#define BUTTON_DETECTION_DELAY          APP_TIMER_TICKS(50)                     /**< Delay from a GPIOTE event until a button is reported as pushed (in number of timer ticks). */

static void GPIO_IRQ_init(void)
{
    ret_code_t err_code;

    //The array must be static because a pointer to it will be saved in the button handler module.
    static app_button_cfg_t RX8010SJ_IRQs[] =
    {
        {RX8010_IRQ1, false, BUTTON_PULL, GPIO_IRQs_event_handler},
        {RX8010_IRQ2, false, BUTTON_PULL, GPIO_IRQs_event_handler}				
    };

    err_code = app_button_init(RX8010SJ_IRQs, ARRAY_SIZE(RX8010SJ_IRQs),BUTTON_DETECTION_DELAY);
    APP_ERROR_CHECK(err_code);
		
    app_button_enable();
}

Step 3: 中断操作函数


/**@brief Function for handling events from the button handler module.
 * @param[in] pin_no        The pin that the event applies to.
 * @param[in] button_action The button action (press/release).
 */

static void GPIO_IRQs_event_handler(uint8_t pin_no, uint8_t button_action)
{
    ret_code_t err_code;
	
    switch (pin_no)
    {
        case RX8010_IRQ1:
            NRF_LOG_INFO("--- RX8010_IRQ1 ---");
            break;
        case RX8010_IRQ2:
            NRF_LOG_INFO("--- RX8010_IRQ2 ---");	
            break;
        default:
            APP_ERROR_HANDLER(pin_no);
            break;
    }
}

 

你可能感兴趣的:(NORDIC,BLUETOOTH,输入中断,app_button_init,NORDIC,nRF52840)