i want to sample 2 ADC channels value and send to smartphone, and my thought is use the software time to sample 2 ADC channels every 500ms, the code is like this below.
void saadc_init(void)
{
ret_code_t err_code;
nrf_saadc_channel_config_t channel_0_config =
NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN0);
nrf_saadc_channel_config_t channel_1_config =
NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN1);
err_code = nrf_drv_saadc_init(NULL, saadc_callback);
APP_ERROR_CHECK(err_code);
err_code = nrf_drv_saadc_channel_init(0, &channel_0_config);
APP_ERROR_CHECK(err_code);
err_code = nrf_drv_saadc_channel_init(1, &channel_1_config);
APP_ERROR_CHECK(err_code);
err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool,SAMPLES_IN_BUFFER);
APP_ERROR_CHECK(err_code);
}
void saadc_callback(nrf_drv_saadc_evt_t const * p_event)
{
// float val;
if (p_event->type == NRF_DRV_SAADC_EVT_DONE)
{
ret_code_t err_code;
err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool, SAMPLES_IN_BUFFER);
APP_ERROR_CHECK(err_code);
}
}
m_buffer_pool is global array: static nrf_saadc_value_t m_buffer_pool[2];
and my timer handler funtion is:
static void thi_monitor_handler(void)
{
uint32_t err_code=0;
//static uint32_t cnt=0;
//nrf_saadc_value_t saadc_val;
uint16_t u16_saadc_val = 0;
uint16_t u16_saadc_val_1 = 0;
nrf_gpio_pin_toggle(LED_1);
nrf_drv_saadc_sample();
u16_saadc_val = m_buffer_pool[0];
u16_saadc_val_1 = m_buffer_pool[1];
err_code = ble_lbs_on_dht_change(m_conn_handle, &m_lbs, u16_saadc_val, u16_saadc_val_1);
NRF_LOG_INFO("err_code = %d\r\n", err_code);
//APP_ERROR_HANDLER(err_code);
APP_ERROR_CHECK(err_code);
if ((err_code != NRF_SUCCESS) &&
(err_code != NRF_ERROR_INVALID_STATE) &&
(err_code != BLE_ERROR_INVALID_CONN_HANDLE)&&
(err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING)
)
{
APP_ERROR_HANDLER(err_code);
}
}
then download the code, the rtt viwer display below:
0> <info> app: Blinky example started.
0> <info> app: err_code = 8
0>
0> <error> app: Fatal error
can any one can tell me why?
