Hello, I'm trying to interface the SEN0193 moisture sensor with the EK-TM4C1294XL launchpad. I've checked the hardware and made sure that the sensor is indeed receiving power, and it is indeed reading in data (voltage changes when I touch the moisture sensor). The problem I'm having is that it is not showing this value onto the screen. I tried following an example of setting up the ADC pin, but I guess I'm doing it wrong somehow. Here is the code where I'm configuring the ADC:
// // Enable the peripherals to be used. // MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); // // Delay 6 clock cycles. // MAP_SysCtlDelay(2); // // Configure PE3 as analog. // MAP_GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3); // // Configure sample sequencer 3. // MAP_ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0); // // Configure step 0 on sequence 3. Sample channel 0 (ADC_CTL_CH0) in // single-ended mode (default) and configure the interrupt flag // (ADC_CTL_IE) to be set when the sample is done. Tell the ADC logic // that this is the last conversion on sequence 3 (ADC_CTL_END). Sequence // 3 has only one programmable step. Sequence 1 and 2 have 4 steps, and // sequence 0 has 8 programmable steps. Since we are only doing a single // conversion using sequence 3 we will only configure step 0. For more // information on the ADC sequences and steps, reference the datasheet. // MAP_ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END); // // Enable sample sequencer 3. // MAP_ADCSequenceEnable(ADC0_BASE, 3); // // Clear the interrupt status flag. This is done to make sure the // interrupt flag is cleared before sampling. // MAP_ADCIntClear(ADC0_BASE, 3);
And here is where I'm reading the data from the buffer:
uint32_t AIN0Buffer[1] = {}; const uint32_t AirValue = 520; const uint32_t WaterValue = 260; uint32_t intervals = (AirValue - WaterValue) / 3; // // Read the analog voltage measurement. // MAP_ADCSequenceDataGet(ADC0_BASE, 3, AIN0Buffer); // // Display messages based on the AIN0 analog value. // if(AIN0Buffer[0] > WaterValue && AIN0Buffer[0] < (WaterValue + intervals)) { UARTprintf("AIN0 = %u | Very Wet\n", AIN0Buffer[0]); } else if(AIN0Buffer[0] > (WaterValue + intervals) && AIN0Buffer[0] < (AirValue - intervals)) { UARTprintf("AIN0 = %u | Wet\n", AIN0Buffer[0]); } else if(AIN0Buffer[0] < AirValue && AIN0Buffer[0] > (AirValue - intervals)) { UARTprintf("AIN0 = %u | Dry\n", AIN0Buffer[0]); } UARTprintf("**** this ****, %u\n", AIN0Buffer[0]);
As you can guess, the code runs straight through the if conditions and get to the last printf, which prints out the subtle message and the value of 0 for the buffer.