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.

MSP430G2553: UART sending garbage

Part Number: MSP430G2553


Hello,

      I'm interfacing MSP430 with PC using UART, to send a single character. MSP430 is sending signals to the PC through the TTL 232 interface.I'm seeing garbage along with received single character. Code is shown below,

#include "msp430g2553.h"
char rx;
void main(void)
{
WDTCTL = WDTPW + WDTHOLD;
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ;
P1DIR = 0x41; // P1.0 = UART TX LED ,P1.6= UART RX LED, 0100 0001
P1OUT =0x00;
P1SEL |= BIT1 + BIT2; // P1.1 UART rx operation selected ==>p1sel, psel2 =1
P1SEL2 |= BIT1 + BIT2; // P1.2 UART tx operation selected ==>p1sel, psel2 =1
UCA0CTL1 |= UCSSEL_2 + UCSWRST; // CLOCK = SMCLK,REGISTER IS RESET
UCA0BR0 = 109; // baud rate =9600
UCA0BR1 = 0;
UCA0MCTL = UCBRS_1; // Modulation value = 1
// UCA0STAT |= UCLISTEN; // loop back mode enabled
UCA0CTL1 &= ~UCSWRST; // Clear UCSWRST to release USCI_A0 for operation
IE2 |= UCA0TXIE + UCA0RXIE; // Enable the Transmit interrupt
_BIS_SR(GIE); // Enable the global interrupt
UCA0TXBUF = 'M'; // Transmit a byte
}


#pragma vector = USCIAB0TX_VECTOR
__interrupt void TXInterrupt(void)
{
P1OUT ^= BIT0;//light up P1.0 Led on Tx
}

#pragma vector = USCIAB0RX_VECTOR
__interrupt void RXInterrupt(void)
{
P1OUT ^= BIT6; // light up P1.6 LED on RX
}

Any suggestions?

Thank you,

Regards,

  • Hello th133,

    Thank you for posting this question. After looking over your code I noticed that your baud rate is not correct with your frequency of 1MHz. Try using the following code:

    UCA0BR0 = 104; // baud rate =9600

    Your original code works for the default frequency of the microcontroller but not when you change it. Another thing that I noticed is that the end of main should contain a forever while loop while(1); to keep the function from ending. This is so that your microcontroller knows what state it needs to be in.

    Let me know if this fixes your problem.

    Regards,
    Travis Black
    Apps Engineer
  • Hello Travis,
    Thank you for the correction. It works now !

    Regards,

**Attention** This is a public forum