Jump to content
43oh

UART Trouble - TX prints "junk" in PuTTY?


Recommended Posts

Hello,

I'm very new to uCs, so please bear with me and my inevitable incorrect use of terminology (corrections appreciated!).
I've been doing a lot of reading, and wrote a little program to TX/RX characters from PuTTY over UART.  I think maybe I have some inappropriate UART settings, because the very first TX always prints garbage, even on reset.  

 

Would someone mind please taking a look for me?  I'll just post the UART setup routine, and the print routine unless posting the whole code would be more useful.

 

I've also attached a PuTTY screenshot as an example of the "garbage" I mean, and my PuTTY config. (9600 baud, 8 data bits, 1 stop bit, no parity, no flow)

I'm using the launchpad MSP-EXP430G2 v1.5 and the g2553.  Windows 7, Code Composer V5.5

 

Thank you so much for any help!
 

void uart_init()
{
/*Setup TX/RX for MSP430G2553*/
BCSCTL1 = CALBC1_1MHZ;     // Set Basic Clock System (msp430g2553.h - 1MHz bitmask)
DCOCTL = CALDCO_1MHZ;      // Digitally Controlled Oscillator (msp430g2553.h - 1MHz bitmask)

P1SEL |= BIT1 + BIT2;                    //Set for UART functionality
P1SEL2 |= BIT1 + BIT2;                   //Set for UART functionality

// Configure UCA0 control register 
UCA0CTL0 = 0;  // Async, UART, One Stop, 8-bit data, LSB, Odd Parity, Parity Disabled
UCA0CTL1 |= UCSSEL_2;      // Use SMCLK as USCI clock source
UCA0CTL1 &= ~UCSWRST;      // Software Reset disabled - USCI reset released for operation

/* 16-bit value (UCA0BR0 + UCA0BR1 x 256) = prescaler */
UCA0BR1 = 0;               // 0 for prescaler maths?
UCA0BR0 = 104;             //1MHz (DCO?) So 1MHz/9600 = ~104

UCA0MCTL = UCBRS0;   //Modulation Control Register (bitclk timing for bit value sampling?)

IE2 |= UCA0RXIE;     // Enable USCI_A0 RX interrupt

}

/*Transmit String byte-by-byte*/
void sendstring(char * str)
{
       char *ptr;
       unsigned char len = 0;
       for (ptr = str; *ptr; ++ptr) ++len;      //calculate string length

       int i;
       for (i=0; i<len; i++)
       {
              while (!(IFG2&UCA0TXIFG));        // USCI_A0 TX buffer ready?
              UCA0TXBUF = str[i];
       }
}

an example, the first sendstring is:  sendstring("garbage\n\r");

post-34438-0-80490300-1384291955_thumb.png

post-34438-0-51295200-1384291998_thumb.png

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...