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

ADC error 8

Hi everyone,

We have three ADC channels, two of them are implemented as a simple ADC without oversampling, the third one uses oversampling. Because one of them use oversampling the adc_uninit() method has to be called firstly when a transition is required

static void adc_uninit(void)
{   
     //nrf_drv_saadc_abort();

     if(m_mass.adc_state == OVERSAMPLING)
     {
       nrf_drv_saadc_channel_uninit(LOAD_CELL_CHANNEL);
     }
     else if(m_mass.adc_state == NORMAL)
     {
        nrf_drv_saadc_channel_uninit(TEMPERATURE_CHANNEL);
        nrf_drv_saadc_channel_uninit(BATTERY_CHANNEL);   
     }     

     nrf_drv_saadc_uninit();
     
     m_mass.adc_state = NONE;   
}

and after that, the saadc_oversampling_init(void) or adc_init()  method is executed depends on the request inserted in the particular characteristic. After one or two switches it happens that (when oversampling_init is called) in method mass_test() function nrf_drv_saadc_sample() return 8. I know that this indicates that ADC is not busy but I do not know why this situation occurs. I will appreciate any help. The program uses Softdevice s112 and SDKv16.00. It is very interesting that the program works fine on nrf52832 but not on nrf52811.

static void saadc_oversampling_init(void)
{

if(m_mass.adc_state == NONE)
{
ret_code_t err_code = NRF_SUCCESS;

nrf_saadc_channel_config_t channel_config = NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN2);
channel_config.gain = NRF_SAADC_GAIN1_3;
channel_config.burst = NRF_SAADC_BURST_ENABLED;

nrfx_saadc_config_t default_config = NRFX_SAADC_DEFAULT_CONFIG;
default_config.oversample = NRF_SAADC_OVERSAMPLE_128X;
default_config.resolution = NRF_SAADC_RESOLUTION_12BIT;
default_config.interrupt_priority = APP_IRQ_PRIORITY_LOW;


err_code = nrf_drv_saadc_init(&default_config, saadc_callback) 
APP_ERROR_CHECK(err_code);

err_code = nrf_drv_saadc_channel_init(LOAD_CELL_CHANNEL, &channel_config);
APP_ERROR_CHECK(err_code);
m_mass.adc_state = OVERSAMPLING;
}

}



static void adc_init(void)
{ 
if(m_mass.adc_state == NONE)
{
ret_code_t err_code = NRF_SUCCESS;


nrf_saadc_channel_config_t channel_config2 = NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN6);
channel_config2.gain = NRF_SAADC_GAIN1_3;

err_code = nrf_drv_saadc_channel_init(BATTERY_CHANNEL, &channel_config2);
APP_ERROR_CHECK(err_code);

nrf_saadc_channel_config_t channel_config3 = NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN3);
channel_config3.gain = NRF_SAADC_GAIN1_3;
err_code = nrf_drv_saadc_channel_init(TEMPERATURE_CHANNEL, &channel_config3);
APP_ERROR_CHECK(err_code);

nrfx_saadc_config_t default_config = NRFX_SAADC_DEFAULT_CONFIG;
default_config.resolution = NRF_SAADC_RESOLUTION_10BIT;
default_config.oversample = NRF_SAADC_OVERSAMPLE_DISABLED;

err_code = nrf_drv_saadc_init(&default_config, saadc_callback);



APP_ERROR_CHECK(err_code); 

m_mass.adc_state = NORMAL;
}

}





static void mass_test()
{ 
uint32_t err_code; 

m_mass.test_counter++;

if(m_mass.test_counter == 1)
{ 
adc_uninit();
saadc_oversampling_init(); 

err_code = app_timer_start(testing_peripheral_units_id, INTERVAL_1000MS ,NULL); 
APP_ERROR_CHECK(err_code); 
}
else if(m_mass.test_counter == 2)
{


err_code = nrf_drv_saadc_buffer_convert(buffer, 1);
APP_ERROR_CHECK(err_code); 

err_code = nrf_drv_saadc_sample();


APP_ERROR_CHECK(err_code); 

err_code = app_timer_start(testing_peripheral_units_id, INTERVAL_1000MS ,NULL); 
APP_ERROR_CHECK(err_code);
} 
else if(m_mass.test_counter == 3)
{


m_mass.test_counter = 1;
err_code = app_timer_start(testing_peripheral_units_id, INTERVAL_1000MS ,NULL); 
APP_ERROR_CHECK(err_code);
}
}

Parents
  • Hello,

    function nrf_drv_saadc_sample() return 8. I know that this indicates that ADC is not busy but I do not know why this situation occurs. I will appreciate any help. The program uses Softdevice s112 and SDKv16.00. It is very interesting that the program works fine on nrf52832 but not on nrf52811.

    I suspect that this is the NRF_ERROR_INVALID_STATE returned by nrf_drv_saadc_sample.
    Could you ensure that DEBUG is defined in your preprocessor defines? How this can be done is illustrated in the included image:

    When we have confirmed that this in fact is the returned error, we may look into how it ends up in the invalid state.
    Furthermore, I notice that you are never unitializing the channels. I recommend unitilizing and reinitilizing it again, instead of just overwriting the existing config.

    For future reference, please use the "Insert -> Code" format when sharing code on the forum.

    Best regards,
    Karl


  • I modified the code according to your suggestion. Here is the log result:

    <info> app: Connected.
    00>
    00> <info> app: GATT ATT MTU on connection 0x0 changed to 128.
    00>
    00> <error> app: ERROR 8 [NRF_ERROR_INVALID_STATE] at C:\Users\samos\OneDrive\Documents\Samo\nRF52_SDK\examples\ble_peripheral\Ble_Indu4s\main.c:1140
    00>
    00> PC at: 0x0001F0D3
    00>
    00> <error> app: End of error report

    Row 1140 is the same as row 91 in the attached code in my first post. I do not understand why code works fine on nrf52832.

  • Hello,

    control said:
    I modified the code according to your suggestion. Here is the log result:
    control said:
    Row 1140 is the same as row 91 in the attached code in my first post. I do not understand why code works fine on nrf52832.

    Thank you for confirming this. It seems like the SAADC indeed is in an invalid state following the switch in configuration.
    This sounds to me a lot like the SAADC Errata 212 for the nRF52811 - though it is strange that you are only seeing it on the nRF52811, and not on the nRF52832.

    Could you implement the workaround for Errata 212 in your project, and let me know if this returns the SAADC to the expected behavior?

    Best regards,
    Karl

  • I implemented Errata 212 and it seems that it works now. BTW: I do not want to open a new topic for one additional question. Please let me know if UART can use inner pull up or it is mandatory to use outer pull up. Our current configuration uses an inner pull up resistor on the Rx pin and we do not get any response. I am wondering if the problem lies in the fact that the outer pull up is not used

  • Hello again,

    control said:
    I implemented Errata 212 and it seems that it works now.

    Great, I am happy to hear that it is now working as expected!

    control said:
    Please let me know if UART can use inner pull up or it is mandatory to use outer pull up. Our current configuration uses an inner pull up resistor on the Rx pin and we do not get any response. I am wondering if the problem lies in the fact that the outer pull up is not used

    The UART pins can use inner pullup, yes. You do not need external pull up resistors. To troubleshoot this issue I would use a logic analyzer to monitor the pin, to see if it is behaving as expected - I do not know what you mean when you say you are not getting any response on the RX pin, this sounds like it might be a problem in the other end of the connection ( if nothing is being sent ).

    control said:
    BTW: I do not want to open a new topic for one additional question.

    It is ok this time, but please open a new ticket in the future if you should have any additional questions that are not related to the initial ticket.
    The response time is the same for existing tickets, so there is no reason not to open a new one instead of asking an unrelated question in an existing one. Opening a new ticket keeps the forum tidy, and makes it easier to navigate.

    Good luck with your development!

    Best regards,
    Karl

Reply
  • Hello again,

    control said:
    I implemented Errata 212 and it seems that it works now.

    Great, I am happy to hear that it is now working as expected!

    control said:
    Please let me know if UART can use inner pull up or it is mandatory to use outer pull up. Our current configuration uses an inner pull up resistor on the Rx pin and we do not get any response. I am wondering if the problem lies in the fact that the outer pull up is not used

    The UART pins can use inner pullup, yes. You do not need external pull up resistors. To troubleshoot this issue I would use a logic analyzer to monitor the pin, to see if it is behaving as expected - I do not know what you mean when you say you are not getting any response on the RX pin, this sounds like it might be a problem in the other end of the connection ( if nothing is being sent ).

    control said:
    BTW: I do not want to open a new topic for one additional question.

    It is ok this time, but please open a new ticket in the future if you should have any additional questions that are not related to the initial ticket.
    The response time is the same for existing tickets, so there is no reason not to open a new one instead of asking an unrelated question in an existing one. Opening a new ticket keeps the forum tidy, and makes it easier to navigate.

    Good luck with your development!

    Best regards,
    Karl

Children
No Data
Related