This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nRF52 & SAADC

I started developing a project on nRF52. My task is to read the value from the light sensor (phototransistor).

The sensor is connected in this way:

 

my code:

init:

void saadc_callback(nrf_drv_saadc_evt_t const * p_event)
{
        (void) p_event;
}

void saadc_init(void)
{
    
    uint32_t err_code;
    
    err_code = nrf_drv_saadc_init(NULL, saadc_callback);
    APP_ERROR_CHECK(err_code);
    nrf_saadc_channel_config_t cfg =  NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN7);
    
    nrf_drv_saadc_channel_init(NRF_SAADC_INPUT_AIN7-1,&cfg);
}


reading:

while(1)

{
    nrf_saadc_value_t als;
    nrf_drv_saadc_sample_convert(7, &als);
...



but it doesn't work .. The chip is reset every time I try to read smth.

Also I checked the voltage on the sensor and it is too low, it looks like AIN7 is not tuned or ... I don't know ... I read a lot of forums and tried 1001 options to read something from the sensor but no luck

here is general view to my config

...

Parents
  • You are mixing the first parameter used in nrf_drv_saadc_channel_init() and nrf_drv_saadc_sample_convert() with the analog input that is configured. There is no dependency between the two. So if you only want to sample NRF_SAADC_INPUT_AIN7 input, then you use nrf_drv_saadc_channel_init(0,&cfg), but make sure that cfg is using NRF_SAADC_INPUT_AIN7. 

    I suggest to take a look at the \examples\peripheral\saadc in the nRF5 SDK.

Reply
  • You are mixing the first parameter used in nrf_drv_saadc_channel_init() and nrf_drv_saadc_sample_convert() with the analog input that is configured. There is no dependency between the two. So if you only want to sample NRF_SAADC_INPUT_AIN7 input, then you use nrf_drv_saadc_channel_init(0,&cfg), but make sure that cfg is using NRF_SAADC_INPUT_AIN7. 

    I suggest to take a look at the \examples\peripheral\saadc in the nRF5 SDK.

Children
No Data
Related