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.

MSP430F5438A: using the MSP430F5438A printf example: Rerouting printf() output to UART

Part Number: MSP430F5438A
Other Parts Discussed in Thread: MSP-FET,

I am using MSP430F5438A inserted in MSP-TS430PZ5X100. And using MSP-FET for JTAG debugging on CCSv7. 

I have not soldered any external oscillator to the board, hence using internal oscillator.

I am using the following code copied from MSP430 rerouting printf example over UART:

The code is taken from http://processors.wiki.ti.com/index.php/Printf_support_for_MSP430_CCSTUDIO_compiler

I am trying to send "J" over UART to desktop Reaterm using FTDI USB to UART cable. I have connected the Ground, RX and TX pins.

But I am receiving a two junk character 0x2D 0x00 for every character of "J" sent.

Also when trying to use printf("Hello world"); then I am receiving 0xAB 0x3A 0x3A 0x0A 0xFA 0x8B 0x0A 0xDA 0x3A 0xBA 0x02 0x00.

I am using an oscilloscope to tap the UART signals.

What can be the possible problem in the code or the hardware set up which leads to the problem.

#include "msp430x54xA.h".
#include <stdio.h>
#include <string.h>

#define UART_PRINTF

#ifdef UART_PRINTF
int fputc(int _c, register FILE *_fp);
int fputs(const char *_ptr, register FILE *_fp);
#endif

void main(void)
{
  unsigned int counter=0;
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT

  // initialize clock module
  P1DIR |= 0x01;                            // P1.0 output
  UCSCTL3 |= SELREF__REFOCLK;
  UCSCTL4 |= SELA__REFOCLK;

  // initialize Timer_A module
  TA1CCTL0 = CCIE;                          // CCR0 interrupt enabled
  TA1CCR0 = 32768;
  TA1CTL = TASSEL__ACLK + MC__UP + TACLR;   // ACLK, up mode, clear TAR

#ifdef UART_PRINTF
  // initialize USCI module
  P5SEL |= BIT6 + BIT7;                     // P5.6,7 = USCI_A1 TXD/RXD
  UCA1CTL1 |= UCSWRST;                      // **Put state machine in reset**
  UCA1CTL1 |= UCSSEL__ACLK;                 // AMCLK
  UCA1BR0 = 27;                             // 32,768kHz 1200 (see User's Guide)
  UCA1BR1 = 0;                              // 32,768kHz 1200
  UCA1MCTL = UCBRS_2;                       // 32,768kHz 1200
  UCA1CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
#endif

  while(1)
  {
    __bis_SR_register(LPM3_bits+GIE);       // Enter LPM3, enable interrupts
    printf("J");
  }
}

// Timer A0 interrupt service routine
#pragma vector=TIMER1_A0_VECTOR
__interrupt void TIMER1_A0_ISR(void)
{
  P1OUT ^= 0x01;                            // Toggle P1.0
  __bic_SR_register_on_exit(LPM3_bits);
}

#ifdef UART_PRINTF
int fputc(int _c, register FILE *_fp)
{
  while(!(UCA1IFG&UCTXIFG));
  UCA1TXBUF = (unsigned char) _c;

  return((unsigned char)_c);
}

int fputs(const char *_ptr, register FILE *_fp)
{
  unsigned int i, len;

  len = strlen(_ptr);

  for(i=0 ; i<len ; i++)
  {
    while(!(UCA1IFG&UCTXIFG));
    UCA1TXBUF = (unsigned char) _ptr[i];
  }

  return len;
}
#endif
  • Dividing down the 32 kHz clock for 1200 baud results in quite large errors, and the default REFO clock is not too accurate to begin with.

    Try using SMCLK instead. It's ultimately based on the same REFO clock, but the nominal 1048576 Hz frequency is easier to divide down to a baud rate without large errors. (For 1200 baud: BRW = 873, BRS = 7.)

    But for a really reliable UART, you need a precise clock source.

  • Hi Clemens,

    I have changed the code as per your suggestion. Still the characters received are same. Hence the problem persists.
    The MSP-TS430PZ5X100 target development board does come enclosed with 32.768 kHz Micro Crystal MS1V-T1K which needs to be soldered.
    Will it be precise enough or do I need to look for some other crystal?

    Thanks and Regards,
    Ankit
  • Any crystal or resonator will be precise enough. (But you need to change the software to start it.)
  • Hi Clemens,

    This is my first time working with MSP430 so I have quite a number of queries. Sorry in advance on bombing you with so many questions.

    I would like to clarify few things about the UCS operations in MSP430F5438A with respect to MSP-TS430PZ5X100 target development board.

    1. While reading the MSP430 Hardware Tools User's Guide (SLAU278Y), I came across . MSP-TS430PZ5x100 Bill of Materials. It mentions the two external crystals Q1 and Q2 as DNP. Furthermore the capacitors C1, C2, C3, C4 and Resistors R6, R8, R9,R12 are also DNP. Why are they DNP? What exactly DNP stands for?

    2. R6, R8, R9,R12 are all 0 ohms, what is the use of 0 ohms resistor?

    While reading the Unified Clock System (UCS) section in MSP430x5xx and MSP430x6xx Family User's Guide SLAU208P, I came across the following paragraph:
    "The XT1 oscillator supports ultra-low-current consumption using a 32768-Hz watch crystal in lowfrequency
    (LF) mode (XTS = 0). A watch crystal connects to XIN and XOUT without any other external
    components. The software-selectable XCAP bits configure the internally provided load capacitance for the
    XT1 crystal in LF mode. This capacitance can be selected as 2 pF, 6 pF, 9 pF, or 12 pF (typical).
    Additional external capacitors can be added if necessary."

    3. Does that mean if i select software-selectable XCAP as 12pF from software then I don't need to use the external capacitor C1 and C2?

    4. Can I connect a function generator to provide an external clock signal on the XIN pin by setting XT1BYPASS?

    5. MSP-TS430PZ5X100 target development board comes enclosed with 32.768 kHz Micro Crystal MS1V-T1K. But on the sachet containing the oscillator it is mentioned that "For a more accurate timing, this TI-MSP430 has the option to connect a quartz crystal unit". Does that mean MS1V-T1K is still not precise enough?

    6. Any recommendations for high frequency quartz crystals that can be used with MSP430F5438A, for 22.1184MHz or 20 MHz?

    7. I am able to make SPI work properly but I am not able to make UART work, does the oscillator play bigger role in baud rate as compared to SPI serial clock?

    Sorry once again for asking a lot of questions.

    Thanks and Regards,
    Ankit
  • DNP = Do Not Place; these components can be soldered in later, if needed.

    0Ω resistors can be unsoldered, if you do not want that connection.

    The internal capacitance indeed can replace external capacitors.

    XT1BYPASS disables the oscillator feedback circuit, so that XIN must get an external digital clock signal.

    "More accurate" means "more accurate than without any crystal".

    SPI is synchronous, i.e., there is a separate line for the master's clock signal. The actual frequency does not matter for the slave.
  • Hi Clemens,

    Thanks a lot for your replies. I have solved the UART printing problem.
    It was a silly FTDI cable mistake. I was using the USB to RS232 cable and I was directly connecting the RS232 pins to the UART pins of the microcontroller., which was causing the problem. I used the FTDI basic breakout - 3.3v and it solved the problem.

    But in the process I have learnt a lot about external crystals and internal oscillator as well.

    Thanks for guiding me :)

    Thanks and Regards,
    Ankit
  • BTW, there is more simple approach for 5xx logging, unfortunately not supported by TI FET's. Mailbox system can be used for this, without any clock setup, and any extra lines / pins / glue logic.

    mailbox.zip

  • Thanks Zrno Soli for the info. I will surely check it out _/\_

**Attention** This is a public forum