@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
}
非常感谢,
梅加