This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Temperature+Simple communication



Hi Nerds,

Got accelerometer and Light sensor integrated with Simple communication, and it works fine. Temperature sensor fails with simple communication - it transmits 2 correct temp readings and then stops. I believe it has to do with the timer, and played around tweaking it, but couldnt hunt it down.

Trying with Temperature + Basic Comms AFZDO, so that I can expand it to simple communication.

Anybody done with that, pls let me know. Basic code snippet I tried posted below:

main(){

 afzdo end device blah blah.....

waitForDeviceState(DEV_END_DEVICE);          //commented for debugging endDevice

 ADC10CTL1 = INCH_10 + ADC10DIV_3;         // 1010 Temperature sensor+ADC10 clock divider;Temp Sensor ADC10CLK/4
 ADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON + ADC10IE;
 TACCR0 = 30;                              // Delay to allow Ref to settle: capture/compare blocks
 TACCTL0 |= CCIE;                         
 TACTL = TASSEL_2 + MC_1;                 
 __bis_SR_register(CPUOFF + GIE);          // LPM0, TA0_ISR will force exit #define CPUOFF (0x0010) #define GIE (0x0008)
 TACCTL0 &= ~CCIE;                         // Disable timer Interrupt

 timerResult = initTimer(4, WAKEUP_AFTER_TIMER);   //Timer dealt above and here also, not required probably

    while (1)//hal_cc2530znp_target_board.c>>469
    {
        //setLed(1);
        printf("Sending Message %u\r\n", counter++);
        temperature_log(&testMessage);
        toggleLed(1);//testMessage[1]=0;testMessage[2]=0;testMessage[3]=0;
        testMessage[0]=counter;testMessage[4]=0;
        afSendData(DEFAULT_ENDPOINT,DEFAULT_ENDPOINT,0, TEST_CLUSTER, testMessage, 5);
        handleReturnValue();
        clearLeds();
        //HAL_SLEEP();  //#define HAL_SLEEP() ( __bis_SR_register(LPM3_bits + GIE))
    }

}

temperature_log(unsigned char * testMessage){
 /* temperature logging */
 ADC10CTL0 |= ENC + ADC10SC;             // ADC10 enabled+Sampling and conversion start
 __bis_SR_register(CPUOFF + GIE);        // LPM0 with interrupts enabled

 // oF = ((A10/1024)*1500mV)-923mV)*1/1.97mV = A10*761/1024 - 468
 temp = ADC10MEM;*(testMessage+1)=temp;
 IntDegF = ((temp - 630) * 761) / 1024;*(testMessage+2)=IntDegF;

 // oC = ((A10/1024)*1500mV)-986mV)*1/3.55mV = A10*423/1024 - 278
 temp = ADC10MEM;
 IntDegC = ((temp - 673) * 423) / 1024;*(testMessage+3)=IntDegC;

 //printf("\r\n Temperatures\r\n");printf("%02d ", temp);printf("%02d ", IntDegF);printf("%02d ", IntDegC);

 // *testMessage=temp;*(testMessage+1)=IntDegF;*(testMessage+2)=IntDegC;
 __no_operation();                       // SET BREAKPOINT HERE
}

#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A (void)
{
    timerIsr();                             //timerIsr = &handleTimer;
    TACTL = 0;                                                       //tried commenting
    __bic_SR_register_on_exit(CPUOFF);     //tried commenting

    if (wakeupFlags & WAKEUP_AFTER_TIMER) 
    {
        HAL_WAKEUP();
    }
}


#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR(void)
{
  __bic_SR_register_on_exit(CPUOFF);        // Clear CPUOFF bit from 0(SR)
}

void handleTimer()  //Will automatically wakeup timer
{
    printf("#");
}

End device sends values twice which coordinator receives, and then stops. I tweaked further, the end device does read the temperature values continuously (instead of just twice using just the end device as stand alone by commenting waitForDeviceState(DEV_END_DEVICE); ), but when I hook the end device along with coordinator,I get this:

waitForMessage Unexpected Message: L22, messageType = 4481
IEEE Request Failed (-31)

I understand that error comes from waitForMessage but how do I solve this entire thing.

.  Where is the issue, any ideas?

-Sree