Exemple #1
0
/**
 * @brief ADC interrupt handler.
 */
void ADC_IRQHandler(void)
{
    nrf_adc_conversion_event_clean();

    adc_sample = nrf_adc_result_get();

    // trigger next ADC conversion
    nrf_adc_start();
}
Exemple #2
0
/**@brief Function for handling the Battery measurement timer timeout.
 *
 * @details This function will be called each time the battery level measurement timer expires.
 *          This function will start the ADC.
 *
 * @param[in] p_context   Pointer used for passing some arbitrary information (context) from the
 *                        app_start_timer() call to the timeout handler.
 */
static void battery_level_meas_timeout_handler(void * p_context)
{
    UNUSED_PARAMETER(p_context);
    #ifdef NRF51
    nrf_adc_start();
    #else // NRF52
    uint32_t err_code;
    err_code = nrf_drv_saadc_sample();
    APP_ERROR_CHECK(err_code);
    #endif // NRF51
}
Exemple #3
0
static inline void periodic_task(void)
{
    g_report_req = 1;
    if (++g_blink_cnt >= BLINK_PERIOD)
    {
        g_blink_cnt = 0;
        rtc_cc_schedule(CC_BLINK, BLINK_TICKS);
        nrf_adc_start();
        led_on();
    }
    rtc_cc_schedule(CC_PERIODIC, reporting_ticks());
}
Exemple #4
0
/**
 * @brief ADC interrupt handler.
 */
void ADC_IRQHandler(void)
{
    //nrf_adc_int_disable(ADC_INTENSET_END_Enabled << ADC_INTENSET_END_Pos);

    nrf_adc_conversion_event_clean();

    adc_sample = nrf_adc_result_get();
    //battery_level_update();

   // nrf_adc_int_enable(ADC_INTENSET_END_Enabled << ADC_INTENSET_END_Pos);
    // trigger next ADC conversion
    nrf_adc_start();
}
Exemple #5
0
/**
 * @brief Blocking function for executing single ADC conversion.
 *
 * This function selects desired input, starts single conversion,
 * waits for its finish  and returns result.
 * ADC is left in STOP state, given input is selected.
 * This function does not check if ADC is initialized and powered.
 *
 * @param[in] input is requested input to be selected
 *
 * @return conversion result
 */
int32_t nrf_adc_convert_single(nrf_adc_config_input_t input)
{
    int32_t val;

    nrf_adc_input_select(input);
    nrf_adc_start();

    while (!nrf_adc_conversion_finished())
    {
    }
    nrf_adc_conversion_event_clean();
    val = nrf_adc_result_get();
    nrf_adc_stop();
    return val;
}
nrfx_err_t nrfx_adc_sample_convert(nrfx_adc_channel_t const * const p_channel,
                                   nrf_adc_value_t                * p_value)
{
    nrfx_err_t err_code;

    NRFX_ASSERT(m_cb.state != NRFX_DRV_STATE_UNINITIALIZED);
    if (m_cb.state == NRFX_DRV_STATE_POWERED_ON)
    {
        err_code = NRFX_ERROR_BUSY;
        NRFX_LOG_WARNING("Function: %s, error code: %s.",
                         __func__,
                         NRFX_LOG_ERROR_STRING_GET(err_code));
        return err_code;
    }
    else
    {
        m_cb.state = NRFX_DRV_STATE_POWERED_ON;

        nrf_adc_config_set(p_channel->config.data);
        nrf_adc_enable();
        nrf_adc_int_disable(NRF_ADC_INT_END_MASK);
        nrf_adc_start();
        if (p_value)
        {
            while (!nrf_adc_event_check(NRF_ADC_EVENT_END)) {}
            nrf_adc_event_clear(NRF_ADC_EVENT_END);
            *p_value = (nrf_adc_value_t)nrf_adc_result_get();
            nrf_adc_disable();

            m_cb.state = NRFX_DRV_STATE_INITIALIZED;
        }
        else
        {
            NRFX_ASSERT(m_cb.event_handler);
            m_cb.p_buffer = NULL;
            nrf_adc_int_enable(NRF_ADC_INT_END_MASK);
        }
        err_code = NRFX_SUCCESS;
        NRFX_LOG_INFO("Function: %s, error code: %s.",
                      __func__,
                      NRFX_LOG_ERROR_STRING_GET(err_code));
        return err_code;
    }
}
Exemple #7
0
/**
 * @brief Function for main application entry.
 */
int main(void)
{
    adc_config();

    uart_config();

    printf("\n\rADC HAL simple example\r\n");

    printf("Current sample value:\r\n");

    nrf_adc_start();

    while (true)
    {
        // enter into sleep mode
        __SEV();
        __WFE();
        __WFE();
    }
}
Exemple #8
0
/**@brief Function for application main entry.
 */
int main(void)
{
    uint32_t err_code;
    bool erase_bonds;

    //uart_config();

    //printf("\n\rBDC HAL simple example\r\n"); //GETS HERE, Dies after first letter!

    // Initialize.
    timers_init();
    buttons_leds_init(&erase_bonds);
    ble_stack_init();
    device_manager_init(erase_bonds);
    gap_params_init();
    advertising_init();
    services_init();
    //sensor_simulator_init();
    conn_params_init();

    //uart_config();

    //printf("\n\rBDC HAL simple example\r\n"); //GETS HERE, Dies after first letter!

    //printf("Current sample value:\r\n");

    adc_config();

    // Start execution.
    application_timers_start();
    nrf_adc_start();
    err_code = ble_advertising_start(BLE_ADV_MODE_FAST);
    APP_ERROR_CHECK(err_code);

    // Enter main loop.
    for (;;)
    {
        power_manage();
    }
}
Exemple #9
0
static void temperature_timeout_handler(void * p_context)
{
    // Update temperature and characteristic value.
    int32_t temperature = 0;    // Declare variable holding temperature value
    static int32_t previous_temperature = 15; // Declare a variable to store current temperature until next measurement.
    
		nrf_adc_start();
  
		//full scale 1.2V is 10 bits 1024, prescaler * 3, -750 for 0 then add 25 which is 750 and 10mv per C after that.
		temperature = -(25 + (((3 * ((1200 * adc_sample) / 1023)) - 750)/10));
	
	
    
    // Check if current temperature is different from last temperature
    if(temperature != previous_temperature)
    {
        // If new temperature then send notification
        cch_termperature_characteristic_update(&m_cch_service, &temperature);
    }
    
    // Save current temperature until next measurement
    previous_temperature = temperature;
}
Exemple #10
0
/**
 * @brief Function for main application entry.
 */
int main(void)
{
    adc_config();

    uart_config();

    printf("\n\rADC HAL simple example\r\n");

    printf("Current sample value:\r\n");

    while (true)
    {
			  // trigger next ADC conversion
			  nrf_adc_start();
        // enter into sleep mode
        __SEV();
        __WFE();
        __WFE();
			
			  nrf_delay_ms(100);	
				printf("%d\r\n", (int)adc_sample); // out ADC result
    }
}
Exemple #11
0
/**@brief Function for handling the Battery measurement timer timeout.
 *
 * @details This function will be called each time the battery level measurement timer expires.
 *          This function will start the ADC.
 *
 * @param[in] p_context   Pointer used for passing some arbitrary information (context) from the
 *                        app_start_timer() call to the timeout handler.
 */
static void battery_level_meas_timeout_handler(void * p_context)
{
    UNUSED_PARAMETER(p_context);
    nrf_adc_start();
}
Exemple #12
0
static void timer_timeout_handler(void * p_context)
{
    UNUSED_PARAMETER(p_context);
    nrf_gpio_pin_toggle(BSP_LED_1);
    nrf_adc_start();
}
void nrfx_adc_sample(void)
{
    NRFX_ASSERT(m_cb.state != NRFX_DRV_STATE_UNINITIALIZED);
    NRFX_ASSERT(!nrf_adc_is_busy());
    nrf_adc_start();
}
Exemple #14
0
void BatteryTick()
{
	nrf_adc_start();
}