Пример #1
0
/**
 * @brief Function for main application entry.
 */
int main(void)
{
    LEDS_CONFIGURE(BSP_LED_0_MASK);
    LEDS_OFF(BSP_LED_0_MASK);

    adc_config();
    UNUSED_RETURN_VALUE(NRF_LOG_INIT());

    NRF_LOG_PRINTF("ADC example\r\n");

    while (true)
    {
        APP_ERROR_CHECK(nrf_drv_adc_buffer_convert(adc_buffer,ADC_BUFFER_SIZE));
        uint32_t i;
        for (i = 0; i < ADC_BUFFER_SIZE; i++)
        {
            // manually trigger ADC conversion
            nrf_drv_adc_sample();
            // enter into sleep mode
            __SEV();
            __WFE();
            __WFE();

            nrf_delay_ms(100);
            LEDS_INVERT(BSP_LED_0_MASK);
        }
    }
}
Пример #2
0
/**
 * @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
    }					
}