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

S110 Soft Device and Analog Inputs

I have an application that reads an nRF51822 pin configured as analog input and then sends that value using "ble uart" (included in Nordic's sdk). Analog input is read in an interrupt 250 times per second, but only a few of those values are sent from my main loop (not from interrupt). However, when the connection is established, the analog input stops working but just gives a fixed value (218).

The problem can be solved by initializing analog input in my main loop all the time as follows:

nrf_adc_init(ADC_RES_10bit, ADC_INPUT_AIN3_P02, ADC_INT_DISABLED);

But if I do so, then the BTLE connection hangs up within a half a minute, and actually the whole system probably crashes.

How should I handle ADC when using soft device? Is the soft device using ADC in some way?

Parents
  • Hi Jarmo

    I am not certain why this is failing actually. However, if you are getting stuck on that loop, it may be because the ADC END event flag is cleared somewhere else in your code.

    Make sure you explicitly set the interupt priority to LOW for the interrupt that you call this ADC handler from. You can see how to set interrupt priority low in the example I posted earlier on this thread, in the ADC init routine.

    I have implemented the example above in a non polling way, i.e. I start the ADC sampling with a timer and then handle the ADC result in the ADC interrupt handler. With that implementation I have not come across any problems. Perhaps you can consider that if the problem persists.

Reply
  • Hi Jarmo

    I am not certain why this is failing actually. However, if you are getting stuck on that loop, it may be because the ADC END event flag is cleared somewhere else in your code.

    Make sure you explicitly set the interupt priority to LOW for the interrupt that you call this ADC handler from. You can see how to set interrupt priority low in the example I posted earlier on this thread, in the ADC init routine.

    I have implemented the example above in a non polling way, i.e. I start the ADC sampling with a timer and then handle the ADC result in the ADC interrupt handler. With that implementation I have not come across any problems. Perhaps you can consider that if the problem persists.

Children
Related