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

Application never gets into ADC_IRQHandler

Hi!

I'm working with nrf51dk with s110 Soft Device. I need to read ADC every 2ms. In order to achieve that, i made timer with interrupt after 2ms. here is my code of initialising and starting timer, and timer interrupt handler:

    #define ADC_SAMPLING_INTERVAL                APP_TIMER_TICKS(2, APP_TIMER_PRESCALER)
    //...
    app_timer_id_t m_adc_sampling_timer_id;
    //...
    static void timers_init(void)
    {
    	//...
    
    	err_code = app_timer_create(&m_adc_sampling_timer_id,
                                    APP_TIMER_MODE_REPEATED,
                                    adc_sampling_timeout_handler);
       	APP_ERROR_CHECK(err_code);
    	//...
    }
    
    //...
    
    static void application_timers_start(void)
    {
    	//...
    
    		err_code = app_timer_start(m_adc_sampling_timer_id, ADC_SAMPLING_INTERVAL, NULL);
        		APP_ERROR_CHECK(err_code);
    	//...
    }
    
    //...
    
    static void adc_sampling_timeout_handler(void * p_context)
    {
    		uint32_t p_is_running = 0;
    		
    	sd_clock_hfclk_request();
    	while(! p_is_running)  							//wait for the hfclk to be available
      	  {    		
        	        	sd_clock_hfclk_is_running((&p_is_running));
    	}               
    		
    	NRF_ADC->TASKS_START = 1;	
    	nrf_gpio_pin_toggle(LED_2);
    	
    
    	
    }

as You see, i toggle led2 at the end, to make sure that application gets to this point, and it does, so i assume that adc->start instruction is executed. but application never gets into ADC_IRQHandler. here is my initialization of ADC:

void adc_init()
{
	/* Enable interrupt on ADC sample ready event*/		
	NRF_ADC->INTENSET = ADC_INTENSET_END_Msk;   
	sd_nvic_SetPriority(ADC_IRQn, NRF_APP_PRIORITY_LOW);  
	sd_nvic_EnableIRQ(ADC_IRQn);
	
	NRF_ADC->CONFIG	= (ADC_CONFIG_EXTREFSEL_None << ADC_CONFIG_EXTREFSEL_Pos) 
										| (ADC_CONFIG_PSEL_AnalogInput0 << ADC_CONFIG_PSEL_Pos)					
										| (ADC_CONFIG_REFSEL_VBG << ADC_CONFIG_REFSEL_Pos)							
										| (ADC_CONFIG_INPSEL_AnalogInputOneThirdPrescaling << ADC_CONFIG_INPSEL_Pos) 
										| (ADC_CONFIG_RES_10bit << ADC_CONFIG_RES_Pos);					
	
	/* Enable ADC*/
	NRF_ADC->ENABLE = ADC_ENABLE_ENABLE_Enabled;
}

I looked at a lot of examples with adc and i still cant figure out what is wrong with my code. I would apreciate any advice on what could be wrong.

best regards, Ina

Parents
  • Hi Ina

    Can you also show me your ADC_IRQHandler code? What S110 softdevice version are you using? What SDK version are you using? I assume you are using nRF51-DK, can you confirm that?

    Your code looks good. The timer is clearly working since LED_2 is blinking. When are you calling adc_init()?

    To figure out the source for the problem, you could try not to request the hfclk crysal to see it that makes any difference. The ADC should then just use the internal 16MHz RC, which works fine even though the accuracy could be a little worse. Also, you could try to lower the sampling frequency to i.e. 1 Hz or 10 Hz to see if that makes any difference.

    What else is happening in your code? Any other peripheral interrupts set? If you flash adc code from Github, does it work? There is one example there for SDK 9.0.0

Reply
  • Hi Ina

    Can you also show me your ADC_IRQHandler code? What S110 softdevice version are you using? What SDK version are you using? I assume you are using nRF51-DK, can you confirm that?

    Your code looks good. The timer is clearly working since LED_2 is blinking. When are you calling adc_init()?

    To figure out the source for the problem, you could try not to request the hfclk crysal to see it that makes any difference. The ADC should then just use the internal 16MHz RC, which works fine even though the accuracy could be a little worse. Also, you could try to lower the sampling frequency to i.e. 1 Hz or 10 Hz to see if that makes any difference.

    What else is happening in your code? Any other peripheral interrupts set? If you flash adc code from Github, does it work? There is one example there for SDK 9.0.0

Children
No Data
Related