0

@Gurus,我在引脚 P2_2(套件 CC2530 ZNP)上将湿度传感器与 MSP430F2274 连接,并使用以下代码读取传感器的输出电压。但这似乎不起作用。每次我得到一个不同的值,并且它偏离传感器的实际输出。我有一个单独的模块来处理时钟和计时器。该套件具有板载光和温度传感器,似乎工作得非常好。你能看看吗?

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

}

非常感谢,

梅加

4

1 回答 1

0

这是MSP430G2553的一个例子,我想我应该是一样的

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
于 2014-02-27T09:38:44.947 回答