Hi,
I have to check every 10 minutes the battery level when BLE is connected.
I have found in this forum this source : github.com/.../main.c
As the source date is 2014-07-25, can you confirm that it is still the right way to check battery level with nRF51822 softdevice 8 and SDK10 when the chip has a active (potential data transfert) connection with a central?
//ADC initialization
static void adc_init(void)
{
/* 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) /* Bits 17..16 : ADC external reference pin selection. */
| (ADC_CONFIG_PSEL_AnalogInput2 << ADC_CONFIG_PSEL_Pos) /*!< Use analog input 2 as analog input. */
| (ADC_CONFIG_REFSEL_VBG << ADC_CONFIG_REFSEL_Pos) /*!< Use internal 1.2V bandgap voltage as reference for conversion. */
| (ADC_CONFIG_INPSEL_AnalogInputOneThirdPrescaling << ADC_CONFIG_INPSEL_Pos) /*!< Analog input specified by PSEL with no prescaling used as input for the conversion. */
| (ADC_CONFIG_RES_8bit << ADC_CONFIG_RES_Pos); /*!< 8bit ADC resolution. */
/* Enable ADC*/
NRF_ADC->ENABLE = ADC_ENABLE_ENABLE_Enabled;
}
// ADC timer handler to start ADC sampling
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_gpio_pin_toggle(LED_2); //Toggle LED2 to indicate start of sampling
NRF_ADC->TASKS_START = 1; //Start ADC sampling
}
/* Interrupt handler for ADC data ready event */
void ADC_IRQHandler(void)
{
/* Clear dataready event */
NRF_ADC->EVENTS_END = 0;
/* Write ADC result to port 2 */
nrf_gpio_port_write(NRF_GPIO_PORT_SELECT_PORT2, NRF_ADC->RESULT);
nrf_gpio_pin_toggle(LED_3);
//Use the STOP task to save current. Workaround for PAN_028 rev1.5 anomaly 1.
NRF_ADC->TASKS_STOP = 1;
//Release the external crystal
sd_clock_hfclk_release();
}
Thanks