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.

MSP430FR6047: uart code is not working

Part Number: MSP430FR6047

Tool/software:

Hello Team,

please help to fix the issue in sending data over uart, i am using MSP430fr6047 EVM board, rev A with Rev B chip.

#include <msp430.h>

#define UART_TX_PORT_SEL0 P2SEL0
#define UART_TX_PORT_SEL1 P2SEL1
#define UART_TX_PIN       BIT0
#define UART_RX_PIN       BIT1

void uart_init(void);
void uart_send_string(const char *str);

int main(void)
{
    WDTCTL = WDTPW | WDTHOLD;      // Stop watchdog timer
    PM5CTL0 &= ~LOCKLPM5;          // Enable GPIO

    // Configure pins for UART
    UART_TX_PORT_SEL0 |= UART_TX_PIN | UART_RX_PIN;
    UART_TX_PORT_SEL1 &= ~(UART_TX_PIN | UART_RX_PIN);

    uart_init();

    while (1) {
        uart_send_string("Hello MSP430 UART!\r\n");
        __delay_cycles(1000000); // ~1 s delay @ 1 MHz
    }
}

void uart_init(void)
{
    UCA0CTLW0 |= UCSWRST;               // Hold in reset
    UCA0CTLW0 |= UCSSEL__SMCLK;        // SMCLK
    UCA0BRW = 104;                      // 1 MHz / 9600 ≈ 104
    UCA0MCTLW = UCOS16 | UCBRF_2 | 0xD600; // Modulation settings for 9600
    UCA0CTLW0 &= ~UCSWRST;             // Initialize USCI
}

void uart_send_string(const char *str)
{
    while (*str) {
        while (!(UCA0IFG & UCTXIFG));  // Wait for TX ready
        UCA0TXBUF = *str++;
    }
}

Thank you.

Venkatarramana

  • You don't say what your problem is.

    But at a glance, your bit rate settings are wrong.The comments say 9600 but the settings are for about 1/16th of that.

    Look at the table (30-5) of typical baud rate settings in the guide.

  • what is the actual value to be set to send data over UART with 9600 baud rate please. 

  • Hi Venkat,

    Below is the example for your reference:

    https://dev.ti.com/tirex/explore/node?node=A__ALlQ8TQBkgGtFo0cTvhy2Q__msp430ware__IOGqZri__LATEST&placeholder=true 

    And you can refer to the UG for how to calculate the Baud Rate: (The demo also show it in the comments)

    B.R.

    Sal

  • More specifically: Remove UCOS16.

  • let me check and update. however, i have found another working example from TI website, its working.

    #include <msp430.h>

    void uartSendStr(char*);
    int main(void)
    {
    WDTCTL = WDTPW | WDTHOLD; // Stop Watchdog

    // Configure GPIO
    P1SEL0 |= BIT2 | BIT3; // USCI_A1 UART operation

    // Disable the GPIO power-on default high-impedance mode to activate
    // previously configured port settings
    PM5CTL0 &= ~LOCKLPM5;

    // Startup clock system with max DCO setting ~8MHz
    CSCTL0_H = CSKEY_H; // Unlock CS registers
    CSCTL1 = DCOFSEL_3 | DCORSEL; // Set DCO to 8MHz
    CSCTL2 = SELA__VLOCLK | SELS__DCOCLK | SELM__DCOCLK;
    CSCTL3 = DIVA__1 | DIVS__1 | DIVM__1; // Set all dividers
    CSCTL0_H = 0; // Lock CS registers

    // Configure USCI_A0 for UART mode
    UCA1CTLW0 = UCSWRST; // Put eUSCI in reset
    UCA1CTLW0 |= UCSSEL__SMCLK; // CLK = SMCLK
    // Baud Rate calculation
    // 8000000/(16*9600) = 52.083
    // Fractional portion = 0.083
    // User's Guide Table 24-4: UCBRSx = 0x04
    // UCBRFx = int ( (52.083-52)*16) = 1
    UCA1BRW = 52; // 8000000/16/9600
    UCA1MCTLW |= UCOS16 | UCBRF_1 | 0x4900;
    UCA1CTLW0 &= ~UCSWRST; // Initialize eUSCI
    // UCA1IE |= UCRXIE; // Enable USCI_A0 RX interrupt

    // __bis_SR_register(GIE); // Enter LPM3, interrupts enabled
    uartSendStr("\r\nramaSita\r\n");
    // __bis_SR_register(LPM3_bits + GIE); // Enter LPM3, interrupts enabled

    //uartSendStr("ramaSita");

    __no_operation(); // For debugger



    }

    /*

    unsigned char temp;
    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector=EUSCI_A1_VECTOR
    __interrupt void USCI_A1_ISR(void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(EUSCI_A1_VECTOR))) USCI_A1_ISR (void)
    #else
    #error Compiler not supported!
    #endif
    {
    switch(__even_in_range(UCA1IV, USCI_UART_UCTXCPTIFG))
    {
    case USCI_NONE: break;
    case USCI_UART_UCRXIFG:
    while(!(UCA1IFG&UCTXIFG));
    temp = UCA1RXBUF;
    UCA1TXBUF = temp;
    // UCA1TXBUF = temp;
    __no_operation();
    break;
    case USCI_UART_UCTXIFG:
    break;
    case USCI_UART_UCSTTIFG: break;
    case USCI_UART_UCTXCPTIFG: break;
    default: break;
    }
    }
    */
    void uartSendStr(char *s)
    {

    while(*s)
    {
    UCA1TXBUF = *s;
    while(!(UCA1IFG & UCTXIFG));

    s++;

    }

    }

**Attention** This is a public forum