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.

LPM mode

I am trying to port the code to low power mode (my initial goal was to make my code work). I wanted to know if I am doing it right, or I still need to change the code, so it consumes as little power as possible. I am using ACLK clock. Please advice, if I could do any thing, so the code uses minimum power.

#include "mrfi.h"
#include "radios/family1/mrfi_spi.h"
#include "drivers/timer/timer.h"
#define TURT_ID 2
#define POLYNOMIAL 0xD8;
#define WIDTH 8
#define TOPBIT (1 << (WIDTH - 1))

volatile int radioReady = 1;
int8_t rssi;
unsigned int i = 0;
volatile uint32_t globaltimer = 0;

unsigned char seconds = 0;
char count[7];

void initializeRandomTimer(){
//unsigned int rand;
//rand = TI_getRandomIntegerFromVLO();
BCSCTL3 |= LFXT1S_2;
TACCTL0 = CCIE;
TACCR0= 3933 ; //goes for 3+random seconds
TACTL = MC_1 | TASSEL_1 | ID_3;

}

uint8_t getCRC(mrfiPacket_t *packet, char size){

uint8_t remainder= 0;
uint8_t i = 0;
 for(i =0; i < size; ++i)
 {
          remainder = remainder ^ (packet->frame[i] << (WIDTH - 8));

          uint8_t bit = 0;
          for(bit = 8; bit > 0; --bit)
          {
             if(remainder & TOPBIT)
             {
                remainder = (remainder << 1) ^ POLYNOMIAL;
             }
             else
             { 
                 remainder = (remainder << 1);
             }

         }
 }

 return remainder;

}


int main(void)
{

   P3SEL = 0x30;
   BSP_Init();
   MRFI_Init();
   P3SEL |= 0x30;
   UCA0CTL1 = UCSSEL_2;
   UCA0BR0 = 0x41;
   UCA0BR1 = 0x3;
   UCA0MCTL = UCBRS_2;
   UCA0CTL1 &= ~UCSWRST;
   IE2 |= UCA0RXIE;

   mrfiSpiWriteReg(PATABLE, 0xFF);
   MRFI_WakeUp();
   MRFI_RxOn();
   initializeRandomTimer();
   //initializeTimerB();
   __bis_SR_register(LPM3_bits + GIE);


   for(;;){

        __bis_SR_register(LPM1_bits);
        if(radioReady==1){
                  mrfiPacket_t packet;
                  packet.frame[0]=8+20;
                  packet.frame[1]=rssi;
                  packet.frame[2]=TURT_ID;
                  packet.frame[3] = globaltimer >> 16; //Timer 1 byte
                  packet.frame[4] = (globaltimer >> 8) & 0xFF; //Timer 2 byte
                  packet.frame[5] = globaltimer & 0xFF; //Timer 3 byte
                                                packet.frame[6] = getCRC(&packet, 6); //CRC
                  MRFI_Transmit(&packet, MRFI_TX_TYPE_FORCED);
                  P1OUT^=0x01;
                  radioReady=0;
                }
         }
   }


void MRFI_RxCompleteISR()
 {
           rssi=MRFI_Rssi();
           mrfiPacket_t packet;
           MRFI_Receive(&packet);
           count[0] = packet.frame[0];
           count[1] = packet.frame[1];
           count[2] = packet.frame[2];
           count[3] = packet.frame[3];
           count[4] = packet.frame[4];
           count[5] = packet.frame[5];
           count[6] = packet.frame[6]; 
           TXString(count,7);
           char arr[1];
           arr[0] = getCRC(&packet, 6);
           TXString(arr, 1);
           if(packet.frame[6] == getCRC(&packet, 6)) P1OUT ^= 0x02;
}
// Timer A0 interrupt service routine
interrupt(TIMERA0_VECTOR) Timer_A (void)
{

           radioReady=1;
           if(++i>=20){
                globaltimer++;
                i=0;
           }
           __bic_SR_register_on_exit(LPM3_bits);
}