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.

MSP430F4152: UART

Part Number: MSP430F4152
Other Parts Discussed in Thread: MSP430FR5962

Hello,
I am using MSP430f4152 with 4MHz external crystal.
The clock, timer, and gpio functions are working correctly.
Also, I am using software I2C for the MLX90614 temperature sensor.
It is fine also.
But, I encounter an issue with UART.
When I execute the UART procedure, The MCU is halted.
The followings are my UART setting and UART procedure.

<UART init>
void init_USCI(void)
{
    UCA0CTL1 |= UCSSEL_2;                  // SMCLK
    UCA0BR0 = 26;                                   // High Frequency Mode, Over sampling(UCOS16 = 1)
    UCA0BR1 = 0;
    UCA0MCTL |= UCBRF_1 + UCOS16; // UCBRFx = 1, UCOS16 = 1
    UCA0CTL1 &= ~UCSWRST;                // **Initialize USCI state machine**
    IE2 |= UCA0RXIE;                                // Enable USCI_A0 RX interrupt
}

<UART sending procedure>
void UCA0_chout(unsigned char tx_ch)
{
    while(!(IFG2&UCA0TXIFG));
    UCA0TXBUF = tx_ch;
}

void UCA0_strout_length(UBYTE *tx_str, UBYTE length)
{
    UBYTE I;
    for(i=0; i<length; i++) {
    UCA0_chout(*(tx_str+i));
}
}

Please help me out.

Thanks,

  • You enable the receive interrupt but show no interrupt service routine.

  • Thanks for your prompt reply.
    Posted code is not the entire code.
    The result is the same.
    The following is the RX interrupt procedure that I am using.
    <UART Interrupt>
    // Echo back RXed character, confirm TX buffer is ready first
    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector=USCIAB0RX_VECTOR
    __interrupt void USCIA0RX_ISR (void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(USCIAB0RX_VECTOR))) USCIA0RX_ISR (void)
    #else
    #error Compiler not supported!
    #endif
    {
        //while(!(IFG2&UCA0TXIFG));
        //UCA0TXBUF = UCA0RXBUF; // TX -> RXed character
    }

  • An ISR that does absolutely nothing will not clear RXIFG. So the interrupt happens again. And again.

  • Hello,
    After inserting the following code in the interrupt service routine,
    MCU halting problem is resolved.

    IFG2 &= ~UCA0RXIFG;


    But, UART Communication is failed with my sound module.
    So, I checked my MCLK clock. Then, my boards have different MCLK frequencies. 3.265MHz, 3.187MHz, 3.238MHz, 3.539MHz
    My board has 4MHz external crystal.
    The following code is clock init code.

    void init_Clock(void)
    {
        FLL_CTL0 |= XTS_FLL;
        FLL_CTL1 |= SELM_A;
    }

    How can I resolve this issue?
    Your comment will be appreciated.
    Thanks,



  • Hello,

    First, when posting code to the forum, please utilize the Insert - </> Code utility for better readability. I've already modified your post to reflect this change.

    Second, for debugging UART, please see this application note as well as our standard UART example to compare against. 

  • The documentation covers baud rate generation in detail. Read it and it should be obvious how to get your desired baud rate from your reference clock.

  • Hello,

    Thanks for your reply.
    I will go through the document you recommend and the standard UART example.
    At this moment, My curiosity is that the clock(MCLK) is not stable with external crystal.
    Also, Thanks for the information on Insert Code Utility. It has more readability than before.
    I will compare the waveform of UART output with other MCU(MSP430FR5962)
    If I have any results, I will post them.

    Thanks & Regards,

  • Hello,
    I failed UART Setting with an external 4MHz Crystal because the clock is unstable.
    So, I replace the external 4MHz crystal with a 32.768KHz crystal.
    Finally, I communicated with the sound module with 9600bps UART setting. The following is my code.

    void initClockTo16MHz()
    {
        FLL_CTL0 |= DCOPLUS + XCAP11PF;           // DCO+ set, freq = xtal x D x N+1
        SCFI0 = FLLD_4+FN_4;                      // x4 DCO freq, 16MHz nominal DCO
        SCFQCTL = 121;                            // (121+1) x 32768 x 4 = 16 MHz
    }
    
    void initUART()
    {
        UCA0CTL1 |= UCSSEL_1;                     // ACLK
        UCA0BR0 = 3;                              // 32768Hz 9600
        UCA0BR1 = 0;                              // 32768Hz 9600
        UCA0MCTL = UCBRS_3;                       // Modulation UCBRSx = 3
        UCA0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
        IFG2 &= ~(UCA0RXIFG);
        //IE2 |= UCA0RXIE;                          // Enable USCI_A0 RX interrupt
    }
    
    void UCA0_chout(unsigned char tx_ch)
    {
        while(!(IFG2&UCA0TXIFG));
        UCA0TXBUF = tx_ch;
    }
    
    void UCA0_strout_length(UBYTE *tx_str, UBYTE length)
    {
        UBYTE i;
        for(i=0; i<length; i++) {
            UCA0_chout(*(tx_str+i));
        }
    }

    Thanks & Regards,

**Attention** This is a public forum