嗨
im trying to read a voltage output from a voltage devider ( 3v to be precise), and i managed to understand some parts about the adc reading
using the sdk 6.0.14 i wrote this code based on the batt example in the peripheral examples
/ /在periph_setup.h
#define ADC_PORT GPIO_PORT_0
#define ADC_PIN GPIO_PIN_1
uint32_t adc_get_voltage_sample(void);
GPIO_ConfigurePin(ADC_PORT,ADC_PIN,INPUT,PID_ADC,false); // in set_pad_functions
//in periph_setup.c
uint32_t adc_get_voltage_sample(void)
{
uint32_t adc_sample;
adc_config_t cfg =
{
.mode = ADC_INPUT_MODE_SINGLE_ENDED,
.sign = true,
.attn = true
};
adc_init(&cfg);
adc_set_se_input(ADC_INPUT_SE_P0_1);
adc_sample = adc_get_sample();
adc_disable();
return adc_sample;
};
and i called this function in the main.c trying to get the value through teraterm
printf_byte_dec(UART, adc_get_voltage_sample());
the value i get is 24-25 ... i suppose if the code is correct this value is wrong ... thank you
Hi HamzaAffes,
谢谢你的问题line. Could you please indicate what is the value that the adc_get_voltage_sample() and adc_get_sample() return?
Thanks, PM_Dialog
thank you for your response .
the value i get is always 15 which is wrong . i tried to read from other channels but still same result . i'm trying to follow the batt exemple on how to read voltage since im still a beginner . if you could clarify the appropriate functions and files to get the correct result that would be helpful.
Hi HamzaAffes,
Sure, the batt example of the SDK should be taken as reference. It seems that you are using the correct configuration. Could you please run it in debug mode and share the value of the ADC register? Additionally, you could add the adc_sample value in the watch window and check the value.
Thanks, PM_Dialog
thank you for your response,
could you pleaase help me by guiding me through this process since im still a beginner ?
Hi HamzaAffes,
Thanks, PM_Dialog