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.

msp430 uart drops byte on transmitting

Other Parts Discussed in Thread: MSP430F5438A

Hi all,
I will appritiate your help in configuring uart.
My MSP is MSP430f5438a
I am currently developing onthe  MSP-EXP430F5438 Experimenter Board.
I am trying to configure MCu to use the board's oscilator running at 20mhz
My problem is that te uart sometimes drops few bytes.

Here is a snippet of the code

Thank you for your help...

 

#define CLOCK_FREQ_MHZ              20000000
#define CLOCK_FREQ_KHZ              (CLOCK_FREQ_MHZ / 1000)
#define RATIO                       (CLOCK_FREQ_MHZ / 32768)  //20000000/32768 = 610.351 (20Mhz/32khz)

void main(void)
{
    //FLL init to 20Mhz
    PDOUT  = 0;
    PDDIR  = 0xFFFF;
    PDSEL  = BIT0 + BIT1;
    LFXT_Start(XT1DRIVE_0);
    Init_FLL_Settle(CLOCK_FREQ_KHZ, RATIO);
 
    uart_data_init();
 
    whlie(1)
    {
        uart_data_write(); //writing to uart
        //sleep enough time to prevent cyclic buffer from being overrun
    }
}

void uart_data_init()
{
    P3SEL |= BIT4 + BIT5; // P3.4,5 = USCI_A0 TXD/RXD
    UCA0CTL1 |= UCSWRST; // **Put state machine in reset**
    UCA0CTL1 |= UCSSEL_2; // SMCLK

    UCA0BR0 = 130;  // 20MHz 9600
    UCA0BR1 = 0;   // 20MHz 9600

    UCA0MCTL = UCBRS_0 + UCBRF_3 + UCOS16; // Modln UCBRSx=0, UCBRFx=3, over sampling

    UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
    UCA0IE = UCRXIE; //enable Receive interrupt
}

int uart_data_write(byte *pdata, int data_len)
{
    //disable Tx interrupts
    UCA0IE &= ~UCTXIE;

 //Add data to cyclic buffer

    //enable Tx interrupts. when tx interrupts are enabled isr is invoked which causes
    //to write to uart the data we stored in the cyclic buffer
    UCA0IFG |= UCTXIFG;
    UCA0IE |= UCTXIE;

    return ret_val;
}

#pragma vector=USCI_A0_VECTOR
__interrupt void USCI_A0_ISR(void)
{
    switch (__even_in_range(UCA0IV, 4))
    {
    case 0:
        break;                          // Vector 0 - no interrupt
    case 2:                             // Vector 2 - RXIFG
  //Read from cyclic buffer
        break;
    case 4:                             // Vector 4 - TXIFG
        if ( g_tx_cyclic_start == g_tx_cyclic_end)
        {//buffer empty. there is nothing to send
            return;
        }

  //send to uart
        UCA0TXBUF = g_tx_cyclic_buff[g_tx_cyclic_end];
        g_tx_cyclic_end = ( g_tx_cyclic_end + 1 ) % CYCLIC_BUFF_SIZE;
        break;
    default:
        break;
    }
}

**Attention** This is a public forum