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

Need help on setting up low level interrupt handler

I'm trying to get the most performance per mA out of my nRF52, for test purposes I've used the nrfx libraries to communicate to the peripherals but I want to make my own.

I’ve successfully created a TWI driver using the HAL library direct register modification. (600ish bytes compared to the 4k optimized nrfx library)

The issue I have now is that I check using a while loop if the transmission is done.

I want to implement interrupts but this seems to be harder than I thought.

I’ve tried to enable interrupts on specific events like error and stop.

nrf_twim_int_enable(p_twim, NRF_TWIM_INT_STOPPED_MASK | NRF_TWIM_INT_ERROR_MASK);

               NRFX_IRQ_PRIORITY_SET(SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQn, 2);

               NRFX_IRQ_ENABLE(SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQn);

I’ve also created a function to be called when the interrupt fires.

#define TWIM0_HANDLER SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQHandler

Yet, whatever I try I cannot get the interrupt to work and I cannot get more information in example projects due to lots of nested functions and structures.

Is it possible to show me a example how to setup the handler properly without the use of higher level libraries other than the HAL?

Kind Regards

  • Well, as always I've spoken too soon.

    After fiddling around I've managed to get it working.

    I've changed the NRFX_IRQ_XXX to

    NVIC_SetPriority(SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQn, p_config->interrupt_priority);
    NVIC_EnableIRQ(SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQn);

    And this made it work. 

    P.S. the 4k optimized is wrong, it is unoptimized. Optimized is 1.9k max which is still 3x as much as the bare code I've written.

    Kind Regards

Related