Hi,
I am using ADC Channel AIN4 for reading Grove Moisture sensor input. Please let me know whether I have done the coding correctly.
#define MOISTURE_SENSOR_ADC_CHANNEL_NUM HAL_ADC_CHN_AIN4
void MoistureSensorSetup(void)
{
//Configure the digital port pin for reading the sensor data
P0SEL |= (0x01 << MOISTURE_SENSOR_ADC_CHANNEL_NUM);
P0INP &= ~(0x01 << MOISTURE_SENSOR_ADC_CHANNEL_NUM);
P0DIR &= ~(0x01 << MOISTURE_SENSOR_ADC_CHANNEL_NUM);
APCFG |= (0x01 << MOISTURE_SENSOR_ADC_CHANNEL_NUM);
AdcChannelNumber = MOISTURE_SENSOR_ADC_CHANNEL_NUM;
HalAdcSetReference(HAL_ADC_REF_AVDD);
}
uint16 ReadMoistureSensorAnalogInput(void)
{
uint16 moistureValue; //Variable to store the value coming from the sensor
moistureValue = HalAdcRead(AdcChannelNumber, HAL_ADC_RESOLUTION_10);
return moistureValue;
}
AVDD5 is connected to 3.3V.
I am seeing only o voltage on the sensor input pin. I provided 4.7V to Grove Moisture Sensor.
Please let me know my source code is correct or any other changes I have to do.
Thanks