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 calculatorThis is my routine. It should (at least in my mind) continually transmit 0x59 (Y) and be able to listen to interrupts.
#include
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 bitAny help would be greatly appreciated. Thanks!
-Bryce