Hello,
On a custom board, using the NRF52832, we want to know the value of a potentiometer. This value is send via a signal on the AIN5 pin of the NRF52.
So, I tried to set up a code to read the value via the saadc module, but it seems it doesn't work as expected...
Here's my code :
void saadc_callback(nrf_drv_saadc_evt_t const * p_event)
{
if (p_event->type == NRF_DRV_SAADC_EVT_DONE)
{
ret_code_t err_code;
err_code = nrf_drv_saadc_buffer_convert(p_event->data.done.p_buffer, SAMPLES_IN_BUFFER);
APP_ERROR_CHECK(err_code);
NRF_LOG_INFO("%d\r\n", p_event->data.done.p_buffer[0]);
}
}
void saadc_init(void)
{
ret_code_t err_code;
nrf_saadc_channel_config_t channel_config
= NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN5);
err_code = nrf_drv_saadc_init(NULL, saadc_callback);
APP_ERROR_CHECK(err_code);
err_code = nrf_drv_saadc_channel_init(0, &channel_config);
APP_ERROR_CHECK(err_code);
err_code = nrf_drv_saadc_buffer_convert(m_buffer, SAMPLES_IN_BUFFER);
APP_ERROR_CHECK(err_code);
}
/**@brief Function for application main entry.
*/
int main(void)
{
bool erase_bonds;
ret_code_t err_code;
initLeds();
led_purple();
// Initialize.
log_init();
// Initialize the async SVCI interface to bootloader before any interrupts are enabled.
//err_code = ble_dfu_buttonless_async_svci_init();
//APP_ERROR_CHECK(err_code);
timers_init();
buttons_leds_init(&erase_bonds);
power_management_init();
ble_stack_init();
storage_init();
gap_params_init();
//scan_init();
gatt_init();
services_init();
advertising_init();
conn_params_init();
peer_manager_init();
//db_discovery_init();
//lbs_c_init();
// Start execution.
NRF_LOG_INFO("Devroye application started.");
application_timers_start();
//scan_start();
advertising_start(erase_bonds);
saadc_init();
// Enter main loop.
for (;;)
{
nrf_drv_saadc_sample();
idle_state_handle();
}
}
My result are the following :
[00:00:02.452,636] <info> app: 90 [00:00:02.527,526] <info> app: 96 [00:00:02.577,453] <info> app: 97 [00:00:04.377,746] <info> app: 102 [00:00:04.452,636] <info> app: 89 [00:00:04.527,526] <info> app: 96 [00:00:04.577,453] <info> app: 98 [00:00:06.377,746] <info> app: 101 [00:00:06.452,636] <info> app: 90 [00:00:06.527,526] <info> app: 96 [00:00:06.577,453] <info> app: 96
And of course, the values are not changing if I changed the value of the potentiometer. I don't understand why is it not working...
Another issue that I had, is that the adc value are showing 3 by 3 with a delay but I've not implemented a delay, so I don't know why...
Thanks for your help !
Chris