EmbeddedRelated.com
Forums

RS232 MSP430 help

Started by kung...@gmail.com July 13, 2007
Hi,

I'm new to the world of MSP430 programming. The project I'm currently
working on involves communication between an MSP430f149 and a PC using
RS232. To start, I'm trying to write a simple routine to echo whatever
is sent to the MSP430 via Hyperterminal. However, all attempts to send
data have failed. I am using a Max3232 to connect to the serial port
of a PC; when I connect the TX and RX ports, I indeed get echoing in
Hyperterminal. This leads me to believe that the problem is caused by
my code on the MSP. Specifically, I am not sure if I set the clock
speed on the MSP correctly. I am trying to use the 32768Hz clock to
generate a 2400 Baud rate. From the MSP430 User Guide, the various
parameters are provided as follows: UBR00 = 0D; UBR10 = 00; UMCTL0 =
6B. However, a separate Baud rate calculator (http://
mspgcc.sourceforge.net/cgi-bin/msp-uart.pl?
clock=32768&baud=2400&submit=calculate) gave me:  UBR00=0x0D;
UBR10=0x00; UMCTL0=0x6D. I have tried both to no avail.

This is my routine. It should (at least in my mind) continually
transmit 0x59 (Y) and be able to listen to interrupts.

#include <msp430x14x.h>

char temp;
volatile int a;
volatile int b;
void main(void)
{

  unsigned int i;
  WDTCTL = WDTPW + WDTHOLD;             // Stop WDT
  P3SEL |= 0x30;                        // P3.4,5 = USART0 TXD/RXD
  P3DIR |= 0x10;                        // P3.4 output direction
  _EINT();                              // Enable interrupts

  BCSCTL1 = 0; // ACLK = LFXT1 = HF XTAL
  BCSCTL2 |= SELM1+SELM0;; // MCLK = LFXT1 (safe)
  do
  {
  IFG1 &= ~OFIFG;                       // Clear OSCFault flag
  for (i = 0xFF; i > 0; i--);           // Time for flag to set
  }
  while ((IFG1 & OFIFG) != 0);          // OSCFault flag still
set?

  UCTL0 = SWRST;
  UCTL0 |= CHAR;                         // 8-bit character
  UTCTL0 |= SSEL0;                       // UCLK = ACLK
  UBR00 = 0x0D;
  UBR10 = 0x00;
  UMCTL0 = 0x6B;
  UCTL &= ~SWRST;
  IFG1 &= ~(UTXIFG0 | URXIFG0);
  ME1 |= UTXE0 + URXE0;                 // Enable USART0 TXD/RXD
  IE1 |= URXIE0;                        // Enable USART0 RX interrupt
  a = 1;

  for (;;) {
//    while ((IFG1 & UTXIFG0) == 0);
//    TXBUF0 = 0x59;
  }
}

  #pragma vector=USART0RX_VECTOR
    __interrupt void intUart0Rx(void)
{
  b = 1;
  while ((IFG1 & UTXIFG0) == 0);        // USART0 TX buffer ready?
  temp = 1;
  TXBUF0 = RXBUF0;                      // RXBUF0 to TXBUF0
}



Regarding the interrupt, I am using Live Watch in IAR Workshop to
monitor the status of variables and it never enters the ISR.

I have been using an oscilloscope to measure voltage changes. I get a
constant 3V from the transmit port and I have yet to pick up any type
of transmit. On the other hand, when I type something in
Hyperterminal, I get a nice periodic voltage signature at on the
ports.

Regarding the clocks, is there an internal built-in 32768Hz crystal or
do I need to connect one to the XIN/XOUT? Is there any way to test if
such a crystal exists? Am I accessing the 32768 clock correctly?

For reference, I am setting Hyperterminal to:
2400bps
8 bit chars
parity: none
flow control: Off
Stop bit: 1 bit

Any help would be greatly appreciated. Thanks!
-Bryce

On Jul 13, 3:03 pm, "kungling...@gmail.com" <kungling...@gmail.com>
wrote:

> Regarding the clocks, is there an internal built-in 32768Hz crystal or > do I need to connect one to the XIN/XOUT?
See the data sheet...
> Is there any way to test if > such a crystal exists? Am I accessing the 32768 clock correctly?
Write a very simple program that toggles an I/O pin in a tight loop. Look at that pin with a scope. If you can figure out how many clocks your loop should take, you might even be able to determine the clock frequency.
On Jul 14, 1:08 am, cs_post...@hotmail.com wrote:
> On Jul 13, 3:03 pm, "kungling...@gmail.com" <kungling...@gmail.com> > wrote: > > > Regarding the clocks, is there an internal built-in 32768Hz crystal or > > do I need to connect one to the XIN/XOUT? >
You have to connect a crystal.
> See the data sheet... > > > Is there any way to test if > > such a crystal exists? Am I accessing the 32768 clock correctly? >
Do you have a debugger? Connect using debugger and as suggested below write a simple program to toggle pin or something. Debugger generates so getting the toggle working shouldn't be much of a problem. If on removing the debugger and supplying clock the toggle continues then you are on your way. btw there aren't many wrong ways of conncting the crystal so I am sure if you have attached one then it should be correct
> Write a very simple program that toggles an I/O pin in a tight loop. > Look at that pin with a scope. If you can figure out how many clocks > your loop should take, you might even be able to determine the clock > frequency.
Frequency: It has PLL inside to frequency is selectable
On Jul 14, 1:03 am, "kungling...@gmail.com" <kungling...@gmail.com>
wrote:
> Hi, > > I'm new to the world of MSP430 programming. The project I'm currently > working on involves communication between an MSP430f149 and a PC using > RS232. To start, I'm trying to write a simple routine to echo whatever > is sent to the MSP430 via Hyperterminal. However, all attempts to send > data have failed. I am using a Max3232 to connect to the serial port > of a PC; when I connect the TX and RX ports, I indeed get echoing in > Hyperterminal. This leads me to believe that the problem is caused by > my code on the MSP. Specifically, I am not sure if I set the clock > speed on the MSP correctly. I am trying to use the 32768Hz clock to > generate a 2400 Baud rate. From the MSP430 User Guide, the various > parameters are provided as follows: UBR00 = 0D; UBR10 = 00; UMCTL0 = > 6B. However, a separate Baud rate calculator (http:// > mspgcc.sourceforge.net/cgi-bin/msp-uart.pl? > clock=32768&baud=2400&submit=calculate) gave me: UBR00=0x0D; > UBR10=0x00; UMCTL0=0x6D. I have tried both to no avail. > > This is my routine. It should (at least in my mind) continually > transmit 0x59 (Y) and be able to listen to interrupts. > > #include <msp430x14x.h> > > char temp; > volatile int a; > volatile int b; > void main(void) > { > > unsigned int i; > WDTCTL = WDTPW + WDTHOLD; // Stop WDT > P3SEL |= 0x30; // P3.4,5 = USART0 TXD/RXD > P3DIR |= 0x10; // P3.4 output direction > _EINT(); // Enable interrupts > > BCSCTL1 = 0; // ACLK = LFXT1 = HF XTAL > BCSCTL2 |= SELM1+SELM0;; // MCLK = LFXT1 (safe) > do > { > IFG1 &= ~OFIFG; // Clear OSCFault flag > for (i = 0xFF; i > 0; i--); // Time for flag to set > } > while ((IFG1 & OFIFG) != 0); // OSCFault flag still > set? > > UCTL0 = SWRST; > UCTL0 |= CHAR; // 8-bit character > UTCTL0 |= SSEL0; // UCLK = ACLK > UBR00 = 0x0D; > UBR10 = 0x00; > UMCTL0 = 0x6B; > UCTL &= ~SWRST; > IFG1 &= ~(UTXIFG0 | URXIFG0); > ME1 |= UTXE0 + URXE0; // Enable USART0 TXD/RXD > IE1 |= URXIE0; // Enable USART0 RX interrupt > a = 1; > > for (;;) { > // while ((IFG1 & UTXIFG0) == 0); > // TXBUF0 = 0x59; > } > > } > > #pragma vector=USART0RX_VECTOR > __interrupt void intUart0Rx(void) > { > b = 1; > while ((IFG1 & UTXIFG0) == 0); // USART0 TX buffer ready? > temp = 1; > TXBUF0 = RXBUF0; // RXBUF0 to TXBUF0 > > } > > Regarding the interrupt, I am using Live Watch in IAR Workshop to > monitor the status of variables and it never enters the ISR. > > I have been using an oscilloscope to measure voltage changes. I get a > constant 3V from the transmit port and I have yet to pick up any type > of transmit. On the other hand, when I type something in > Hyperterminal, I get a nice periodic voltage signature at on the > ports. > > Regarding the clocks, is there an internal built-in 32768Hz crystal or > do I need to connect one to the XIN/XOUT? Is there any way to test if > such a crystal exists? Am I accessing the 32768 clock correctly? > > For reference, I am setting Hyperterminal to: > 2400bps > 8 bit chars > parity: none > flow control: Off > Stop bit: 1 bit > > Any help would be greatly appreciated. Thanks! > -Bryce
Hi, This post had helped me through earlier. Do post back if you are still not able to figure out. Will try to post some code http://groups.google.com/group/comp.arch.embedded/browse_thread/thread/23b6e70d7cd7a185/29e5f07cee45303e?lnk=gst&q=msp430++usart&rnum=13#29e5f07cee45303e Rohan