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.

MSP-EXP430FR5994: GCC UART communication not working

Part Number: MSP-EXP430FR5994

Hello,

I try to send serial data over the UART. The program gets stuck in the loop. Any ideas?

Thanks, Edi

#include <msp430.h>
#include <stdint.h>
#include <stdio.h>
#include <stdbool.h>

#define TXLED BIT0
#define RXLED BIT1
#define TXD BIT0
#define RXD BIT1

int main(void)
{
    WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer

    // Configure one FRAM waitstate as required by the device datasheet for MCLK
    // operation beyond 8MHz _before_ configuring the clock system.
    FRCTL0 = FRCTLPW | NWAITS_1;

    // Clock System Setup
    CSCTL0_H = CSKEY_H;                                  // Unlock CS registers
    CSCTL1 = DCOFSEL_0;                                  // Set DCO to 1MHz
    CSCTL2 = SELA__VLOCLK | SELS__DCOCLK | SELM__DCOCLK; // Set SMCLK = MCLK = DCO, ACLK = VLOCLK

    // Per Device Errata set divider to 4 before changing frequency to
    // prevent out of spec operation from overshoot transient
    CSCTL3 = DIVA__4 | DIVS__4 | DIVM__4; // Set all corresponding clk sources to divide by 4 for errata
    CSCTL1 = DCOFSEL_4 | DCORSEL;         // Set DCO to 16MHz

    // Delay by ~10us to let DCO settle. 60 cycles = 20 cycles buffer + (10us / (1/4MHz))
    __delay_cycles(60);
    CSCTL3 = DIVA__1 | DIVS__1 | DIVM__1; // Set all dividers to 1 for 16MHz operation
    CSCTL0_H = 0;                         // Lock CS registers

    // Init UART
    UCA0CTL1 = UCSWRST;       // Stop UART
    UCA0BR0 = 104;            // 9600bps @16MHz
    UCA0BR1 = 2;              // 9600bps @16MHz
    UCA0MCTLW = 0x49;         // 9600bps @16MHz
    UCA0CTL1 = UCSSEL__SMCLK; // Start UART, connect it to SMCLK

    // Init Pins
    PM5CTL0 &= ~LOCKLPM5; // Enable ports
    P2SEL0 |= TXD | RXD;  // Set tertiary pin function on UART pins
    P2SEL1 |= TXD | RXD;  // set tertiary pin function on uart pins
    P1DIR |= BIT0;        // Configure P1.0 as output (LED)
    P1OUT |= BIT0;        // Set P1.0 (LED on)
    __delay_cycles(16e6); // Delay about a second
    P1OUT &= ~BIT0;       // Clear P1.0 (LED off)

    while (true)
    {
        __delay_cycles(16e5); // Delay about 0.1s
        P1OUT |= BIT0;        // Set P1.0 (LED on)
        while (!(UCA0IFG & UCTXCPTIFG))
            ;                 // Check if TX is ready
        __delay_cycles(16e5); // Delay about 0.1s
        P1OUT &= ~BIT0;       // Clear P1.0 (LED off)
        UCA0TXBUF = 'x';      // Transmit an 'x'
    }
}

  • You used the wrong flag. UCTXCPTIFG is set after something is shifted out and you test it before sending anything. Thus it remains clear. The usual test for polled transmission is UCTXIFG. Which is set after a device or serial port reset.

    I also wonder about your baud rate setting. This device has a single 16 bit register, UCA0BRW. You should review the user guide to see how the values for UCBRx, UCBRFx, and UCBRSx map to device registers.

  • Thank you! I changed it to 

    while (!(UCA0IFG & UCTXIFG))
    And now it does not hang. But nothing is transmitted, I also don't see anything on the osclilloscope...
  • >  P2SEL0 |= TXD | RXD; // Set tertiary pin function on UART pins

    Per data sheet (SLASE54D) Table 9-23, the PSEL0 bits should be 0 for UCA0. Try removing this line.

    ----------------

    >  UCA0BR1 = 2; // 9600bps @16MHz

    With BR0=104 this is a divisor of /(512+104). With UCOS16=1, this is 16M/16/616=1623bps. Try instead:

    >  UCA0BR1 = 0; // 9600bps @16MHz

  • Perfect, thanks a lot! Everything working now!

**Attention** This is a public forum