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.

MSP430 Baud Rate measuring

Other Parts Discussed in Thread: MSP430F149

Hi all,

I am using an MSP430F149 . I am connecting serially to a RN-41 Bluetooth transceiver.  The baud rate desired for the communication is 9600.  I checked out pretty much every table and baudrate calculator out there and got to the point that for the USART module to work at 9600 I need:

 

UBR00=0x6D; UBR10=0x00; UMCTL0=0x44;

However, when I work with this settings, the data sent is  incorrect. I start receiving different  characters from the ones that I am sending.  I had to work with the following settings to make it work ok:
UBR00=0x55; UBR10=0x00; UMCTL0=0x03;
Which I got from randomly changing the values until it worked.


What I want to know is a way to measure the tx/rx to make sure that the baud rate is set ok on the controller.

thanks in advance for any help
-sednus

 

  • You can hookup an oscilloscope to watch the waveform of TXD. It should be normally high. When you send the ASCII upper case U (0x55), you should see 5 negative pulses. If the bit-rate is 9.6 kb/s, the pules widths and spaces between them should all be 1/9.6=0.1042 msec. But because of "modulation", some of them will be longer while others are shorter.You should aim at getting the transitions to be close to: 0, 0.10432, 0.2083,  0.3125,  0.4167, 0.5208, 0.6250, 0.7292, 0.8333, 0.9375 msec.

  • Do you have a scope?

    If so connect one probes on tx channel and put a trigger on its falling edge, one shot mode.

    Then send a character from one side to the other, say U (capital u), which binary representation is 01010101, and you should see a corresponding square wave on the tx channel and calculate your baudrate.

    Regards.

     

    Peppe

  • This sounds a lot like the MSP is not running at the frequency you're guessing it to run on (I'm assuming the RN-41 works fine as it's an external module). So maybe the first thing to look for is the correct clock frequency. If you can, try to output the clock you are sourcing the USART from at one of the pins and measure it with an oscilloscope/frequency counter.

    Your first line indicates a clock frequency of around 1MHz whereas your empirical values indicate a frequency of  only ~800kHz. So if your processor is running at 800kHz instead of 1MHz, the communication will of course fail (20% error).

  • Hello ,

    As I see from your setting for 9600 baudrate, there is someting not correct. For MSP430 UART Baudrate at 9600, the setting should be below:

    9600 baud:

    ACLK = 32768 Hz

    Prescaler = 32768Hz/9600baud = 3.41

    UxBR1 | UxBR0 | UxMCTL =  00h | 03h | 4Ah

    Please look at the section 13-16 from http://www.ti.com/litv/pdf/slau049f there is an table to sett the baudrate.

    Please see below an example code:

    //******************************************************************************

    // MSP-FET430P140 Demo - USART0, Ultra-Low Pwr UART 9600 Echo ISR, 32kHz ACLK

    //

    // Description: Echo a received character, RX ISR used. In the Mainloop UART0

    // is made ready to receive one character with interrupt active. The Mainloop

    // waits in LPM3. The UART0 ISR forces the Mainloop to exit LPM3 after

    // receiving one character which echo's back the received character.

    // ACLK = UCLK0 = LFXT1 = 32768, MCLK = SMCLK = DCO~ 800k

    // Baud rate divider with 32768hz XTAL @9600 = 32768Hz/9600 = 3.41 (0003h 4Ah )

    // //* An external watch crystal is required on XIN XOUT for ACLK *//

    //

    // MSP430F149

    // -----------------

    // /|\| XIN|-

    // | | | 32kHz

    // --|RST XOUT|-

    // | |

    // | P3.4|----------->

    // | | 9600 - 8N1

    // | P3.5|<-----------

    //

    //

    // M. Buccini

    // Texas Instruments Inc.

    // Feb 2005

    // Built with CCE Version: 3.2.0 and IAR Embedded Workbench Version: 3.21A

    //******************************************************************************

    #include <msp430x14x.h>

    void main(void)

    {

    WDTCTL = WDTPW + WDTHOLD; // Stop WDT

    P3SEL |= 0x30; // P3.4,5 = USART0 TXD/RXD

    ME1 |= UTXE0 + URXE0; // Enable USART0 TXD/RXD

    UCTL0 |= CHAR; // 8-bit character

    UTCTL0 |= SSEL0; // UCLK = ACLK

    UBR00 = 0x03; // 32k/9600 - 3.41

    UBR10 = 0x00; //

    UMCTL0 = 0x4A; // Modulation

    UCTL0 &= ~SWRST; // Initialize USART state machine

    IE1 |= URXIE0; // Enable USART0 RX interrupt

    // Mainloop

    for (;;)

    {

    _BIS_SR(LPM3_bits + GIE); // Enter LPM3 w/interrupt

    while (!(IFG1 & UTXIFG0)); // USART0 TX buffer ready?

    TXBUF0 = RXBUF0; // RXBUF0 to TXBUF0

    }

    }

    // UART0 RX ISR will for exit from LPM3 in Mainloop

    #pragma vector=USART0RX_VECTOR

    __interrupt void usart0_rx (void)

    {

    _BIC_SR_IRQ(LPM3_bits); // Clear LPM3 bits from 0(SR)

    }

     

    Best Regards

    Yunus

     

  • Thanks I'll try it out

  • It worked fine now, thanks a lot guys!

    Wilberto Lopez said:

    Thanks I'll try it out

     

**Attention** This is a public forum