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.

MSP430F5529 UART

Hi,

I'm trying to convert some code one of my professors wrote for the g2553 and make it work on the f5529 launchpad. I realize that there are several differences between the two boards, so in addition to is this possible, can I get some help properly converting the registers and variables to what they need to be on the f5529?

So far I've changed IFG2 -> UCB0IFG and IE2 -> UCB0IE, as well as changing the LED pin. These changes allow me to compile & run, but I'm pretty certain that my ignorance on what all the variables are / mean is why I can't see why the code won't work. If there's some reference for what all these variables mean, I'd be grateful for a link.

I'm using Tera Term and connecting to the MSP serially using port "COM8: MSP Application UART1", then running the program using code composer. However, nothing happens. If I load the code on the MSP and then connect serially using port "COM9: MSP Debug Interface", I can enter a character, but then garbage is printed and echoed back.

Any/all help or suggestions are welcome. 

Thanks, Christina.

Here's the code:

void Init_UART(void);
void OUTA_UART(unsigned char A);
unsigned char INCHAR_UART(void);

#include <msp430f5529.h>
#include "stdio.h"

/*
 * main.c
 */
int main(void) {
	volatile unsigned char a;
	volatile unsigned int i; // volatile to prevent optimization

	WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer

	Init_UART();
	a=INCHAR_UART();
	OUTA_UART(a);
	// go blink the light to indicate code is running
	P4DIR |= 0x80; // Set P4.7 to output direction

	// Use The LED as an indicator
	for (;;){
		P4OUT ^= 0x80; // Toggle P4.7 using exclusive-OR
		i = 10000; // SW Delay
		do i--;
		while (i != 0);
	}
	
	return 0;
}

void OUTA_UART(unsigned char A){
	//---------------------------------------------------------------
	//***************************************************************
	//---------------------------------------------------------------
	// IFG2 register (1) = 1 transmit buffer is empty,
	// UCA0TXBUF 8 bit transmit buffer
	// wait for the transmit buffer to be empty before sending the
	// data out
	do {}
	while ((UCB1IFG&0x02)==0);
	// send the data to the transmit buffer
	UCA0TXBUF = A;
}

unsigned char INCHAR_UART(void){
	//---------------------------------------------------------------
	//***************************************************************
	//---------------------------------------------------------------
	// IFG2 register (0) = 1 receive buffer is full,
	// UCA0RXBUF 8 bit receive buffer
	// wait for the receive buffer is full before getting the data
	do {} while ((UCB1IFG&0x01)==0);
	// go get the char from the receive buffer
	return (UCA0RXBUF);
}


void Init_UART(void){
	//---------------------------------------------------------------
	// Initialization code to set up the uart on the experimenter
	// board to 8 data,
	// 1 stop, no parity, and 9600 baud, polling operation
	//---------------------------------------------------------------
	P2SEL=0x30; // transmit and receive to port 2 b its 4 and 5
	 // 0011 0000
	 // Bits p2.4 transmit and p2.5 receive

	UCA0CTL0=0; // 8 data, no parity 1 stop, uart, async
	 // (7)=1 (parity), (6)=1 Even, (5)= 0 lsb first,
	 // (4)= 0 8 data / 1 7 data,
	 // (3) 0 1 stop 1 / 2 stop, (2-1) -- UART mode,
	 // (0) 0 = async

	UCA0CTL1= 0x41;
	 // select ALK 32768 and put in
	 // software reset the UART
	 // (7-6) 00 UCLK, 01 ACLK (32768 hz), 10 SMCLK,
	 // 11 SMCLK
	 // (0) = 1 reset

	UCA0BR1=0; // upper byte of divider clock word

	UCA0BR0=3; // clock divide from a clock to bit clock 32768/9600
	 // = 3.413
	 // UCA0BR1:UCA0BR0 two 8 bit reg to from 16 bit
	 // clock divider
	 // for the baud rate

	UCA0MCTL=0x06;
	 // low frequency mode module 3 modulation pater
	 // used for the bit clock

	UCA0STAT=0; // do not loop the transmitter back to the
	 // receiver for echoing
	 // (7) = 1 echo back trans to rec
	 // (6) = 1 framing, (5) = 1 overrun, (4) =1 Parity,
	 // (3) = 1 break
	 // (0) = 2 transmitting or receiving data

	UCA0CTL1=0x40;
	 // take UART out of reset

	UCB0IE=0; // turn transmit interrupts off
	//---------------------------------------------------------------
	//***************************************************************
	//---------------------------------------------------------------
	 // IFG2 register (0) = 1 receiver buffer is full,
	 // UCA0RXIFG
	 // IFG2 register (1) = 1 transmit buffer is empty,
	 // UCA0RXIFG
	 // UCA0RXBUF 8 bit receiver buffer
	 // UCA0TXBUF 8 bit transmit buffer
}

  • A couple of things....

    1. First should be to read the F5x/F6x User's Guide and understand how the UART works on the 5529 device.
    2. You need to know what the default clock configuration of the 5529 is (since it doesn't appear that you are changing it). Again , check the User's Guide.
    3. Once you know that, you can figure out how to configure the baud rate of the UART.
    4. You have references to UCB1, but UCB1 only does SPI or I2C. I think you meant to use UCA0 which supports UART mode. These are totally separate peripherals. You shouldn't be mixing the register sets like you are.
  • The two main differences in your case are the clock system and the USCI.
    I don't see you initializing the clock system. Apparently the code is using the default. Which is different for the two families. ( ~1.05MHz for 2x family and 1.0158MHz for 5x family) THis affects the baudrate.
    The other one is that on 5x family, all USCI interrupts are shared on one interrupt vector. And the registers for controlling the interrupts are different.
    See the two users guides for details.
  • Thanks for the help, Brian and Jens-Michael. I decided to not use this code and instead used sample code downloaded using the newest Code Composer that was coded specifically for the F5529. There are different samples for different baud rate configurations, and the only change I had to make was using USCI_A1 since that's the uart used by the F5529 to communicate through the usb with my computer. 

  • Hello sir,
    i copied ur code and dumped to f5529LP but i am not getting the output.is there any jumper connection to be modified ,if so please let me know.
    am also using tera term for output to see.

    thank you
  • As mentioned in the previous answers, the code in the question is wrong.

    Just copy the example code from SLAC300.

**Attention** This is a public forum