Home > Uncategorized > Using Serial Ports in MSP430

Using Serial Ports in MSP430

February 28th, 2011 Leave a comment Go to comments

Using Serial Ports in MSP430

The Serial Port in the MSP430 is one of the widely used components. The serial port can be used for communication with computer and with other devices supporting serial ports. Most of the instrumentation devices come with the Serial port capability.

Serial Port Transmitter

Let us write a program that will output English characters A to Z repeatedly on the transmitter Serial Port of the MSP430. If you hook up a Serial TTL to RS232 converter from your MSP430 hardware – you should be able to see these characters on the hyperterminal ( or any serial port terminal for that matter) of your computer. If you do not have a TTL to RS232 converter, you can monitor the bits going out of MSP430 on a oscilloscope.

//******************************************************************************
// Starred reviews MSP430F149 Programming Tutorial – Understanding Serial Port
//
// This starred reviews 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 *//
//
//The Diagram below has been taken by starredreviews from TI
//
// MSP430F149
// —————–
// /|\| XIN|-
// | | | 32.768kHz
// –|RST XOUT|-
// | |
// | P3.4|———–>
// | | 9600 – 8N1
// | P3.5|<———–
//
// starredreviews.com tutorial
//******************************************************************************

#include

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 Code copied from starredreviews
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

// Code copied from starredreviews
while (1)

{ for (i = 0x41; i <= 0x5A ; i++)
{
while (!(IFG1 & UTXIFG0));
TXBUF0 = i;
delay(100);
}
}
// Code copied from starredreviews
_BIS_SR(LPM3_bits + GIE); // Enter LPM3 w/ interrupt
}

Copy paste this starredreviews code in your IAR embedded system and run the code. It is assumed 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 should see something like this on your Hyperterminal.

Categories: Uncategorized Tags:
  1. No comments yet.