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

GPIO not working with SD

Hello,

I have configured a 1 ms timer (Timer 2) interrupt. I am just updating some static variables for reference in the 1 ms interrupt. Everything seems to be working fine here (SD enabled). However I tried to toggle one of the GPIO pins in the 1 ms interrupt routine every 6 ms. Looks like this does not go well with SD. The control is in SD and is not returning to any one of my functions. I am not sure what the problem is. After this the SD stops broadcasting and nothing works. After I reset the controller via debugger it starts broadcasting and the same thing repeats.

Are there known issues in this regard? If not then can anyone let me know what might be the problem? I am not sure if I have given sufficient details. If not do let me know.

I am using: SD: 7.1 SDK 6

Thanks in advance!

  • What you are trying to achieve is basic and that should work otherwise there would have been a lot of reports here regarding that. I have verified this on SDK 7.2 with just one advertiser and there were no problems with the gpio. I verified even with 0.1ms timer interrupt and it just worked fine.

    post your code here and I can check for you.

  • Hey Thanks for your response! Here is the code:

    1 ms timer configuration: NRF_TIMER2->TASKS_STOP = 1; // Stop timer, if it was running NRF_TIMER2->TASKS_CLEAR = 1; NRF_TIMER2->MODE = TIMER_MODE_MODE_Timer; // Timer mode (not counter) NRF_TIMER2->EVENTS_COMPARE[0] = 0; // clean up possible old events NRF_TIMER2->EVENTS_COMPARE[1] = 0; NRF_TIMER2->EVENTS_COMPARE[2] = 0; NRF_TIMER2->EVENTS_COMPARE[3] = 0;

    // Timer is polled, but enable the compare0 interrupt in order to wakeup from CPU sleep
    NRF_TIMER2->INTENSET    = TIMER_INTENSET_COMPARE0_Msk;
    	NRF_TIMER2->SHORTS      = 1 << TIMER_SHORTS_COMPARE0_CLEAR_Pos;    // Clear the count every time timer reaches the CCREG0 count
    NRF_TIMER2->PRESCALER   = 9;                                       // Input clock is 16MHz, timer clock = 2 ^ prescale -> interval 1us 9
    NRF_TIMER2->CC[0]       = 32;                          
    	NVIC_EnableIRQ(TIMER2_IRQn);
    	NRF_TIMER2->TASKS_START = 1;
    

    1 ms Timer IRQ:

    void TIMER2_IRQHandler(void) { if ((NRF_TIMER2->EVENTS_COMPARE[0] != 0) && ((NRF_TIMER2->INTENSET & TIMER_INTENSET_COMPARE0_Msk) != 0)) { NRF_TIMER2->EVENTS_COMPARE[0] = 0; //Clear compare register 0 event ms_update_timer(); h++; if((h<6) && (BuzzerTimer != 0)) { nrf_gpio_pin_set(BUZZER_0); } else { nrf_gpio_pin_clear(BUZZER_0); h=0; }

    }
    

    }

    Is it possible to check with SD 7.1? Thanks for your time.

  • I copied your timer logic into my test and it worked just fine even with 7.1. There must be something else that you must be doing wrong with advertiser (not related to Timer initialization and not related to timer interrupt handler)

    I would however suggest you to set your timer interrupt priority to lower

    	NVIC_SetPriority(TIMER2_IRQn, APP_PRIORITY_LOW);
    	NVIC_ClearPendingIRQ(TIMER2_IRQn);
    	NVIC_EnableIRQ(TIMER2_IRQn);
    

    Please note that on Cortex-M0

    Out of reset, all interrupts and exceptions with configurable priority have the same default priority of zero. This priority number represents the highest-possible interrupt urgency.

  • Hey Aryan,

    Thanks for your time and inputs. I have updated your code as per your suggestion. The port I am toggling is basically connected to a Piezo buzzer. As stated the buzzer starts beeping upon starting the device. Upon BLE connection or disconnection the buzzer stops and then the device stops broadcasting too. I have kinda reached a dead end here. Is it possible to share your project? I would like to flash your s/w and check the behavior with my device. Thanks!

  • I am sorry for the late answer. When I try to check something, I update some example code verify and move on, I did not save that configuration. Sorry for that. I could help you if you could give me your project and I will look into it to see why the GPIO (in your case buzzer ) is not working as it should.

Related