外部传感器与MSP430连接

时间:2013-11-01 09:03:26

标签: msp430 zigbee

@Gurus,我已经在P2_2引脚(Kit 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

}

非常感谢,

MEGHA

1 个答案:

答案 0 :(得分: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