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.

MSP430F5659: Uart initialization problem

Part Number: MSP430F5659

hello,

I am using msp430f5659 and trying to interface uart. I am not able to transmit any char. My Ucs code is:

void clock()
{
     UCSCTL3 |= SELREF_2;                      // Set DCO FLL reference = REFO

          UCSCTL4 |= SELA_2;                        // Set ACLK = REFO

          __bis_SR_register(SCG0);                  // Disable the FLL control loop

          UCSCTL0 = 0x0000;                         // Set lowest possible DCOx, MODx

          UCSCTL1 = DCORSEL_4;                      // Select DCO range 8MHz operation

          UCSCTL2 = FLLD_1 + 121;                // Set DCO Multiplier for 4MHz

                                                    // (N + 1) * FLLRef = Fdco

                                                    // (121 + 1) * 32768 = 4 MHz

                                                    // Set FLL Div = fDCOCLK/2

          __bic_SR_register(SCG0);                  // Enable the FLL control loop



          // Worst-case settling time for the DCO when the DCO range bits have been

          // changed is n x 32 x 32 x f_MCLK / f_FLL_reference. See UCS chapter in 5xx

          // UG for optimization.

          // 32 x 32 x 4 MHz / 32,768 Hz = 125000 = MCLK cycles for DCO to settle

          __delay_cycles(125000);//

          // Loop until XT1,XT2 & DCO fault flag is cleared

          do

          {

            UCSCTL7 &= ~(XT2OFFG + XT1LFOFFG + DCOFFG);

                                                    // Clear XT2,XT1,DCO fault flags

            SFRIFG1 &= ~OFIFG;                      // Clear fault flags

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

and Uart init code is :

void uart(){

 P9SEL |= RXD + TXD ;                            // Assign TX AND RX FACILITY FOR P9.2 AND P9.3 respectively

    UCA2CTL1 |=UCSWRST;
    UCA2CTL1 |= UCSSEL__ACLK;                  // SELECT SMCLK 1 MHZ clock source to USCI module
    UCA2CTL0 = 0x00;                    // no parity, 8 bit mode, lsb first, UART Async mode, stop bit=1

    UCA2BR0=416;                        // presacalar value for BAUD rate generator 9600 bps
    UCA2BR1=0;
    UCA2MCTL=UCBRS_5 + UCBRF_0;                 // Modulation UCBRSx=5, UCBRFx=0
    UCA2CTL1 &=~UCSWRST;                  //initialize USCI state machine


    UCA2IE |= UCRXIE;                    // Enable USCI_A0 RX interrupt
     __bis_SR_register(GIE);             // global interrupt enable

}

I am not able to identify where is the problem.

  • I tried this one also using xt1clk as reference to FLL. But it is not transmitting any character on my uart.
    void ucs_init()
    {
    UCSCTL3 = SELREF_0; // 1mhz
    UCSCTL4 = SELA_0 + SELS_3 + SELM_3;
    __bis_SR_register(SCG0); // Disable the FLL control loop
    UCSCTL0= 0x00;
    UCSCTL1= DCORSEL_3;

    UCSCTL2 = FLLD_0 + 121; // 4mhz
    __bic_SR_register(SCG0); // Enable the FLL control loop
    __delay_cycles(125000);
    }
  • Hi Harish,

    I'll review your code, but in the meantime can you read through the General and UART sections of Solutions to Common eUSCI and USCI Serial Communication Issues on MSP430 MCUs. As the name suggests, this document walks you through the most common serial communication issues and how to solve them. Once you've read through it let me know. 

    Best regards, 

    Caleb Overbay

  • Hi Harish,

    After looking at your code I have a few comments:

    1. UCA2CTL1 |= UCSSEL__ACLK;                  // SELECT SMCLK 1 MHZ clock source to USCI module
      1. You are setting the UART clock source to ACLK not SMCLK. ACLK = 32768
    2. UCA2BR0=416;                        // presacalar value for BAUD rate generator 9600 bps
      1. This will not properly achieve the 9600 baud rate you desire. We off a baud rate generation calculator here. I recommend using it to properly setup your registers

    Best regards,

    Caleb Overbay

  • hello,

    I have changed my settings as follows:

        P9SEL |= RXD + TXD ;                            // Assign TX AND RX FACILITY FOR P9.2 AND P9.3 respectively
        UCA2CTL1 |=UCSWRST;
        UCA2CTL1 |= UCSSEL__SMCLK;                  // SELECT SMCLK 4 MHZ clock source to USCI module since my clock at 4 MHz
        UCA2CTL0 = 0x00;                    // no parity, 8 bit mode, lsb first, UART Async mode, stop bit=1
        UCA2BR0=26;                        // presacalar value for BAUD rate generator 9600 bps (4MHz/9600/16=26)
        UCA2BR1=0;
        UCA2MCTL=UCBRS_0 + UCBRF_1 + UCOS16;                 // Modulation UCBRSx=5, UCBRFx=0, uCOS=1 for oversampling
        UCA2CTL1 &=~UCSWRST;                  //initialize USCI state machine
        UCA2IE |= UCRXIE;                    // Enable USCI_A0 RX interrupt
         __bis_SR_register(GIE);             // global interrupt enable

    But still not receiving any character on terminal.

  • Hi Harish,

    If you're going to be using the SMCLK at 4MHz, your prescalar settings are still incorrect. When plugging the numbers into the baud rate calculator I get the following:

    You can see the max bit error is lower for the non-oversampling method so I recommend using those numbers for your registers. 

    Also, how are you interfacing the MSP430F5659 to your PC? Are you using the device on a custom board as well? Can you connect a logic analyzer to the TX/RX lines and monitor the baud rate?

    Best regards, 

    Caleb Overbay

**Attention** This is a public forum