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

Interaction between pwm library and gpiote(error in gpiote init)

Hi All,

Continuing on with my project: a custom board containing nRF52 + ECG front end.

Successfully integrates SPI functionality; need 2 more interfaces:

  1. 32 KHz clock; using pwm library; codes taken from the pwm_library example

  2. 2x interrupt pins; using gpiote driver; codes taken from the "pin_change_int" example

    I am using SDK 12.2.0

codes:

/* pins used */

#define INTB_PIN     3        //interrupt pin
#define INT2B_PIN   4        //interrupt pin
#define FCLK_PIN    10      //32 KHz output clock pin


/* codes in main */
	
    // Unlock the NFC pins as GPIO   // part of the errata-devzone
	  //  happens to use NFC2 pin P0.10 as MAX30001 FCLK pin
    uint32_t nfcpins = (*(uint32_t *)0x1000120C);
    if (nfcpins & 1) {
        nrf_nvmc_write_word(0x1000120C, 0xFFFFFFFE);
        NVIC_SystemReset();
    }	

/******  CODE BLOCK 1:  codes to init the 2 interrupt pins  *****/ 
    //set interrupt pins, INT2 and INT2B
    err_code = nrf_drv_gpiote_init();
    APP_ERROR_CHECK(err_code);  
	
    nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_HITOLO(true);
    in_config.pull = NRF_GPIO_PIN_PULLUP;

    err_code = nrf_drv_gpiote_in_init(INTB_PIN, &in_config, in_pin_handler);
    APP_ERROR_CHECK(err_code);
    err_code = nrf_drv_gpiote_in_init(INT2B_PIN, &in_config, in_pin_handler);
    APP_ERROR_CHECK(err_code);
	
    // enable this to allow interrupt
    nrf_drv_gpiote_in_event_enable(INTB_PIN, true);
    nrf_drv_gpiote_in_event_enable(INT2B_PIN, true);
/****************************************************************************/
		

/******  CODE BLOCK 2:  codes to init the 2 interrupt pins  *****/ 
    //set 32.768 KHz clock at the required max30001 FCLK pin
    /* 1-channel PWM, 32768 Hz, output on FCLK */
    app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_1CH(31L, FCLK_PIN);

    /* Initialize and enable PWM. */
    err_code = app_pwm_init(&PWM1, &pwm1_cfg, NULL);
    APP_ERROR_CHECK(err_code);
    app_pwm_enable(&PWM1);	
    app_pwm_channel_duty_set(&PWM1, 0, 50);	
/****************************************************************************/	

Issue encountered: If I put codes in "CODE BLOCK 2" on top(ie. earlier in main), the function nrf_drv_gpiote_init() from CODE BLOCK 1 will encounter an error; it seems to work if I put CODE BLOCK 1 first and then CODE BLOCK 2.

    if (m_cb.state != NRF_DRV_STATE_UNINITIALIZED)
    {
        err_code = NRF_ERROR_INVALID_STATE;
        NRF_LOG_WARNING("Function: %s, error code: %s.\r\n",
                        (uint32_t)__func__,
                        (uint32_t)ERR_TO_STR(err_code));
        return err_code;
    }

I am guessing that this has to do with SDK configuration ?; ie. which resources are used etc...

Any comments on which areas to look first ?

Thanks, Lee

Parents Reply Children
No Data
Related