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

Simple analog read on nrf52

Hello. How i can do a simple read an 0 -> 3 Volt (vdd) signal on Analog 0 P0.03? I try it with saadc without sucess

            int result = 0;
		
			NRF_SAADC->CH[0].CONFIG = (
						SAADC_CH_PSELN_PSELN_AnalogInput0 << SAADC_CH_CONFIG_BURST_Pos |
						SAADC_CH_CONFIG_BURST_Enabled << SAADC_CH_CONFIG_BURST_Pos |
						SAADC_CH_CONFIG_MODE_SE << SAADC_CH_CONFIG_MODE_Pos |
						SAADC_CH_CONFIG_TACQ_10us << SAADC_CH_CONFIG_TACQ_Pos |
						SAADC_CH_CONFIG_REFSEL_Internal << SAADC_CH_CONFIG_TACQ_Pos |
						SAADC_CH_CONFIG_GAIN_Gain1_5 << SAADC_CH_CONFIG_GAIN_Pos |
						SAADC_CH_CONFIG_RESN_Bypass << SAADC_CH_CONFIG_RESN_Pos |
						SAADC_CH_CONFIG_RESP_Bypass << SAADC_CH_CONFIG_RESP_Pos );

			NRF_SAADC->CH[0].PSELP = SAADC_CH_PSELP_PSELP_VDD;
			NRF_SAADC->CH[0].PSELN = SAADC_CH_PSELN_PSELN_NC;
		
			// Configure the SAADC resolution.
			NRF_SAADC->RESOLUTION = SAADC_RESOLUTION_VAL_14bit << SAADC_RESOLUTION_VAL_Pos;
			NRF_SAADC->OVERSAMPLE = SAADC_OVERSAMPLE_OVERSAMPLE_Over256x << SAADC_OVERSAMPLE_OVERSAMPLE_Pos;

			//Setup memory location
			NRF_SAADC->RESULT.PTR = (uint32_t)&result;

			// No automatic sampling, will trigger with TASKS_SAMPLE.
			NRF_SAADC->SAMPLERATE = SAADC_SAMPLERATE_MODE_Task << SAADC_SAMPLERATE_MODE_Pos;

			// Enable SAADC (would capture analog pins if they were used in CH[0].PSELP)
			NRF_SAADC->ENABLE = SAADC_ENABLE_ENABLE_Enabled << SAADC_ENABLE_ENABLE_Pos;
Parents Reply Children
No Data
Related