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

Software Interrupt Handler nRF52832

Hi,

Good day!

Statement of porblem: We are developing appliction using nrf52832. In our application we have Capacitive touch button and capacitive wheel sensor for user input and other pheripheral LED, TEMP.. interrupts are available. At the moment application interrupts are run through a while loop in main.c (which is for sure not the best way to do it). and using app_timer. 

Query: 

I would appreciate suggestions, in determinig what is the best approach to this implementation part.  I looked up google found out that Software interrupts(SWI) can be used for this purpose. But i could not find any example which describes the SWI use in SDK. 

If more inforamtion required please do let me know.

Thank you

Aim High.

  • HI Aim High, 

    the nRF52832 has a EGU — Event generator unit ( i.e. Software interrupt unit) that you can use to trigger SW interrupts, see snippet below.

    void SWI3_EGU3_IRQHandler(void)
    {   
        // Clear SWI Event. 
        NRF_EGU3->EVENTS_TRIGGERED[0] = 0;
                 
        // Place code here
    
    }
    
    static void init_egu()
    {  
        // Enable TRIGGERED0 interrupt
        NRF_EGU3->INTENSET = EGU_INTENSET_TRIGGERED0_Enabled << EGU_INTENSET_TRIGGERED0_Pos;
        
        // Set EGU3 Interrupt pririty to 6.
        NVIC_SetPriority(SWI3_EGU3_IRQn,6);
        
        //Enable SWI3_EGU3 interrupt. 
        NVIC_EnableIRQ(SWI3_EGU3_IRQn);
    }
    
    
    int main(void)
    {
        bool erase_bonds;
        uint32_t err_code;
        
        // Initialize.
        log_init();
        timers_init();
        buttons_leds_init(&erase_bonds);
        ble_stack_init();
        gap_params_init();
        gatt_init();
        advertising_init();
        services_init();
        conn_params_init();
        egu_init();
        
        // Trigger event
        NRF_EGU3->TASKS_TRIGGER[0] = 1;
        
        // Enter main loop.
        for (;;)
        {
            if (NRF_LOG_PROCESS() == false)
            {
                power_manage();
            }
        }
    }
    Best regards
    Bjørn
  • Hi Bjorn,

    Thank you for that code snippet.

    Do you have any specific examples available in the SDK 16 or lower?

    Does this EGU have got any API's?

    Is there any restriction on using EGU with softdevice?

    Is EGU any different from SWI?

    Thank you 

    Aim High

  • AimHigh said:
    Do you have any specific examples available in the SDK 16 or lower?

     No, there is no dedicated EGU example in the SDKm but there are several threads on it here on DevZone

    AimHigh said:
    Does this EGU have got any API's?

     No, the register interface itself is very straight forward so we have not opted for an Hardware abstraction layar on top. 

    AimHigh said:
    Is there any restriction on using EGU with softdevice?

     Yes, see Hardware peripherals under System on Chip resource requirements in the S132 SoftDevice specification. 

    AimHigh said:
    Is EGU any different from SWI?

     No, not really. The EGU allows you to trigger a interrupt from software, i.e. a Software Interrupt. 

    Best regards

    Bjørn

Related