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++;
}