/**@brief Initialize application. */ static void application_initialize() { uint32_t err_code; err_code = sd_ant_cw_test_mode_init(); APP_ERROR_CHECK(err_code); // sd_ant_cw_test_mode assumes that the hfclck is enabled. // Request and wait for it to be ready. err_code = sd_clock_hfclk_request(); APP_ERROR_CHECK(err_code); uint32_t hfclk_is_running = 0; while (!hfclk_is_running) { APP_ERROR_CHECK(sd_clock_hfclk_is_running(&hfclk_is_running) ); } // CW Mode at +4dBm, 2410 MHz with Modulated Transmission err_code = sd_ant_cw_test_mode(RADIO_FREQ_OFFSET, RADIO_TX_POWER_LVL_CUSTOM, RADIO_TXPOWER_TXPOWER_Pos4dBm, MODULATED_TRANSMISSION_TEST_MODE); APP_ERROR_CHECK(err_code); }
bool nrf_drv_clock_hfclk_is_running(void) { bool result; ASSERT(m_clock_cb.module_initialized); #ifndef SOFTDEVICE_PRESENT result = nrf_clock_hf_is_running(NRF_CLOCK_HF_SRC_HIGH_ACCURACY); #else uint32_t is_running; UNUSED_VARIABLE(sd_clock_hfclk_is_running(&is_running)); result = is_running ? true : false; #endif return result; }
void OpenAdc(uint32_t uAdcNumber) { 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)); } while (ADC_BUSY == NRF_ADC->EVENTS_END); NRF_ADC->CONFIG = (ADC_CONFIG_RES_10bit << ADC_CONFIG_RES_Pos) | (ADC_CONFIG_INPSEL_AnalogInputOneThirdPrescaling << ADC_CONFIG_INPSEL_Pos) | (ADC_CONFIG_REFSEL_VBG << ADC_CONFIG_REFSEL_Pos) | (uAdcNumber << ADC_CONFIG_PSEL_Pos); NRF_ADC->TASKS_START = 1; }
bool nrf_drv_clock_hfclk_is_running(void) { ASSERT(m_clock_cb.module_initialized); #ifdef SOFTDEVICE_PRESENT if (softdevice_handler_is_enabled()) { uint32_t is_running; UNUSED_VARIABLE(sd_clock_hfclk_is_running(&is_running)); return (is_running ? true : false); } #endif // SOFTDEVICE_PRESENT return nrf_clock_hf_is_running(NRF_CLOCK_HFCLK_HIGH_ACCURACY); }
/** * @brief Function to trigger ADC sampling */ void adc_sample(void) { ret_code_t ret_code; uint32_t p_is_running = 0; ret_code = nrf_drv_adc_buffer_convert(adc_buffer, ADC_BUFFER_SIZE); // Allocate buffer for ADC APP_ERROR_CHECK(ret_code); //Request the external high frequency crystal for best ADC accuracy. For lowest current consumption, don't request the crystal. sd_clock_hfclk_request(); while(! p_is_running) { //wait for the hfclk to be available sd_clock_hfclk_is_running((&p_is_running)); } for (uint32_t i = 0; i < ADC_BUFFER_SIZE; i++) { while((NRF_ADC->BUSY & ADC_BUSY_BUSY_Msk) == ADC_BUSY_BUSY_Busy) {} //Wait until the ADC is finished sampling NRF_LOG_INFO("Start sampling ... \r\n"); nrf_drv_adc_sample(); // Trigger ADC conversion } }