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.

Xbee & MSP430F2272 Choose Baud Rate Parameters

Other Parts Discussed in Thread: MSP430F2272

Hello,

 

I am interfacing a Xbee module with the UART RX of the MSP430F2272. I am receiving the API Frame of 14 bytes properly for some time. But after a little while, the UART of MSP430 gets out of sync with the Xbee and I am reading other parts of the packet instead of byte 11 and 12 where the data is stored constantly. I tried Oversampling, increasing the clock speed from 1MHz to 8MHz, but not much difference (un-synchronization still occurs). Any help is much appreciated.

 

**CODE**

void main(void)
{
   WDTCTL = WDTPW + WDTHOLD;   // Stop WDT
   BCSCTL1 = CALBC1_8MHZ;      // Set DCO
   DCOCTL = CALDCO_8MHZ;
  
   P1SEL = 0x00;
   P2SEL = 0x00;
   P3SEL = 0x30;   //P3.4,5 = USCI_A0 TXD/RXD
  
   P1DIR = 0x00;   //set columns P1.0-P1.3 as inputs
   P2DIR = 0x39;   //set rows P2.3 and P2.4, P2.0 for # pressed = LED on, and P2.5 Xbee0 DI0 as outputs
   P3DIR = 0xC0;   //set rows P3.6 and P3.7 as outputs
   P4DIR = 0x10;   //set P4.6 as fancontrol: fancontrol=0 (off); fancontrol=1 (on)

   P3OUT = 0x00;   //initialize output port to ground
   P2OUT = 0x00;
  
   __delay_cycles(800000);
   lcd_init();      //get the lcd booted up
  
  
  //RX Parameters
  UCA0CTL1 |= UCSSEL_2;                     //SMCLK
  UCA0BR0 = 0x34;                           //Prescaler = 8MHz/(16 x 9600) = 52 = 0x34
  UCA0BR1 = 0x00;                             
  UCA0MCTL = 0x11;                          //UCA0MCTL = UCBRFx | UCBRSx | UCOS16
                                              //UCBRFx (1st modulation stage) = 0001b
                                            //UCBRSx (2nd modulation stage) = 000b
                                            //UCOS16 (Oversampling mode) = 1b -> Enabled
  UCA0CTL1 &= ~UCSWRST;                     //**Initialize USCI state machine**
  IE2 |= UCA0RXIE;                          //Enable USCI_A0 RX interrupt
 
  while (1) {
     __bis_SR_register(CPUOFF + GIE);       //Enter LPM0 w/ interrupt
     if (dataReady == 1) {
         displayTemp();
     }
     //inputTemp();
     numkeypressed = 0;
  }
}

// Receive RXed character
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{
 
     apiframe[j] = UCA0RXBUF;
     if (apiframe[0] == 0x7E) {
         data[j] = apiframe[j];
         if (j == 11) { 
            dh = data[j];
         }
         if (j == 12) { 
            dl = data[j];
            //dataReady = 1;
         }
     }
     if (j > sizeof apiframe - 1) {  
          dataReady = 1;
          j = 0;
          __bic_SR_register_on_exit(CPUOFF);        // Return to active mode
     }
     j++;  
}

  • It's possible that your timing is a bit off (maybe the sender, not on the MSP).

    You don't check for errors. I guess you're getting framing errors every now and then (happens when the timing is at the edge).
    In this case you'll miss the byte with the framing error and the transfer gets out of sync.

    Assuming that the packets do not come in a burst, you could try to implement a timeout. If a package is started but not finished in a given time frame, it is discarded.
    Just waiting for the 14th byte without any resyncing isn't a good approach.

    Also, I don't know whether there might be incomplete packages being received. RF transmissions are not 100% reliable. Normally I'd assume that the XBee module will discard incomplete packages by itself (and maybe cause a repeated transmission), but it depends on configuration (point-to-point or broadcast, CRC checking etc.)

     

  • I have two xbee endpoint connected to a temperature sensor and a xbee coordinator connected to pc. I have to take sensor reading and send it to the coordinator. I want to use API mode for this . I want to know how should i generate frames for sending data to coordinator and how to configure xbee for it.

**Attention** This is a public forum