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 }