MSP430 Embedded Programming Tutorial TUTORIAL


Using Serial Ports


The Serial Port of MSP430 is almost always used in any MSP430 design. The serial port can be used for communication with computer and with other devices supporting serial ports.

Serial Port Transmitter


Let us write a code that will output englisg characters A to Z repeatedly on the Serial Port of the MSP430. If you hook up a Serial TTL to RS232 converter then you should be able to see these characters on the hyperterminal of your computer. If you do not have a TTL to RS232 converter you should be able to monitor the bits going out of MSP430 on a oscilloscope.

//******************************************************************************
//  MSP430F149 Programming Tutorial - Understanding Serial Port
//
//  This program Transmits Character A to Z on Hyperterminal at 9600-baud UART using
//  USART0 and a 32.768 kHz crystal.
//  Baud rate divider with 32.768 Khz XTAL
//  @9600 = 32768Hz/9600 = 3.41  =>  UBR00 = 0x03;  UBR01 = 0x03;
//  //* An external 32.768KHz crystal is required on XIN XOUT *//   
//
//               MSP430F149
//            -----------------
//        /|\|              XIN|-
//         | |                 | 32.768kHz
//         --|RST          XOUT|-
//           |                 |
//           |             P3.4|----------->
//           |                 | 9600 - 8N1
//           |             P3.5|<-----------
//
// referencedesigner.com tutorial
//******************************************************************************

#include  <msp430x14x.h>

void delay(unsigned int ms)
{
unsigned int i, j;
for (i = 0; i <= ms; i++)
{
for (j = 0; j<=255; j++);
}
}

void main(void)
{
  unsigned int i;
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
  P3SEL |= 0x30;                            // P3.4,5 = USART0 TXD/RXD
  ME1 |= UTXE0 + URXE0;                     // Enable USART0 TXD/RXD
  UCTL0 |= CHAR;                            // 8-bit character
  UTCTL0 |= SSEL0;                          // UCLK = ACLK
  UBR00 = 0x03;                             // 32k/9600 - 3.41
  UBR10 = 0x00;                             //
  UMCTL0 = 0x4A;                            // Modulation
  UCTL0 &= ~SWRST;                          // Initialize USART state machine
 
  while (1)

  { for (i = 0x41; i <= 0x5A ; i++)
    {
      while (!(IFG1 & UTXIFG0));
      TXBUF0 = i;
      delay(100);
    }
  }

  _BIS_SR(LPM3_bits + GIE);                 // Enter LPM3 w/ interrupt
}



Copy paste this code in your IAR embedder system and run the code. I am assuming that you connect a TTL to RS232 converter between P3.4 and the input ( Pin 2 ) of the DB9 serial port connector of your computer. If you open the hyperterminal then you shoul see something like this on your Hyperterminal


<