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.

printf support for CCSv6 - garbage on monitor

Other Parts Discussed in Thread: CCSTUDIO, MSP-EXP430F5529LP, MSP430F5529, TUSB3410

Hello,

I am using the MSP-EXP430F5529 evaluation kit.   I am also using CCS v6.2

i want to print a number of messages to the UART RXD line for debug and general system information.  I have followed the instructions on the IT wiki page.  Printf_support_for_MSP430_CCSTUDIO_compiler.  ( I would love to post a link but this apparently cannot be done on this forum...weird)

The issue I have is that I see garbage on my putty monitor.    I have configured the putty to the right com port and set the baud rate to 1200.  I double check the baud rate using a calculator on ti so I am confident that UCA1BRO = 27 and UCA1BR1 = 0.

The data coming out is total garbage, but there is data.

Here is my code...again taken straight from the ti website.  the only thing I changed was the UCA1 UART RXD and TXD port to reflect the MSP-EXP430F5529LP evaluation board.

______


#include <stdint.h>
#include <MSP430F5529.h>
#include <stdio.h>
#include <string.h>

#define UART_PRINTF

#ifdef UART_PRINTF                                    //setup to have print statements on serial RFD port
int fputc(int _c, register FILE *_fp);                //see processors.wiki.ti.com/.../Printf_support_for_MSP430_CCSTUDIO_compiler
int fputs(const char *_ptr, register FILE *_fp);
#endif

void main(void){

    unsigned int counter=0;
    WDTCTL = WDTPW+WDTHOLD;                     // Stop watchdog timer

    init_serialprint();                            // chris - printf setup


    while(1)                                    //Printf task
    {
      __bis_SR_register(LPM3_bits+GIE);       // Enter LPM3, enable interrupts
      printf("Hello world %d!\r\n", counter++);
    }
}

init_serialprint()
{
        //code copied from processors.wiki.ti.com/.../Printf_support_for_MSP430_CCSTUDIO_compiler
      // 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
      P4SEL |= BIT4 + BIT5;                             // P4.4,5 = USCI_A1 TXD/RXD                 Changed to accommodate MSP-EXP430F5529LP
      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
}

// 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

  • Hi Chris,

    Thanks for posting - hopefully we can drive this to a quick conclusion.

    As a note - you should be able to post links, they just will not turn into a hyperlink until you submit from the standard editor (as long as they start with http://....). Or, you can click "Use rich formatting" at the bottom right when you are posting to get the rich editor which will have more options for inserting hyperlinks etc.

    To clarify, are you using the MSP-EXP430F5529 Experimenter board (a white board with an LCD on it), or the MSP-EXP430F5529LP Launchpad board (red board)? The reason I'm asking is because on the white MSP-EXP430F5529 experimenter board, I believe that the TUSB3410 that is connecting the MSP430 UART to the PC only supports a fixed rate of 9600 baud. If you are using the white experimenter board, try changing your code and Putty to use 9600 baud and see if that works.

    If you are using the red Launchpad, the UART connection on that board should support multiple baud rates. I'm continuing to look into your issue and will try to reproduce on the Launchpad board.

    Regards,
    Katie
  • Hi Chris,

    I tried out your code on an MSP-EXP430F5529LP Launchpad. I saw similar behavior at 1200 baud - using a terminal program that can display hex, I was always getting 0x80. I also found the same behavior if I use the UART interface directly without printf. When I changed the USCIA1 setup to use 9600 baud, suddenly everything started working. I'm wondering if maybe there is an issue with the backchannel UART hardware support for interfacing with the PC on the MSP-EXP430F5529LP at such a low baud rate even though that Launchpad supports multiple baud rates. Looking at www.ti.com/.../slau647 the table 9 only goes down to 4800 baud - I will ask with our tools team if they know of any problem using a lower baud rate with the hardware on the Launchpad.

    For now, I'd recommend simply changing to 9600 baud. You can find a list of Baud rate settings in the user's guide www.ti.com/.../slau208 section 36.3.13 Typical Baud Rates and Errors. Right near the beginning of the table you'll see the settings for using 9600 baud from a 32768 source.

    To be clear, if this is the issue, what it means is that the hardware on the Launchpad that translates between the MSP430 UART signals and the PC is where the issue is, not with the UART or code on the MSP430 itself (therefore you'd be able to communicate with another device connected directly to the UART pins for example even if you're having these PC issues).

    Regards,
    Katie
  • Thanks Katie,

    I am using the Red LaunchPad board for the MPS-430F5529LP. Rev 1.6.

    I changed the divider values

    UCA1BRO = 3;
    UCA1BR1 = 3;

    The I chnage dthe putty to 9600 . However the issue remains.

    On another note....I was able to use the UART exampe for the MSP430F552x C examples found on the MSP430F5529 webpage. Inside this folder there is a UART example. The file is MSP430F55xx_uscib0_uart_04.c

    Apparently some readers believe this is a better way to code the UART channel instead of using PrintF.

    It would be great if you could revise the document for how to use printf as it is a little old, fix your hardware issues and maybe even improve this feature so it is easier to impliment. a module would be awesome.

    In anycase, I have been able to move on using the uart example. So I am good.
  • Chris from Pinterec said:
    It would be great if you could revise the document for how to use printf as it is a little old, fix your hardware issues and maybe even improve this feature so it is easier to impliment. a module would be awesome.

    No, this is not awesome. There is mailbox system, perfect solution for MSP430x5xx logging. No extra pins / wires, no clock setup, no chance for garbage on monitor. But TI didn't implemented (yet) this feature on FET's. 

  • Hi Chris,

    We do in general recommend to use UART without printf as it is more efficient - so that is a better way to go that you are using now.

    However I do also want to point out for 9600 baud, in addition to setting UCA1BR0 = 3, UCA1BR1 = 0, and UCBRSx = 3. Not sure if that was a typo in your post and you actually set it correctly, or maybe an oversight in your code, but this setting worked correctly for me when I tested on the Launchpad board with printf and a terminal program (I used Docklight, but that shouldn't matter).

    I'm still waiting for an answer on whether there are any limitations on lower end baud rates below 9600 on the F5529 Launchpad which has eZ-FET lite and I'll update the thread when I get an answer.

    Regards,
    Katie
  • YA.... UCBRSx is not defined in the example. When I add it to the if statement it just give me an error. Rightly so... As it is undefined. I am looking at section 36.3.13. Table 36-5 of SLAU208O and this is unclear how to implement it. Do I need to write it as USA1BRSx or is it just UCBRSx?

    I tried both...but both versions did not compile.

    Here is the code again.... Straight from the website.

    #include <MSP430F5529.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
    P4SEL |= BIT4 + BIT5; // P4.4,5 = USCI_A1 TXD/RXD
    UCA1CTL1 |= UCSWRST; // **Put state machine in reset**
    UCA1CTL1 |= UCSSEL__ACLK; // AMCLK
    UCA1BR0 = 3; // 32,768kHz 1200 (see User's Guide), original example used 27, set to 3 for 9600
    UCA1BR1 = 0; // 32,768kHz 1200, original example used 0, set to 3 for 9600
    UCBRSx = 3; // This is just give me an error as it is undefined.!
    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("Hello world %d!\r\n", counter++);
    }
    }

    // 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
  • Hi Chris,

    I realize now that probably caused some confusion: UCBRSx refers to the UCBRS bitfield within the UCA1MCTL register - the x is because this is multiple bits wide bitfield. See the 5xx user's guide www.ti.com/.../slau208 Figure 36-16 and Table 36-11 UCAxMCTL Register Description, where you'll see the bitfield UCBRSx is defined.

    Actually your code already sets this bitfield - see the line where you have:
    "
    UCA1MCTL = UCBRS_2; // 32,768kHz 1200
    "
    So instead of adding a line that's UCBRSx = 3, what you need to do is change this existing line where you set UCA1MCTL to be:
    "
    UCA1MCTL = UCBRS_3; // 32,768kHz 9600
    "
    That is setting the bitfield UCBRSx within the UCA1MCTL register so that UCBRSx = 3 (you use this UCBRS_3 definition because UCBRSx is not the lowest bit so writing 3 is actually writing 6 to the UCA1MCTL register due to bit offsets).

    I hope that this helps to clear things up.

    Regards,
    Katie

**Attention** This is a public forum