This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Using application timer causes hardfault in ble_app_uart (S120) ?

I've modified the ble_app_uart example by adding GPIOTE so that the transmitter sends a character to the receiver when a GPIO pin is toggled. This part is working well.

Then, I used the application timer to count the number of falling edges occurring in a GPIO pin. I followed the advice in this thread.

This counter worked well if the transmitter did not link with the receiver.

When the receiver was switched on and linked to the transmitter, the counter stopped working.

Is there any way to count the number of falling edge in a GPIO pin without using the application timer?

The transmitter code was based on the ble_app_uart example over S120.

  • Hi,

    The application timer should work fine alongside the SoftDevice. For new designs we recommend using S130 which incorporates the functionality of s120 and s110.

    What error are you getting?

    See this question/answer for more help on debugging using Keil.

    Best regards,

    Øyvind

  • There was no error message. It just froze.

    Here is the serial output without BLE.

    START: 10501  
    PULSE FREQ: 1000
    START: 76037
    PULSE FREQ: 1000
    

    The difference in the counter time is about 65000 = 2 seconds

    Here is the serial output with BLE.

    START: 0
    PULSE FREQ: 1000
    S  <<== Frozen
    
  • Have a look at the question/answer I linked below and check the error code you are getting.

  • I followed the instruction to debug the code. When the code froze, the error handler was called. The error code was 0x00000008. It occurred when the app_timer_start was called.

    Interestingly, when I ran the debug again a few times, the error handler was not called again. It just froze.

    Here is the sequence of my code.

    In main, I initialised the GPIOTE and created the timer.

      gpiote_init();
    
      err_code = app_timer_create(&timer_stim_freq_id, APP_TIMER_MODE_REPEATED, timer_stim_freq_handler);
    

    The timer ID was defined before main,

    APP_TIMER_DEF(timer_stim_freq_id);
    

    I also changed APP_TIMER_OP_QUEUE_SIZE to 10. I don't know if I need to change it - it did not make any noticeable difference.

    In gpiote_init, I define the interrupt handler: audio_stimulus_handler.

    err_code = nrf_drv_gpiote_in_init(AUDIO_STIM_PIN, &fall_event_config, audio_stimulus_handler);
    

    So when the GPIO detects a falling edge, this handler is called and in turn starts the timer.

    void audio_stimulus_handler(void) 
    {
    	uint32_t err_code;
    	switch (audio_stim_case)
    	{
    		case AUDIO_STIM_STATE_IDLE:
    		{
    			// Start the timer
    			err_code = app_timer_start(timer_stim_freq_id, APP_TIMER_TICKS(AUDIO_STIM_MARKER_WINDOW, APP_TIMER_PRESCALER), NULL);
          APP_ERROR_CHECK(err_code);
    

    Then, when the timer is time out, it calls the timer handler, which stops the timer.

    static void timer_stim_freq_handler(void * p_context)
    {
    	uint32_t err_code, diff_tick;
    	switch (audio_stim_case)
    	{
    		case AUDIO_STIM_STATE_EVAL_FREQ:
    		{
    			// Update the state
    			audio_stim_case = AUDIO_STIM_STATE_DONE;
    			// Stop the timer and start again with a different timeout
    			err_code = app_timer_stop(timer_stim_freq_id);
                           APP_ERROR_CHECK(err_code);
    
  • I also want to add AUDIO_STIM_PIN = pin 15 in the nRF dongle. The choice of the pin should not be a problem, should it?

Related