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.

CCS/MSP430F5438A: UART Configuration

Part Number: MSP430F5438A

Tool/software: Code Composer Studio

Hey, I'm a new programmer and I wanted to configure the MSP430 to blink a LED via UART. I ran into trouble setting up the register, pin ports (IO) & DCO. I know the baud rate is suppose to be 57600 bps, and the clock frequency should be 16Mhz. Is there a simple way to do this? Am going down the right path? With the Code below can I reach my goal, If yes what should I do next?

/**

* using UART to blink LED forever

* blink.c

*/

#include <msp430.h>

int ReadRegister(void);

void TestBlinkingLight(void);

int x;

int main(void)

{

 

while(1)

{

x = ReadRegister();

switch(x)

{

case 0x03:

TestBlinkingLight();

break;

default:

break;

}

}

}

// initialize UART

 

 

// set DCO

 

 

// Configure IO

void TestBlinkingLight(void)

{

WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer

P1DIR |= 0x01; // configure P1.0 as output

volatile unsigned int i; // volatile to prevent optimization

while(1)

{

P1OUT ^= 0x01; // toggle P1.0

for(i=10000; i>0; i--); // delay

}

}

int ReadRegister()

{

x = UCA0STAT;

if (0x01 == UCA0STAT)

x = UCA0RXBUF;

return x;

}

  • There's some configuration you need to do to the UART. I suggest you start with one of the "uscia0_uart" examples at:

    http://dev.ti.com/tirex/explore/node?node=AMG0G4bDkAUNjJAhdKxRYA__IOGqZri__LATEST

  • Hi Bruce

    Thanks for your comment! Code example should be the good approach to study MSP430 peripheral usage at the beginning.

  • Thank you all for your  responses. With the help of the examples I have developed a better code yet I believe something is wrong. I wish to send a command through UART to trigger a flashing led1 and solid led2. May you review the latest code I developed and tell me what I'm doing wrong.

    #include <msp430.h>
    /**
     * blink.c
     */

    //int ReadRegister(void);
    void TestBlinkingLight(void);
    //int x;

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

        P3SEL = 0x30;                             // P3.4,5 = USCI_A0 TXD/RXD
        UCA0CTL1 |= UCSWRST;                      // **Put state machine in reset**
        UCA0CTL1 |= UCSSEL_2;                     // SMCLK
        UCA0BR0 = 109;                              // 1MHz 57600 (see User's Guide)
        UCA0BR1 = 0;                              // 1MHz 57600
        UCA0MCTL |= UCBRS_1 + UCBRF_0;            // Modulation UCBRSx=1, UCBRFx=0
        UCA0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
        UCA0IE |= UCRXIE;                         // Enable USCI_A0 RX interrupt

        __bis_SR_register(LPM0_bits + GIE);       // Enter LPM0, interrupts enabled
        __no_operation();
        TestBlinkingLight();
    }

    void TestBlinkingLight(void)
    {
        WDTCTL = WDTPW | WDTHOLD;       // stop watchdog timer
        P1DIR |= 0x01;                  // configure P1.0 as output

        volatile unsigned int i;        // volatile to prevent optimization

        while(1)
        {
            P1OUT ^= 0x01;              // toggle P1.0
            for(i=10000; i>0; i--);     // delay
        }
    }
    /*
    int ReadRegister()
    {
        x = UCA0STAT;
        if (0x01 == UCA0STAT)
            x = UCA0RXBUF;

        return x;

    }

    */

    // Echo back RXed character, confirm TX buffer is ready first
    #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,4))
      {
      case 0:break;                             // Vector 0 - no interrupt
      case 2:                                   // Vector 2 - RXIFG
        while (!(UCA0IFG&UCTXIFG));             // USCI_A0 TX buffer ready?
        UCA0TXBUF = UCA0RXBUF;                  // TX -> RXed character
        P1DIR |= 0x02;                          // Configure P1.1 Port Direction
        P1OUT = 0x02;                           // Turn on P1.1 LED2
        break;
      case 4:break;                             // Vector 4 - TXIFG


          break;

      default: break;
      }
    }

  • Hi Snow

    Sorry to be late because I am out of office. I am back to office today. I will study your code and share my comment later.

  • Hi Snow,

    There is the UART enhanced code example "msp430x54xA_uart_standard_transceiver.c" in  http://dev.ti.com/tirex/explore/node?node=AMG0G4bDkAUNjJAhdKxRYA__IOGqZri__LATEST

    Could you please help to study and try this code as the reference to debug your code. Thanks!

  • Thank you I will review it

**Attention** This is a public forum