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

how to configure several saadc channels of nRF 52810

Hi,

 I need to use 6 saadc channels to sample voltage on my project. The saadc channel 0 could be configured to connect different inputs(ANI0~AIN7).But I try to configue other saadc channel,it doesn't work.I have no idea for that.There is my code and the result of saadc register below.

Parents
  • Pretty sure that the SAADC example in the SDK uses 3 channels ... ?

    How to properly post source code:

  •         uint32_t ba_err_code;
    			 int16_t batteryTemp[4] = { 0 };
    			 int32_t batteryLevel = 0;
    			 uint8_t checkStatus = 0;
    			 uint8_t batterPercentTemp;
    			
    			 //InitAdcChannel( ADC_CHANNEL_SIX, LOW_TEMPERATURE );
    			 nrf_saadc_channel_config_t channel_config = 
           ADC_DEFAULT_CHANNEL_CONFIG_SE( NRF_SAADC_INPUT_AIN0 );
    			 
    			 nrf_saadc_channel_config_t channel_config1 = 
           ADC_DEFAULT_CHANNEL_CONFIG_SE( NRF_SAADC_INPUT_AIN1 );
    			 
    			 ba_err_code = nrf_drv_saadc_channel_init( 0, &channel_config );
    			 APP_ERROR_CHECK(ba_err_code);
    				
    			 ba_err_code = nrf_drv_saadc_channel_init( 1, &channel_config1 );
    				APP_ERROR_CHECK(ba_err_code);
    			 
    			 __ASM volatile ("nop");
    			 __ASM volatile ("nop");
    			 __ASM volatile ("nop");
    			 __ASM volatile ("nop");
    			 __ASM volatile ("nop");
    			 __ASM volatile ("nop");
    			 
    			 ba_err_code = nrfx_saadc_sample_convert( 0, batteryTemp );
    			 if( ba_err_code == NRFX_SUCCESS )
    				{
    					 ba_err_code = nrfx_saadc_sample_convert( 0, batteryTemp );
    					 if( ba_err_code == NRFX_SUCCESS )
    						{
    							 batteryTemp[0] >>= ADC_BATTERY_SHIFT_BIT;
    							 batteryLevel += batteryTemp[0];
    							 ba_err_code = nrfx_saadc_sample_convert( 1, batteryTemp );
    							 if( ba_err_code == NRFX_SUCCESS )
    								{
    									 batteryTemp[0] >>= ADC_BATTERY_SHIFT_BIT;
    									 batteryLevel += batteryTemp[0];
    								}
    							 else
    								{
    									 checkStatus = 1;
    								}
    						}
    					 else
    						{
    							checkStatus = 1;
    						}
    				}
    			 else
    				{
    					 checkStatus = 1;
    				}

Reply
  •         uint32_t ba_err_code;
    			 int16_t batteryTemp[4] = { 0 };
    			 int32_t batteryLevel = 0;
    			 uint8_t checkStatus = 0;
    			 uint8_t batterPercentTemp;
    			
    			 //InitAdcChannel( ADC_CHANNEL_SIX, LOW_TEMPERATURE );
    			 nrf_saadc_channel_config_t channel_config = 
           ADC_DEFAULT_CHANNEL_CONFIG_SE( NRF_SAADC_INPUT_AIN0 );
    			 
    			 nrf_saadc_channel_config_t channel_config1 = 
           ADC_DEFAULT_CHANNEL_CONFIG_SE( NRF_SAADC_INPUT_AIN1 );
    			 
    			 ba_err_code = nrf_drv_saadc_channel_init( 0, &channel_config );
    			 APP_ERROR_CHECK(ba_err_code);
    				
    			 ba_err_code = nrf_drv_saadc_channel_init( 1, &channel_config1 );
    				APP_ERROR_CHECK(ba_err_code);
    			 
    			 __ASM volatile ("nop");
    			 __ASM volatile ("nop");
    			 __ASM volatile ("nop");
    			 __ASM volatile ("nop");
    			 __ASM volatile ("nop");
    			 __ASM volatile ("nop");
    			 
    			 ba_err_code = nrfx_saadc_sample_convert( 0, batteryTemp );
    			 if( ba_err_code == NRFX_SUCCESS )
    				{
    					 ba_err_code = nrfx_saadc_sample_convert( 0, batteryTemp );
    					 if( ba_err_code == NRFX_SUCCESS )
    						{
    							 batteryTemp[0] >>= ADC_BATTERY_SHIFT_BIT;
    							 batteryLevel += batteryTemp[0];
    							 ba_err_code = nrfx_saadc_sample_convert( 1, batteryTemp );
    							 if( ba_err_code == NRFX_SUCCESS )
    								{
    									 batteryTemp[0] >>= ADC_BATTERY_SHIFT_BIT;
    									 batteryLevel += batteryTemp[0];
    								}
    							 else
    								{
    									 checkStatus = 1;
    								}
    						}
    					 else
    						{
    							checkStatus = 1;
    						}
    				}
    			 else
    				{
    					 checkStatus = 1;
    				}

Children
No Data
Related