0

@Gurus, I have interfaced a humidity sensor with MSP430F2274 on pin P2_2 (Kit CC2530 ZNP) and using the following code to read the output voltage from the sensor. But it doesn't seem to be working. I am getting a different value each time and its way off the actual output from the sensor. I have a separate module which takes care of the clock and timers. The Kit has on-board Light and temperature sensors which seem to work perfectly fine. Could you please have a look?

getHumidity()
{
int result, volt;

ADC10CTL0 &= ~ENC;
ADC10CTL0 &= ~ADC10ON;

// P2.2 -> Humidity Sensor - A2

P2DIR &= ~0x04; 
P2SEL &= ~0x04; 
ADC10AE0 |= 0x04; // ADC Low Bit (A2)
ADC10AE1 = 0x00; 
ADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON + ADC10IE + REF2_5V;
ADC10CTL1 = INCH_2 + ADC10DIV_3; // Input Selct and Clock Div
ADC10CTL0 |= ENC + ADC10SC; // Start to sample

// __bis_SR_register(CPUOFF + GIE); // LPM0 w/ int

while(ADC10CTL1 & ADC10BUSY); 
result = ADC10MEM; // Store Result
if (result < 0) result = 0; // Correct for potential Weirdness
volt=(int)((result*2500.00)/1023.00);
ADC10AE0 = 0; // Reset Selection Bits
ADC10AE1 = 0;

ADC10CTL0 &= ~ENC;

ADC10CTL0 &= ~(REFON + ADC10ON);

return volt; // Return Result

}

Many Thanks,

Megha

megha
  • 1
  • 2
  • @Gurus, I still can't figure out why it's not working.Any help will be highly appreciated. Thanks – megha Nov 08 '13 at 11:48

1 Answers1

0

here is an example for MSP430G2553, i think i should be the same

BCSCTL1 = CALBC1_16MHZ; // Set range
DCOCTL = CALDCO_16MHZ;
BCSCTL2 &= ~(DIVS_3); // SMCLK = DCO = 16MHz

ADC10CTL1 = INCH2 + ADC10DIV_0 + CONSEQ_0 + SHS_0; 
ADC10CTL0 = SREF_0 + ADC10SHT_2 + ADC10ON + ADC10IE;
ADC10AE0 |= BIT2;

P2SEL |= BIT2; //ADC Input pin P2.2

ADC10CTL0 &= ~ENC;
while (ADC10CTL1 & BUSY);
ADC10SA = ADC10MEM;
ADC10CTL0 |= ENC + ADC10SC; // ENC = enable conversion, ADC10SC = Sampling and conversion start
Ofer Orgal
  • 192
  • 9