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.

UART To receive Multibyte is not working.

Other Parts Discussed in Thread: MSP430G2553

Hello I'm working on a bluetooth to MCU interface project to receive a stream of bytes and act accordingly  ( like switching on a Relay or so on ) on a msp-exp430g2 with a msp430g2553 ic.

I'm able to receive buff_rxTemp[1],buff_rxTemp[2] but all other values are junk.Other thing that I noticed is that buff_rxCnt jumps to 52 quite consistently from 2 and never counts to 3 to 52.Therefore values between 3 and 52 are always '\0'.

Is there any problem with my code.

#include <msp430.h> 

/*
 * main.c
 */

unsigned char buff_rxTemp[];
unsigned char buff_rx[];
unsigned int buff_rxCnt=0;
unsigned int i;

int main(void) {
    WDTCTL = WDTPW | WDTHOLD;	// Stop watchdog timer

    P1DIR |=BIT6;
    P1OUT &=BIT6;
    P1DIR |=BIT0;
    P1OUT &=BIT0;

    DCOCTL = 0; // Select lowest DCOx and MODx settings<
    BCSCTL1 = CALBC1_1MHZ; // Set DCO
    DCOCTL = CALDCO_1MHZ;

    P1SEL= 		BIT1 + BIT2	;
    P1SEL2= 	BIT1 +BIT2;
    UCA0CTL1|=  UCSSEL_2;
    UCA0BR0=	104;
    UCA0BR1=	0;
    UCA0MCTL= 	UCBRF_0 + UCBRS_1 ;
    UCA0CTL1&=	~UCSWRST;
    IE2|= 		UCA0RXIE;

    __bis_SR_register(CPUOFF + GIE); // Enter LPM0 w/ int until Byte RXed


    while(1){

    }

}
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)	{
		buff_rxTemp[i]= UCA0RXBUF;
		i++;
}

 

  • Bharath,

    you should make the arrays fixed size ones:

    unsigned char buff_rxTemp[];

    Use the largest number of bytes you expect, for example:

    unsigned char buff_rxTemp[100];

    Dennis

  • I don't see you initializing i. And buf_rxCnt is never used.
    buff_rx and buff_rxTem have an unspecified size (didn't teh compiler throw a warning?). So they do not allocate space on memory. It's possible that buff_rxTemp[2] points to the location of i (index out of bounds), altering it with the just received byte.

**Attention** This is a public forum