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 of MSP430F6779 RX is not working properly

Other Parts Discussed in Thread: MSP430F6779

Hello All,

I am evaluating my UART communication with MSP430F6779 device, which is mounted on customized board. I am currently can send the data on its UCA0TXBUF to send it to end device, but I am unable to Rx data continuously. I am expecting my device to receive continuous data over longer time.

Following are the Code which I have developed. Kindly go through it.

#include <msp430.h>
#include <string.h>

unsigned char uartrcv(unsigned char x,int y);
unsigned char b,v,w;
unsigned char rx[40];
int i,c,t;

void main(void)


{
    WDTCTL = WDTPW | WDTHOLD;               // Stop WDT



// Setup P3.0 UCA0RXD, P3.1 UCA0TXD
    P3SEL0 |= BIT0 | BIT1;                  // Set P3.0, P3.1 to non-IO

    P3DIR |= BIT0 | BIT1;                   // Enable UCA0RXD, UCA0TXD



// Setup LFXT1

    UCSCTL6 &= ~(XT1OFF);                   // XT1 On

    UCSCTL6 |= XCAP_3;                      // Internal load cap


// Loop until XT1 fault flag is cleared

/*
do
    {
        UCSCTL6 &= ~(XT2OFFG | XT1LFOFFG | DCOFFG);
        // Clear XT2,XT1,DCO fault flags

        SFRIFG1 &= ~OFIFG;                  // Clear fault flags

    }

while (SFRIFG1 & OFIFG);              // Test oscillator fault flag


*/

// Setup eUSCI_A0


UCA0CTLW0 |= UCSWRST;                   // **Put state machine in reset**

UCA0CTLW0 |= UCSSEL_1;                  // CLK = ACLK

UCA0BRW_L = 0x03;                       // 32kHz/9600=3.41 (see User's Guide)

UCA0BRW_H = 0x00;                       //

UCA0MCTLW = 0x5300;                     // Modulation UCBRSx=0x53, UCBRFx=0

UCA0CTLW0 &= ~UCSWRST;                  // **Initialize USCI state machine**

UCA0IE |= UCTXIE|UCRXIE;                       // Enable USCI_A0 RX interrupt



__bis_SR_register(GIE);
// Enter LPM3, interrupts enabled


__no_operation();                       // For debugger
}



// USCI_A0 interrupt service routine


#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)

#pragma vector=USCI_A0_VECTOR
__interrupt
void USCI_A0_ISR(void)

#elif defined(__GNUC__)


void __attribute__ ((interrupt(USCI_A0_VECTOR))) USCI_A0_ISR (void)

#else

#error Compiler not supported!


#endif
{
    switch (__even_in_range(UCA0IV, 4))

        {

            case USCI_NONE:
            break;              // No interrupt


            case USCI_UART_UCRXIFG:             // RXIFG
                   uartrcv(b,c);
                   break;


            case USCI_UART_UCTXIFG:
                    break;      // TXIFG


            case USCI_UART_UCSTTIFG:
            break;     // TTIFG


            case USCI_UART_UCTXCPTIFG:
            break;   // TXCPTIFG


            default: break;

        }

}

unsigned char uartrcv(unsigned char x,int y)
{
int t=0;

//while (!(UCRXIFG));
    //{

        for (t=0;t<8;t++)
        {
            __delay_cycles(2000000);
            rx[t]= UCA0RXBUF;
        }


        //}
return(0);
}

In short, TX section is working with delay of 10000 count. But for the same delay_count i am unable to receive data, even i have increased the delay so that controller can read the data.

If anyone can resolve this issue?

Thank you.

  • You must read RXBUF only when a byte is available, i.e., when RXIFG is set. Waiting any amount of time does not guarantee that data is actually available.

    You can check RXIFG either by polling, or by using an interrupt handler, but not with both at the same time (one would reset the flag before the other one would be able to act on it).

    The example programs (both for the F6779, and for driverlib) show how this is done correctlyl.

  • Thank you, Clemens.

    But, when I studied in user guide for MSP430F6779, I came across line that described RXIFG is reset automatically when RXBUF is read. So, whenever i rx any data, it is pushed in buffer and that buffer is read by any variable.

    Now, in this code, I am trying to push the data in rx[] array bytewise, while checking RXIFG. But, instead it shows only last byte received.

    So, is there a problem in looping or delay issue? Can you help me out?
  • You are never checking RXIFG (not even implicitly with an interrupt handler). So when you read RXBUF, you don't know if you have a new byte or not, or if there were several new bytes (which are lost).

**Attention** This is a public forum