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

Combination of SPI and GPIOTE interrupt does not work

Hello,

I've checked a few related threads, but without any success.

I need to react on "Data Ready Interrupt" and read data from SPI.
SPI and Device is initialized before application_timers_start();
The device is initalized via a few SPI commands. Device init includes enabling of GPIOTE interrupt.

If a phone connects to my device, two SPI commands are sent to enable device and start measurement. Afterwards, the DRDY pin is tied LOW if data is ready. Inside drdy interrupt, data is read from the device using SPI. The SPI is based on the SPI master example.

But drdy interrupt is just called 1 to 5 times and then no further log output is shown. It seems, that interrupt is not called anymore.
Battery Timer is running in parallel and battery level update notifications are sent.

IRQ priorities: SPI = 1, GPIOTE = 3

Any idea what's wrong?

static void drdy_in_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
    if (drdy_counter >= DRDY_COUNT) { // Reduce speed, read every 100th value
		NRF_LOG_INFO("DRDY %dth time called\r\n", drdy_counter);
		drdy_counter = 1;
		uint8_t rxBuf[27];
		data_read(rxBuf, 27);
		send_ble_update(rxBuf, 27); // At the moment this function does nothing
	} else {
		NRF_LOG_INFO("ignore\r\n");
		drdy_counter++;
	}
}

static void spi_init(void)
{
    NRF_LOG_INFO("SPI init\r\n");
    nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
    spi_config.ss_pin   = SPI_SS_PIN;
    spi_config.miso_pin = SPI_MISO_PIN;
    spi_config.mosi_pin = SPI_MOSI_PIN;
    spi_config.sck_pin  = SPI_SCK_PIN;
    spi_config.mode     = NRF_DRV_SPI_MODE_1;
    APP_ERROR_CHECK(nrf_drv_spi_init(&spi, &spi_config, spi_event_handler));
}

static ret_code_t device_init() {
    ...
    nrf_gpio_cfg_input(PIN_DRDY, NRF_GPIO_PIN_PULLUP);
    nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_HITOLO(true);
    uint32_t err_code = nrf_drv_gpiote_in_init(PIN_DRDY, &in_config, drdy_in_handler);
    APP_ERROR_CHECK(err_code);
    nrf_drv_gpiote_in_event_enable(PIN_DRDY, true);
    return NRF_SUCCESS;
}

main() {
    ...
    conn_params_init();
    spi_init();
    device_init();

    // Start execution.
    application_timers_start();
    ...
}

Thx

Related