Hi,
I am trying to read voltage values on two channels (A1, A2; i.e. Pin 4 and Pin 5), and transfer the result to the AP connected to a PC. Although I can successfully read from single channel, I am unable to do two channels.
Here is my code:
while (1) {
__bis_SR_register(LPM3_bits+GIE); // LPM3 with interrupts enabled
SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_AWAKE, 0); //get radio ready...awakens in idle state
ADC10CTL1 = INCH_2 + CONSEQ_3;
ADC10CTL0 = REF2_5V + SREF_1 + ADC10SHT_2 + REFON + ADC10ON + ADC10IE;
for (countDown = 240; countDown > 0; countDown--); //delay to allow references to settle
ADC10AE0 |= 0x06; //110
ADC10DTC1 = 0x10; // 16 conversions
while (ADC10CTL1 & BUSY); // Wait if ADC10 core is active
ADC10SA = 0x200; // Data buffer start
ADC10CTL0 |= ENC + ADC10SC; //Sampling and conversion start
__bis_SR_register(CPUOFF + GIE); // LPM0 with interrupts enabled
//read result
readPtr = (int *)0x200; //same value as ADC10SA
int ri, ii;
for (ri = 0, ii=0; ri <16; ri++) { //this loop is similar to sample temperature sensor code
incomingVoltage[ii++] = (*(readPtr + ri))&0xFF;
incomingVoltage[ii++] = ((*(readPtr + ri))>>8)&&0xFF;
}
ADC10CTL0 &= ~ENC;
ADC10CTL0 &= ~(REFON + ADC10ON); // turn off A/D to save power
rc=SMPL_SendOpt(sLinkID1, incomingVoltage, sizeof(incomingVoltage), SMPL_TXOPTION_ACKREQ))) //send message
Following are my questions:
1. Is it a good idea to do all of this in a infinite loop?
2. My understanding is: the code after the line '__bis_SR_register(CPUOFF + GIE); // LPM0 with interrupts enabled' (i.e. the result reading part) will be hit only after the conversions are done and the results are written into memory. Is that correct? I am afraid my understanding of interrupts is still shaky..
3. I do get 'peer connected' message in the console, but none of the data transfer messages. Any help in debugging this would be greatly appreciated.
Thanks!