static void hfclk_stop(void) { #ifndef SOFTDEVICE_PRESENT nrf_clock_task_trigger(NRF_CLOCK_TASK_HFCLKSTOP); while (nrf_clock_hf_is_running(NRF_CLOCK_HF_SRC_HIGH_ACCURACY)); #else UNUSED_VARIABLE(sd_clock_hfclk_release()); #endif }
uint32_t GetAdcValue(void) { NRF_ADC->EVENTS_END = ADC_BUSY; while (ADC_IDLE == NRF_ADC->EVENTS_END); uint32_t uRet = NRF_ADC->RESULT & ADC_RESULT_RESULT_Msk; NRF_ADC->TASKS_STOP = 1; NRF_ADC->EVENTS_END = 0; //Release the external crystal sd_clock_hfclk_release(); return uRet; }
static void hfclk_stop(void) { #ifdef SOFTDEVICE_PRESENT if (softdevice_handler_is_enabled()) { (void)sd_clock_hfclk_release(); return; } #endif // SOFTDEVICE_PRESENT nrf_clock_task_trigger(NRF_CLOCK_TASK_HFCLKSTOP); while (nrf_clock_hf_is_running(NRF_CLOCK_HFCLK_HIGH_ACCURACY)) {} m_clock_cb.hfclk_on = false; }
/** * @brief ADC interrupt handler. */ static void adc_event_handler(nrf_drv_adc_evt_t const * p_event) { uint32_t err_code; uint16_t adc_sum_value = 0; uint16_t adc_average_value; uint16_t adc_result_millivolts; uint8_t adc_result_percent; sd_clock_hfclk_release(); //Release the external crystal adc_event_counter++; NRF_LOG_INFO(" ADC event counter: %d\r\n", adc_event_counter); if (p_event->type == NRF_DRV_ADC_EVT_DONE) { uint32_t i; for (i = 0; i < p_event->data.done.size; i++) { NRF_LOG_INFO("Sample value %d: %d\r\n", i+1, p_event->data.done.p_buffer[i]); adc_sum_value += p_event->data.done.p_buffer[i]; //Sum all values in ADC buffer } adc_average_value = adc_sum_value / p_event->data.done.size; //Calculate average value from all samples in the ADC buffer NRF_LOG_INFO("Average ADC value: %d\r\n", adc_average_value); adc_result_millivolts = ADC_RESULT_IN_MILLI_VOLTS(adc_average_value); //Transform the average ADC value into millivolts value NRF_LOG_INFO("ADC result in millivolts: %d\r\n", adc_result_millivolts); adc_result_percent = battery_level_in_percent(adc_result_millivolts); //Transform the millivolts value into battery level percent. NRF_LOG_INFO("ADC result in percent: %d\r\n", adc_result_percent); //Send the battery level over BLE err_code = ble_bas_battery_level_update(&m_bas, adc_result_percent); //Send the battery level over BLE if ((err_code != NRF_SUCCESS) && (err_code != NRF_ERROR_INVALID_STATE) && (err_code != BLE_ERROR_NO_TX_PACKETS) && (err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING)) { APP_ERROR_HANDLER(err_code); //Assert on error } } }