This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Detect External Pin Interrupts with nRF51

Hello, I am using external interrupt from an ADXL345 . Can you tell me how to detect that external interrupt with the nRF51 ?

Parents
  • The following code will detect a Low-to-High transition on a given Interrupt Pin( needs to be defined by you).

    GPIOTE Event Handler:

    void gpiote_evt_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
    {
        switch(action)
        {
            case NRF_GPIOTE_POLARITY_LOTOHI:
                //do something
                break;
            default:
                //do nothing
                break;
        }
    }
    

    Main Function:

    int main(void)
    {
        ret_code_t ret_code;
        
        ret_code = nrf_drv_gpiote_init();
        APP_ERROR_CHECK(ret_code);
        
        nrf_drv_gpiote_in_config_t config =
        {
            .sense = NRF_GPIOTE_POLARITY_LOTOHI,
            .pull = NRF_GPIO_PIN_NOPULL ,
            .is_watcher = false,
            .hi_accuracy = false
        };
            
        
        ret_code = nrf_drv_gpiote_in_init(INTERRUPT_PIN, &config, gpiote_evt_handler);
        APP_ERROR_CHECK(ret_code);
        
        nrf_drv_gpiote_in_event_enable(INTERRUPT_PIN,true);
    }
    

    Update:

    Project files for an example that toogles a led when a button is pressed

    toggle_led_fixed.zip

  • *** Using Compiler 'V5.06 update 1 (build 61)', folder: 'C:\Keil_v5\ARM\ARMCC\Bin' Rebuild target 'nrf51422_xxac' compiling main.c... ....\main.c(22): error: #5: cannot open source input file "app_util_platform.h": No such file or directory #include "app_util_platform.h" ....\main.c: 0 warnings, 1 error compiling app_util_platform.c... compiling nrf_drv_gpiote.c... ............\components\drivers_nrf\gpiote\nrf_drv_gpiote.h(26): error: #5: cannot open source input file "nrf_gpiote.h": No such file or directory #include "nrf_gpiote.h" ............\components\drivers_nrf\gpiote\nrf_drv_gpiote.c: 0 warnings, 1 error compiling app_error.c... ............\components\libraries\util\app_error.h(27): error: #5: cannot open source input file "nrf_error.h": No such file or directory #include "nrf_error.h" ............\components\libraries\util\app_error.c: 0 warnings, 1 error compiling nrf_assert.c... assembling arm_startup_nrf51.s... compiling nrf_drv_common.c... compiling system_nrf51.c... "._build\nrf51422_xxac.axf" - 3 Error(s), 0 Warning(s). Target not created. Build Time Elapsed: 00:00:03

Reply
  • *** Using Compiler 'V5.06 update 1 (build 61)', folder: 'C:\Keil_v5\ARM\ARMCC\Bin' Rebuild target 'nrf51422_xxac' compiling main.c... ....\main.c(22): error: #5: cannot open source input file "app_util_platform.h": No such file or directory #include "app_util_platform.h" ....\main.c: 0 warnings, 1 error compiling app_util_platform.c... compiling nrf_drv_gpiote.c... ............\components\drivers_nrf\gpiote\nrf_drv_gpiote.h(26): error: #5: cannot open source input file "nrf_gpiote.h": No such file or directory #include "nrf_gpiote.h" ............\components\drivers_nrf\gpiote\nrf_drv_gpiote.c: 0 warnings, 1 error compiling app_error.c... ............\components\libraries\util\app_error.h(27): error: #5: cannot open source input file "nrf_error.h": No such file or directory #include "nrf_error.h" ............\components\libraries\util\app_error.c: 0 warnings, 1 error compiling nrf_assert.c... assembling arm_startup_nrf51.s... compiling nrf_drv_common.c... compiling system_nrf51.c... "._build\nrf51422_xxac.axf" - 3 Error(s), 0 Warning(s). Target not created. Build Time Elapsed: 00:00:03

Children
No Data
Related