MSP430FR4133: msp430fr4133 uart baudrate 1200 doesn't work

Part Number: MSP430FR4133

In my previous post, eUSCI of msp430fr4133 cannot use aclk, so I was suggested to set the smclk value by adjusting it.(smclk = 1MHz, BRW = 833)

I made 1mhz smclk and set up 1200 baudrate uart, but transmission did not work properly... (I want to do uart communication at 1200 baudrate on msp430fr4133 )

below is the entire code that I have set up.

(I created initUART_1200() and initClockTo1MHz by changing only the setting values in initUART and initClockTo16mHz. the rest of the logic is the same as the reference.

#include <msp430.h>

//******************************************************************************
// UART Initialization *********************************************************
//******************************************************************************

#define LED_OUT     P1OUT
#define LED_DIR     P1DIR
#define LED_PIN     BIT2

#define SMCLK_115200     0
#define SMCLK_9600       1

#define UART_MODE       SMCLK_115200//SMCLK_9600//

void initUART()
{
    // Configure USCI_A0 for UART mode
    UCA0CTLW0 |= UCSWRST;                      // Put eUSCI in reset
#if UART_MODE == SMCLK_115200

    UCA0CTLW0 |= UCSSEL__SMCLK;               // CLK = SMCLK
    // Baud Rate Setting
    // Use Table 21-5
    UCA0BRW = 8;
    UCA0MCTLW |= UCOS16 | UCBRF_10 | 0xF700;   //0xF700 is UCBRSx = 0xF7

#elif UART_MODE == SMCLK_9600

    UCA0CTLW0 |= UCSSEL__SMCLK;               // CLK = SMCLK
    // Baud Rate Setting
    // Use Table 21-5
    UCA0BRW = 104;
    UCA0MCTLW |= UCOS16 | UCBRF_2 | 0xD600;   //0xD600 is UCBRSx = 0xD6
#else
    # error "Please specify baud rate to 115200 or 9600"
#endif

    UCA0CTLW0 &= ~UCSWRST;                    // Initialize eUSCI
    UCA0IE |= UCRXIE;                         // Enable USCI_A0 RX interrupt
}

void initUART_1200()
{
    // Configure USCI_A0 for UART mode
    UCA0CTLW0 |= UCSWRST;
    UCA0CTLW0 |= UCSSEL__SMCLK;

    UCA0BRW = 52;
    UCA0MCTLW |= UCOS16 | UCBRF_1 | 0x4900;

    UCA0CTLW0 &= ~UCSWRST;
    UCA0IE |= UCRXIE;
}

//******************************************************************************
// Device Initialization *******************************************************
//******************************************************************************

void initGPIO()
{
    LED_DIR |= LED_PIN;
    LED_OUT &= ~LED_PIN;

    // USCI_A0 UART operation
    P1SEL0 |= BIT0 | BIT1;

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

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

    __bis_SR_register(SCG0);    // disable FLL
    CSCTL3 |= SELREF__REFOCLK;  // Set REFO as FLL reference source
    CSCTL0 = 0;                 // clear DCO and MOD registers
    CSCTL1 &= ~(DCORSEL_7);     // Clear DCO frequency select bits first
    CSCTL1 |= DCORSEL_5;        // Set DCO = 16MHz
    CSCTL2 = FLLD_0 + 487;      // set to fDCOCLKDIV = (FLLN + 1)*(fFLLREFCLK/n)
                                //                   = (487 + 1)*(32.768 kHz/1)
                                //                   = 16 MHz
    __delay_cycles(3);
    __bic_SR_register(SCG0);                        // enable FLL
    while(CSCTL7 & (FLLUNLOCK0 | FLLUNLOCK1));      // FLL locked

    CSCTL4 = SELMS__DCOCLKDIV | SELA__REFOCLK;
}

void initClockTo1MHz()
{
    // Configure one FRAM waitstate as required by the device datasheet for MCLK
    // operation beyond 8MHz _before_ configuring the clock system.

    FRCTL0 = FRCTLPW | NWAITS_1;

    __bis_SR_register(SCG0);    // disable FLL
    CSCTL3 |= SELREF__REFOCLK;  // Set REFO as FLL reference source
    CSCTL0 = 0;                 // clear DCO and MOD registers
    CSCTL1 &= ~(DCORSEL_7);     // Clear DCO frequency select bits first
    CSCTL1 |= DCORSEL_0;        // Set DCO = 1MHz
    CSCTL2 = FLLD_0 + 30;       // set to fDCOCLKDIV = (FLLN + 1)*(fFLLREFCLK/n)
                                //                   = (487 + 1)*(32.768 kHz/1)
                                //                   = 16 MHz
    __delay_cycles(3);
    __bic_SR_register(SCG0);                        // enable FLL
    while(CSCTL7 & (FLLUNLOCK0 | FLLUNLOCK1));      // FLL locked

    CSCTL4 = SELMS__DCOCLKDIV | SELA__REFOCLK;
}

//******************************************************************************
// Main ************************************************************************
// Enters LPM0 if SMCLK is used and waits for UART interrupts. If ACLK is used *
// then the device will enter LPM3 mode instead. The UART RX interrupt handles *
// the received character and echoes it.                                       *
//******************************************************************************

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

  initGPIO();
  //initClockTo16MHz();
  //initUART();
  initClockTo1MHz();
  initUART_1200();


#if UART_MODE == SMCLK_9600
    __bis_SR_register(LPM0_bits + GIE);       // Since ACLK is source, enter LPM0, interrupts enabled
#else
    __bis_SR_register(LPM0_bits + GIE);       // Since SMCLK is source, enter LPM0, interrupts enabled
#endif
  __no_operation();                         // For debugger
}

//******************************************************************************
// UART Interrupt ***********************************************************
//******************************************************************************

#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=USCI_A0_VECTOR
__interrupt void USCI_A0_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(USCI_A0_VECTOR))) USCI_A0_ISR (void)
#else
#error Compiler not supported!
#endif
{
  switch(__even_in_range(UCA0IV, USCI_UART_UCTXCPTIFG))
  {
    case USCI_NONE: break;
    case USCI_UART_UCRXIFG:
      while(!(UCA0IFG&UCTXIFG));
      UCA0TXBUF = UCA0RXBUF;
      __no_operation();
      break;
    case USCI_UART_UCTXIFG: break;
    case USCI_UART_UCSTTIFG: break;
    case USCI_UART_UCTXCPTIFG: break;
  }
}

Are there any mistake or missing parts? or is there something else that needs to be changed?

  • Hi Kim

    according "22.3.10Settinga BaudRate" of MSP430FR4xx and MSP430FR2xx Family User's Guide (Rev. I), I think the following setting is correct on 1200bps at 1MHz UART clock.

    void initUART_1200()
    {
        // Configure USCI_A0 for UART mode
        UCA0CTLW0 |= UCSWRST;
        UCA0CTLW0 |= UCSSEL__SMCLK;

        UCA0BRW = 52;
        UCA0MCTLW |= UCOS16 | UCBRF_1 | 0x4900;

        UCA0CTLW0 &= ~UCSWRST;
        UCA0IE |= UCRXIE;
    }

    Please consider check SMCLK frequency and UART waveform using oscilloscope.

    Thanks!

  • If you're using the Launchpad, be sure to remove the jumper on JP1 (LED1), since it's also connected to the TXD (P1.0) pin.

  • I tried what you suggested, but it doesn't work properly.

    As a result of testing so far, only the values presented in the document table(MSP430FR4xx and MSP430FR2xx family table22-5, page 589) work normally.

    For 9600 or 115200 baudrate, various BRCLK contents such as 1M, 4M, and 16M are presented in the table, and it works.(even with the settings I made.)

    1200 baudrate is only shown in the table for 32768 BRCLK.

    I don't know if that is the reason, but it doesn't work in the 1M BRCLK setting

    UCLK cannot be used on the my actual board due to hardware structure. So I want to use 1200 baudrate using modclk.

    but modclk is known as 5M fixed. when I set based 5M BRCLK(modclk), it does not work.

    1. is it possible to set uart 1200 baudrate using modclk(msp430fr4133)? 

    2. If there is no problem in use, I am curious about the setting value(the value calculate by the formula in the document does not work)
        I already know on-line calculator 

  • I see the same behavior on my Launchpad. Using UCA0 through the Backchannel UART, with PuTTY at the host, I see:

    1) When I type at PuTTY, I see a (single) very short pulse on RXD

    2) When I use the debugger to put a byte in UCA0TXBUF, I see a very good waveform on TXD. This suggests that the MSP430 is doing the right thing(s).

    I think the problem is that the Backchannel UART can't run at 1200bps. Table 14 in the Debuggers User Guide (SLAU647O) doesn't list 1200bps, the lowest it goes is 4800bps. [Though I'm pretty sure I've run it faster than 115kbps.]

    You may succeed with an external USB/UART converter e.g. the FT232.

    I suspect you won't succeed using MODCLK, since it is specified only to +/-20%.