MSP430 Launchpad Baud Rate: Understanding UCA0BR0, UCA0BR1 and UCA0MCTL

Hi all,

I am currently trying to use the MSP430G2553 (Launchpad) to send data to the PC using UART. Using the example code provided (below), I was able to do this with a clock of 1MHz. However, I am trying to use a clock of 16MHz and I am not sure what to do, I know how UCA0BR0 is calculated, but 16000000/9600 = 1667 which causes truncation in UCA0BR0.

Can someone explain to me how to get the 9600 Baud Rate with a 16MHz clock instead of a 1MHz clock? Is the UCA0BR1 value for when UCA0BR0 overflows? Also how does UCA0MCTL work, as I cannot find any useful help with setting that value in software from the user guides. Are there any other variables that I would need to set for using this 16MHz clock?

void main(void)

{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
BCSCTL1 = CALBC1_1MHZ; // Set DCO
DCOCTL = CALDCO_1MHZ;
P1SEL = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
P1SEL2 = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
UCA0CTL1 |= UCSSEL_2; // SMCLK
UCA0BR0 = 104; // 1MHz 9600
UCA0BR1 = 0; // 1MHz 9600
UCA0MCTL = UCBRS0; // Modulation UCBRSx = 1
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
IE2 |= UCA0RXIE; // Enable USCI_A0 RX interrupt

__bis_SR_register(LPM0_bits + GIE); // Enter LPM0, interrupts enabled
}

// Echo back RXed character, confirm TX buffer is ready first
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{
while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready?
UCA0TXBUF = 'z';
}

Thanks,

Matt

18 Replies

  • Yes, UCA0BR1 is the "overflow" of UCA0BR0. Hence 1667 is split into UCA0BR1 = 6; and UCA0BR0 = 131;

    (6*256 + 131) = (1536 + 131) = 1667

    This and the details of UCA0MCTL are described in the User's Guide slau144i.pdf Chapter 15

  • Here is tool that you can use for calculation...

    http://forum.43oh.com/topic/2640-uart-configurator

  • In reply to old_cow_yellow:

    Hi,

         Can you please elaborate how exactly are you splitting and coming to the conclusion that we have to feed the values 131 and 6 respectively.  general calculation would be 8M/9600= 833. So how exactly are we splitting it with UCABR1 and UCABRO register?? 

  • In reply to Deepak kalalbandi:

    Deepak kalalbandi

    Hi,

         Can you please elaborate how exactly are you splitting and coming to the conclusion that we have to feed the values 131 and 6 respectively.  general calculation would be 8M/9600= 833. So how exactly are we splitting it with UCABR1 and UCABRO register?? 

    For 9600 bps at 8 MHz...
    8000000 / 9600 = 833.333
    833 dec = 0341 hex
    UCABR0 = 41 hex = 65 dec
    UCABR1 = 3
  • In reply to Deepak kalalbandi:

    Deepak kalalbandi
    So how exactly are we splitting it with UCABR1 and UCABRO register?? 

    UCABR0 and UCABR1 are low and high byte of a 16 bit value.

    If the value is decimal 833, its hexadecimal value would be 0x0314, so 0x14 goes to UCBR0 and 0x03 goes to UCBR1.

    For the remainder of 0.333, there is MCTL. It adds a pattern to UCBR(0/1) that makes the divider by 1 larger for some of the bits. Details and a formula are found in the users guide.
    Basically, if the first bit is too short (833 instead of 833.333 clock pulses) and the second is too short too, then the third has to be made longer (834 clock pulses) to keep the average baudrate. MCTL controls which bits have to be made longer by one clock cycle.

    _____________________________________

    Time to say goodbye - I don't have the time anymore to read and answer forum posts. See my bio for details.

    Before posting bug reports or ask for help, do at least quick scan over this article. It applies to any kind of problem reporting. On any forum. And/or look here.
    I'm sorry that  I can no longer provide help  in the forum or by private conversation.

  • In reply to Jens-Michael Gross:

    Thanks a lot Michael, i was worried about the remainder calculation. 

  • In reply to Jens-Michael Gross:

    You can even type cast the whole value directly and separate LSB and MSB and place it in the corresponding registers. 

  • Hi Matt,

    I'm a little confused about the relationship between baud rate and bit per second. Does 2400 baud rate means 2400bps for msp430 microcontrollers? Or assuming that my uart mode is set as 8-bit data and 2 stop bits, for this case, 2400 baud rate means 2400bps or 2400*10=24000bps?

    Thanks!

    Wang

  • In reply to user4215514:

    user4215514
    I'm a little confused about the relationship between baud rate and bit per second.

    You are not alone. They mean the same thing if the symbols used carry only one bit of information. Thus most people use these two terms interchangeably and unknowingly.

  • In reply to user4215514:

    Baud is related to gross bit rate expressed as bits per second.
    So it's not bytes/sec and as a uart byte uses 10bits only 240 chars per seconds shows up at the other end.