-
Notifications
You must be signed in to change notification settings - Fork 137
SAADC Simple blocking mode
Karol Lasończyk edited this page Dec 6, 2019
·
1 revision
#include <stdbool.h>
#include <stdint.h>
#include <nrfx_saadc.h>
nrfx_saadc_channel_t channel = NRFX_SAADC_DEFAULT_CHANNEL_SE(NRF_SAADC_INPUT_AIN1, 0);
static void handle_error(nrfx_err_t error_code)
{
if (error_code!= NRFX_SUCCESS)
{
// error
while(1){};
}
}
int main(void)
{
nrfx_err_t err_code;
nrf_saadc_value_t sample;
err_code = nrfx_saadc_init(NRFX_SAADC_DEFAULT_CONFIG_IRQ_PRIORITY);
handle_error(err_code);
err_code = nrfx_saadc_channels_config(&channel, 1);
handle_error(err_code);
err_code = nrfx_saadc_simple_mode_set((1<<0),
NRF_SAADC_RESOLUTION_10BIT,
NRF_SAADC_OVERSAMPLE_DISABLED,
NULL);
handle_error(err_code);
err_code = nrfx_saadc_buffer_set(&sample, 1);
handle_error(err_code);
while (1)
{
err_code = nrfx_saadc_mode_trigger();
handle_error(err_code);
printf("sample %d", sample);
NRFX_DELAY_US(1000000);
}
}