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.

UART Send Byte 9600 Baud - MSP430G2553

I have this code, but it's not working:

void configUART()
{
   UCA0CTL1 &= ~UCSWRST; // stop software reset of uart
   UCA0CTL0 = 0x00; // default mode...8 data bits, 1 stop //bit, async
   UCA0CTL1 |=	BIT7; //SMCLK, which is set to 16MHz
   // for baud of 9600 we want prescalar = 1666; that's //130 + 6*256
   UCA0BR1 = 0x06; // 6
   UCA0BR0 = 0x82; // 130
   UCA0MCTL = 0x0C; // UCBRSx = 6
   P1DIR |= BIT2; // select output pin
   P1SEL |= BIT2;	// choose UART option for pin
   P1SEL2 |= BIT2;
}

I then have a while loop, and in it I set UCA0TXBUF = 0x55; However nothing is showing on the terminal program (putty). I selected the right COM port (10) and the correct baud rate (9600).

  • did you de-activate the uart reset? I do not see it at the end of the config routine?

  • To configure an USCI you should first SET the software reset, configure your module and then release it from software reset. You do not show your whole code, just the init of the UART. But a while loop, sending 0x55 all the time is a bad idea, you should at least check the flag for a free buffer before writing new data to it.

    From your prescaler I assume that you are clocking the device with 16MHz?

    Your config seems to be OK, but the reset is handled wrong:

    void configUART( void )
    {
      P1SEL    |=  0x04;
      P1SEL2   |=  0x04;
    
      UCA0CTL1  =  UCSWRST;
      UCA0CTL0  =  0x00;
      UCA0CTL1 |=  UCSSEL_2;
      UCA0BR0   =  130;
      UCA0BR1   =  6;
      UCA0MCTL  =  UCBRS_6;
      UCA0CTL1 &= ~UCSWRST;
    }

    There is no need to configure P1.2 as an output - this is done by the USCI.

    And in your main-loop, do the following:

    while( 1 )
    {
      while( !(IFG2 & UCA0TXIFG) );
      UCA0TXBUF = 0x55;
    }

    But as mentioned before, maybe the problem is somewhere else in your code. Maybe you should provide us the whole code. Btw: Doesn't your compiler tell you anything because of a missing type inside your brackets of configUART()?

    Dennis

  • Hey, thanks for replying. No, my compiler says nothing about not include (void) in my function.

    Anyways, I tried your code, including the polling in the while loop, but it still didn't work. So here's all the relevant code.

    inline void configSubMainClock16MHz()
    {
    	BCSCTL1 = CALBC1_16MHZ;
    	DCOCTL = CALDCO_16MHZ;
    	BCSCTL2 &= ~SELS;
    }
    
    void configUART( void )
    {
      P1SEL    |=  0x04;
      P1SEL2   |=  0x04;
    
      UCA0CTL1  =  UCSWRST;
      UCA0CTL0  =  0x00;
      UCA0CTL1 |=  UCSSEL_2;
      UCA0BR0   =  130;
      UCA0BR1   =  6;
      UCA0MCTL  =  UCBRS_6;
      UCA0CTL1 &= ~UCSWRST;
    }
    
    void main(void)
    {
        WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
        configSubMainClock16MHz();
        configUART();
    
        _BIS_SR(GIE); // enable global interrupts
        while(1)
        {
        	while(IFG2 & UCA0TXIFG)
        		UCA0TXBUF = 0x55;
        }
        
    }

    This is using the function you provided. Also, I know for a fact the my SMCLK is 16MHz, because I was using it earlier for PWM generation and it was confirmed using an oscilloscope.

    Thanks again for your help.


    EDIT: Now that I think about it, the SMCLK was never confirmed to be 16MHz. That was something else. So if the problem is in the SMCLK, do let me know. Thanks.

    EDIT2: I just realized I omitted the negation "!" from my while loop while polling. I corrected the mistake, but still no received bytes on the terminal.

    EDIT3: I'm so stupid. I just realized I had to reorient the jumpers on the launchpad to allow hardware UART. Thanks for the help!

**Attention** This is a public forum