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.

MSP430FR5949: UART did not receive data properly

Part Number: MSP430FR5949

Hi,

I am using UART protocol as command and response manner. So, whenever  the controller receives the command then only it responses. Earlier this function of protocol is okay with following configuration: Baud_Rate : 9600, Bits: 8, Stop_bit:1, Parity:None.

Now I am trying the same thing with Baud_rate:115200, Bits: 8, Stop_bit:1, Parity:None. But The UART receive buffer is not getting the command bytes properly on its first trial. In the first trial I got 0xff in UART receive buffer. When the command hitting the receive buffer on it's second time then only it receives the command bytes. 

I have no idea about this behaviour of UART receiver. So please help me to find the solution.

  • Hi Siv,

    This is most likely an issue caused by different baud rates. You need to make sure both the controller and receiver have the same baud rate; if you only changed one to 115200 you will not get the correct data in the buffer.

    Best,
    Amruta 

  • Yes, both transmitter and receiver are kept in same baud_rate only. Here my problem is that I can receive data in controller at the second attempt of the command. In the first attempt controller RXBUF is filled by 0xff. 

  • I would check it with a scope. A glitch on the line that mimics a start-bit will cause this.

  • Okay then how to overcome this error? Can you please explain which factor cause this type of problem and please help me to solve this.

  • Since it is on the receive side it is coming from whatever is sending the data.

  • Have you looked at it with a scope? When you do, what are you seeing?

  • Yes I do. I saw the data whatever sent by the transmitter at the receiver end/ RX pin of the controller. But in debug mode the RXBUF of controller filled with 0xff or some garbage characters. I couldn't figured out what functionality is missing in UART configuration. 

  • Are you using an interrupt?

    Can you share your code?

  • Yes I am using ISR for UART. Here I share my code. Please find the attachment.

    uint8_t uart_initialize(void)
    {
        P3DIR = 0x01;
        P2SEL1 = 0x03;
        UCA0CTLW0 = 0x0081;
    //    UCA0BRW =  104;                                                              /* 16MHz / 9600 Baud_rate set */
    //    UCA0MCTLW = 0xD621;
        UCA0BRW =  0x0008;                                                              /* 16MHz / 115200 Baud_rate set */
        UCA0MCTLW = 0xF7A1;
        UCA0CTLW0 = 0x0080;
        UCA0IE = 0x0001;
        return 1;
    }
    
    /*
     * This function used to transmit the data Through UART
     */
    uint8_t tx_dat(uint8_t dat)
    {
        while(!(UCA0IFG & UCTXIFG));
        UCA0TXBUF = dat;
    
        return 1;
    }
    
    /*
     * This function used to receive the data Through UART
     */
    uint8_t rx_dat()
    {
        uint8_t rx_data = 0U;
        while(!(UCA0IFG & UCRXIFG));
        rx_data = UCA0RXBUF;
        return (rx_data);
    }
    
    /*
     * This function used as UART Interrupt calling function
     */
    uint8_t uart_interrupt1(void)
    {
        uint8_t dat_buf[250] = {0};
        volatile uint8_t rxd_data1;
        uint16_t  looper_151;
    
        for(looper_151 = 0U; looper_151 < 245; looper_151++)
        {
            rxd_data1 = rx_dat();
            if(rxd_data1 != (uint8_t)'!')
            {
                rxd_data1 &= 0xFF;
                dat_buf[looper_151] = rxd_data1;
            }
            else
            {
                looper_151 = 245U;
            }
        }
        (void)commands(dat_buf);
        return 1;
    }
    
    /*
     * UART Interrupt Service routine
     */
    #pragma vector = USCI_A0_VECTOR
    __interrupt void UART_A0_ISR(void)
    {
        (void)uart_interrupt1();
    }
    

  • You should only read one byte at a time in the interrupt, return, and wait for the next one. Check out the UART examples in Resource Explorer.

    Remember Herbert Hawkins rules for interrupts:

    Hubert Hawkins: I'd like to get in, get on with it, get it over with, and get out. Get it?

    Ravenhurst: Got it.

    Hubert Hawkins: Good.

     -Hubert Hawkins’ first rule of interrupts. Danny Kaye in The Court Jester

  • Yes, take it out of the loop and just read every time the interrupt occurs.

**Attention** This is a public forum