Please check the ADC example which is located under projects\target_apps\peripheral_examples\adc\batt_lvl SDK path and you will find all the appropriate steps for the usage of the ADC.
In order to read an ADC value for a GPIO, you should reserve and configure the GPIO as PID_ADC. For example:
In GPIO_reservation(): RESERVE_GPIO( ADC, ADC_PORT, ADC_PIN, PID_ADC);
In set_pad_function(): GPIO_ConfigurePin( ADC_PORT, ADC_PIN, INPUT, PID_ADC, false);
Be aware that you could use specific GPIO as an ADC. Please check Table 1: Pin Description of the DA14585 datasheet and search the “Analog Interface” section. After that, you should use the appropriate APIs from the ADC library, but we don’t have any available example on this.
The ADC example of the SDK gets sample from VBAT1V or VBAT3V power supplies using the 20 usec delay. Please check the adc_get_vbat_sample() :
如果sample_vbat1v= TRUE, then the adc_enable_channel(ADC_CHANNEL_VBAT1V)
如果sample_vbat1v= FALSE, then the adc_enable_channel(ADC_CHANNEL_VBAT3V)
This means that according the sample_vbat1v, the ADC is configured to gets samples either from VBAT1V or VBAT3V. Both ADC_CHANNEL_VBAT1V and ADC_CHANNEL_VBAT3V are defined into adc.h header file. Suppose that you would like to get samples from Pin_00, so you have to enable it first. A sample code for that is the following:
嗨Jasu,
Please check the ADC example which is located under projects\target_apps\peripheral_examples\adc\batt_lvl SDK path and you will find all the appropriate steps for the usage of the ADC.
Thanks, PM_Dialog
YES I LOOKED AT THAT EXAMPLE BUT THAT DOESN'T READ ANY VALUE FROM GPIO
嗨Jasu,
In order to read an ADC value for a GPIO, you should reserve and configure the GPIO as PID_ADC. For example:
Be aware that you could use specific GPIO as an ADC. Please check Table 1: Pin Description of the DA14585 datasheet and search the “Analog Interface” section. After that, you should use the appropriate APIs from the ADC library, but we don’t have any available example on this.
Thanks, PM_Dialog
i reserved and configure the GPIO .but i cannot understand how to read adc value from gpio(adc) pin!!
嗨Jasu,
The ADC example of the SDK gets sample from VBAT1V or VBAT3V power supplies using the 20 usec delay. Please check the adc_get_vbat_sample() :
This means that according the sample_vbat1v, the ADC is configured to gets samples either from VBAT1V or VBAT3V. Both ADC_CHANNEL_VBAT1V and ADC_CHANNEL_VBAT3V are defined into adc.h header file. Suppose that you would like to get samples from Pin_00, so you have to enable it first. A sample code for that is the following:
adc_calibrate();
adc_init(GP_ADC_SE,GP_ADC_SIGN,0);
adc_usDelay(20);
adc_enable_channel(ADC_CHANNEL_P00);
adc_value = adc_get_sample();
Thanks, PM_Dialog