greetings !
i am new to the world of micro controllers and programming, and am using the eZ430R-F2500 development kit. after reading the necessary documents, and the related posts on this forum, lots of things are still not that much clear to me, specially the registers that i wrote in red text. that's why am making a new post.
i want to connect two external sensors to the target board, soil moisture (seeedstudio.com/wiki/Grove_-_Moisture_Sensor) and a humidity+temperature sensor (DTH22, adafruit.com/products/385). each sensor will be connected to an externally 5V battery. the ADC10 code is below. i still have to configure the equations for humidity and moisture at the end of this code.
while (1)
{
volatile long temp;
int degC, volt;
int humidity;
int moisture;
int results[3];
SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_SLEEP, "" );
__bis_SR_register(LPM3_bits+GIE); // LPM3 with interrupts enabled
SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_AWAKE, "" );
BSP_TOGGLE_LED2();
/* integrated temperature sensor*/
ADC10CTL1 = INCH_10 + ADC10DIV_4; // Temp Sensor ADC10CLK/5
ADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON + ADC10IE + ADC10SR;
for( degC = 240; degC > 0; degC-- ); // delay to allow reference to settle
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
__bis_SR_register(CPUOFF + GIE); // LPM0 with interrupts enabled
results[0] = ADC10MEM;
ADC10CTL0 &= ~ENC;
/*external sensors humidity and moisture*/
P2SEL = 0x03; // peripheral mode
P2DIR = 0xFC;
P2OUT = 0x00;
ADC10AE0 = 0x03; //A0/A1 analog input enabled
ADC10DTC0 = ADC10CT; // continuous transfer
ADC10DTC1 = 0x02;
ADC10SA = 0x200;
ADC10CTL1 = CONSEQ_3 + ADC10SSEL_0 + ADC10DIV_4 + SHS_0 + INCH_1; // soil moisture/humdity sensor, Repeat sequence of channels
ADC10CTL0 = ADC10IE + ADC10ON + REFON + ADC10SR + MSC + ADC10SHT_3 + SREF_1; //multiple sample and conversion
__delay_cycles(240);
ADC10CTL0 |= ENC + ADC10SC;
__bis_SR_register(CPUOFF + GIE); // LPM0 with interrupts enabled
results[1] = ADC10MEM;
ADC10CTL0 &= ~ENC;
/*voltage*/
ADC10CTL1 = INCH_11; // AVcc/2
ADC10CTL0 = SREF_1 + ADC10SHT_2 + REFON + ADC10ON + ADC10IE + REF2_5V;
for( degC = 240; degC > 0; degC-- ); // delay to allow reference to settle
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
__bis_SR_register(CPUOFF + GIE); // LPM0 with interrupts enabled
results[2] = ADC10MEM;
ADC10CTL0 &= ~ENC;
ADC10CTL0 &= ~(REFON + ADC10ON); // turn off A/D to save power
// oC = ((A10/1024)*1500mV)-986mV)*1/3.55mV = A10*423/1024 - 278
// the temperature is transmitted as an integer where 32.1 = 321
// hence 4230 instead of 423
temp = results[0];
degC = ((temp - 673) * 4230) / 1024;
if( tempOffset != 0xFFFF )
{
degC += tempOffset;
}
/*message format, UB = upper Byte, LB = lower Byte
-------------------------------
|degC LB | degC UB | volt LB |
-------------------------------
0 1 2
*/
temp = results[2];
volt = (temp*25)/512;
msg[0] = degC&0xFF;
msg[1] = (degC>>8)&0xFF;
msg[2] = volt;
msg[3] = humidity;
msg[4] = moisture;
am i right so far with the code. can anyone help to correct me ?
thanks alot
Tahir Khan