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.

CCS/MSP430F5529: Receiving garbage values on terminal software (Teraterm)

Part Number: MSP430F5529


Tool/software: Code Composer Studio

Hello,

I am trying to print a string on Teraterm terminal via P4.4 & P4.5 UART of MSP430F5529LP. I am printing the string only once and just to test it I have not put my code in infinite loop. The issue is I am receiving garbage values continuously after I have received the string once on Teraterm.

These are the garbage values I am receiving after the string:

The baudrate on the terminal and configuration code is the same(i.e., 115200). When I am putting the breakpoint in the function and checking the main code using step in debugging, the code works fine and I do not receive any garbage value except the string. It is when I run the code without the breakpoint I am receiving garbage values after the string. I also checked the last value in UCA1TXBUF register, which is the last value of the string character transmitted. 

The below "printstring" function is what I have written for passing the string:

void printstring(char *buff,char length)
{
	  int i;
	  for(i=0;i<length;i++,buff++)
	  {
		while (!(UCA1IFG&UCTXIFG));
		UCA1TXBUF = *buff;
	  }
}

The following is the initialization code of UART I am using:
void initUART()
{
  P4SEL |= BIT5+BIT4;                       // P3.3,4 = USCI_A0 TXD/RXD
  UCA1CTL1 |= UCSWRST;                      // **Put state machine in reset**
  UCA1CTL1 |= UCSSEL_2;                     // SMCLK
  UCA1BR0 = 9;                              // 1MHz 115200 (see User's Guide)
  UCA1BR1 = 0;                              // 1MHz 115200
  UCA1MCTL |= UCBRS_1 + UCBRF_0;            // Modulation UCBRSx=1, UCBRFx=0
  UCA1CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
}

The below is the main code I am testing:

#include <msp430f5529.h>
#include "UART.h"
int main(void) { initUART(); __asm("NOP"); printstring("Hello",5); }

Would be great if someone can help me on this.

Thanks
  • Hi,

    First please try removing the JP6.1 and JP6.2 jumpers (which will disconnect the backchannel UART) and see if that fixes your issue.

    Regards,
    Nathan
  • Hello Nathan,

    Thanks for your quick response. I tried removing the JP6.1 and 6.2 jumpers but that is not even printing the string at all. The data is not passing to the PC on removing the jumpers.
  • Hi,

    Sorry, I misread your original description. You will need to put those jumpers back. Your initialization code looks correct, and if the last value in the UCA1TXBUF is the last value you are intending to transmit, then it does not look like the MSP430 is transmitting any other characters. Have you tried another serial terminal? It is possible that this is an issue on TeraTerm's side.

    Regards,
    Nathan
  • Hello Nathan,

    It certainly does not look like MSP430 is transmitting character as I even tried putting it into low power mode after transmitting the characters and still receiving those garbage values. Tried other terminals such as docklight and realterm which also gives the same results. The settings on tera term side also seems fine and list no such options of checking these garbage values. 

    The code is going into an infinite for loop of the abort function as shown below, when I have run the code for sometime and paused it when garbage values are being printed. Doing a step over debugging, does not take the code into abort function.

  • Hi,

    To not get into the abort function, make sure that you include an empty while(1) loop at the end of main(). With your current code, it is hitting the end of main() in active mode, and getting lost in a weird state. It is possible that this state is causing voltage fluctuations or something similar on the serial communication pins, so please try including the while(1) loop and see if that fixes the issue.

    Regards,
    Nathan
  • Hi,

    Did this resolve your issue? If so, please mark it as answered. If no response soon, this thread will be closed due to inactivity.

    Regards,
    Nathan
  • Hi Nathan,

    Apologies for not replying as I was held up in some other work. I tried putting infinite loop at the end which also bears the same result. The settings on the terminal window seems fine.
  • Hi,

    I am starting to wonder if this is a board issue, as the description you have given should not be causing this issue. Could you please try disabling the USCI (UART) module (UCA1CTL1 |= UCSWRST;) in your code after you have printed the string and see if you still see the garbage bytes?

    Also, could you please set your terminal to print the hex values so we can see what garbage bits are actually being printed? Hopefully this can give us a sense of what is actually going on.

    Regards,
    Nathan
  • Hello Nathan,

    I was also wondering the same. I tried putting a while(1) and also disabled the UART module, but I can still see the garbage bytes being printed.

    These are the following bytes (in hexadecimal ) being printed on the teraterm terminal. The initial five bytes are the"Hello" string bytes. The following are the garbage bytes which are not following any particular pattern.

    I was wondering if its a terminal software issue. Hence I tried printing it on a different terminal software (i.e., Docklite) which is again printing the same values as shown below:

    I started thinking if it was a launchpad issue and changed the launchpad but to no gain. The same values are being printed on a different board as well.

  • Hi,

    Based on what you have ruled out I took a look at your code again and I discovered something that may be an issue. The following line may be causing the issue:

    UCA1MCTL |= UCBRS_1 + UCBRF_0;

    Please try changing this to the following:

    UCA1MCTL |= UCBRS_4 + UCBRF_0;

    I think you may have had the wrong modulation value. Please try this and let me know if it works.

    Regards,
    Nathan
  • Hi Nathan,

    I tried the solution you proposed but still getting the same result. From what I understand, I have not configured the clock system module and the  UART is sourcing the clock from SMCLK which is 1048576Hz by default.  Referring to the MSP430x5xx user guide, the UCBRS value mentioned against 1048576 BRCLK is 1, which refers to UCBRS_1.

    So I wonder if that is causing the issue. Although I checked the Tx pin (i.e., P4.4) on the scope and observed some noise in the wave instead of a clean logic high which should be the case for an idle level.

    Currently, I am travelling and will post the CRO waveform as soon as I reach office for you to analyze .

    Thank you for your active participation in trying to solve the problem Nathan.

  • Hi,

    Has there been an update with this issue?

    Regards,
    Nathan
  • Easy:

    1. Start with an accurate and known clock. Xstal is the day to do, though sometimes the internal rc clock works as we.. beware of their accuracy. I once had a luminary part whose 12Mhz nominal clock runs at 9.6Mhz.

    2. Make sure that your baud rate And other parameters of the module are set right. Not made to start with majic numbers.

    3. Test your tansmission / buffer to avoid overrun.

    4. Configure the uart pins.

    5. Makre sure your transmission buffer is sufficiently long.

    I would start with transmission known address.

    ...
  • here is my initialization code for F2xx series: not exactly identical to yours but hopefully with minor modifications it applies to your device: I took a quick scan and the two devices are quite similar.

    //reset uart0/eusci_a0
    void uart0_init(uint32_t bps) {
    	uint16_t brx;								//used for baud rate calculation, corresponds to BRx, BRFx, BRSx in the datasheet
    	uint8_t brfx, brsx;
    	uint8_t OS16;
    	uint32_t intN;
    	uint16_t fracN;								//N - INT(N), x 10000
    
    	//configure the pins
    #if defined(UART0_TX)
    	UART0_TX();
    #endif
    	
    #if defined(UART0_RX)
    	UART0_RX();
    #endif
    	
    	// Configure USCI_A0 for UART mode
    	UCAxCTL1 = (1<<0);							//EUSCI_A_CTLW0_SWRST;			//UCAxCTLW0 = UCSWRST;                      // Put eUSCI in reset
    	//UCAxCTLW0|= EUSCI_A_CTLW0_SSEL__SMCLK;	//UCAxCTLW0 |= UCSSEL__SMCLK;               // CLK = SMCLK
    	UCAxCTL0 = 		(0<< 7) |					//0->parity disabled, 1->parity enabled
    					(0<< 6) |					//0->odd parity, 1->even parity
    					(0<< 5) |					//0->lsb first, 1->msb first
    					(0<< 4) |					//0->8-bit data, 1->7-bit data
    					(0<< 3) |					//0->1 stop bit, 1->two stop bits
    					(0<< 1) |					//0->uart mode, 1->idle line multiprocessor mode, 1->address-bit multiprocessor mode, 3->uart mode with automatic baud rate detection
    					(0<< 0) |					//0->asynchronous mode, 1->synchronous mode
    					0x00;
    	UCAxCTL1 = 		(2<< 6) |					//0->uclk, 1->aclk, 2->smclk, 3->smclk
    					(0<< 5) |					//0->errornous characters rejected and ucrxifg is not set, 1->errorneous chararcters received ans set ucrxifg
    					(0<< 4) |					//0->received break character do not set ucrxifg, 1->received break characters set ucrxifg
    					(0<< 3) |					//0->not dormant. all received characters set ucrxifg, 1->dormant
    					(0<< 2) |					//0->next frame transmitted is data, 1->next frame transmitted is an address
    					(0<< 1) |					//0->next frame transmitted is not break; 1->next frame transmited is break;
    					(1<< 0) |					//0->reset disabled. usci reset released for operation. 1->hold usci in reset
    					0x00;
    	// Baud Rate calculation
    	// 8000000/(16*9600) = 52.083
    	// Fractional portion = 0.083
    	// User's Guide Table 21-4: UCBRSx = 0x04
    	// UCBRFx = int ( (52.083-52)*16) = 1
    
    	//see section 22.3.10 in the datasheet
    	//step 1
    	intN = F_UART / bps;
    	if (intN > 16) {
    		//step 3 - high frequency mode, 16 oversampling
    		OS16 = 1; brx = intN / 16; brfx = intN - (brx * 16); brsx = 0;
    	} else {
    		//step 2 - low frequency mode
    		OS16 = 0; brx = intN; brfx = 0; brsx = intN * 8 - (brx * 8);		//brfx ignored
    	}
    	//step 4 - optional
    	//fracN = (F_UART - intN * bps) * 10000ul / bps;
    	//brsx = 0;									//default to 0
    	//brx=104; brsx=1; brfx=0; OS16=0;
    #if 0
    	//look up brsx based on fracN
    	         if (fracN < ((   0 +  529) / 2)) brsx = 0x00;
    	 	else if (fracN < (( 529 +  715) / 2)) brsx = 0x01;
    		else if (fracN < (( 715 +  835) / 2)) brsx = 0x02;
    		else if (fracN < (( 835 + 1001) / 2)) brsx = 0x04;
    		else if (fracN < ((1001 + 1252) / 2)) brsx = 0x08;
    		else if (fracN < ((1252 + 1430) / 2)) brsx = 0x10;
    		else if (fracN < ((1430 + 1670) / 2)) brsx = 0x20;
    		else if (fracN < ((1670 + 2147) / 2)) brsx = 0x11;
    		else if (fracN < ((2147 + 2224) / 2)) brsx = 0x21;
    		else if (fracN < ((2224 + 2503) / 2)) brsx = 0x22;
    		else if (fracN < ((2503 + 3000) / 2)) brsx = 0x44;
    		else if (fracN < ((3000 + 3335) / 2)) brsx = 0x25;
    		else if (fracN < ((3335 + 3575) / 2)) brsx = 0x49;
    		else if (fracN < ((3575 + 3753) / 2)) brsx = 0x4a;
    		else if (fracN < ((3753 + 4003) / 2)) brsx = 0x52;
    		else if (fracN < ((4003 + 4286) / 2)) brsx = 0x92;
    		else if (fracN < ((4286 + 4378) / 2)) brsx = 0x53;
    		else if (fracN < ((4378 + 5002) / 2)) brsx = 0x55;
    		else if (fracN < ((5002 + 5715) / 2)) brsx = 0xaa;
    		else if (fracN < ((5715 + 6003) / 2)) brsx = 0x6b;
    		else if (fracN < ((6003 + 6254) / 2)) brsx = 0xad;
    		else if (fracN < ((6254 + 6432) / 2)) brsx = 0xb5;
    		else if (fracN < ((6432 + 6667) / 2)) brsx = 0xb6;
    		else if (fracN < ((6667 + 7001) / 2)) brsx = 0xd6;
    		else if (fracN < ((7001 + 7147) / 2)) brsx = 0xb7;
    		else if (fracN < ((7503 + 7861) / 2)) brsx = 0xbb;
    		else if (fracN < ((7861 + 8004) / 2)) brsx = 0xdd;
    		else if (fracN < ((8004 + 8333) / 2)) brsx = 0xed;
    		else if (fracN < ((8333 + 8464) / 2)) brsx = 0xee;
    		else if (fracN < ((8464 + 8572) / 2)) brsx = 0xbf;
    		else if (fracN < ((8572 + 8751) / 2)) brsx = 0xdf;
    		else if (fracN < ((8751 + 9004) / 2)) brsx = 0xef;
    		else if (fracN < ((9004 + 9170) / 2)) brsx = 0xfb;
    		else if (fracN < ((9170 + 9288) / 2)) brsx = 0xfd;
    		else                                  brsx = 0xfe;
    #endif
    
    	UCAxBR0=brx;								//LSB
    	UCAxBR1=brx>>8;								//MSB
    	//UCAxBR0 = 52;                             // 8000000/16/9600
    	//UCAxBR1 = 0x00;
    	//UCAxMCTLW |= UCOS16 | UCBRF_1;
    	UCAxMCTL = 		((brfx & 0x0f) << 4) |		//ucbrsx: 2nd modulation stage select
    					((brsx &  0x07) << 1) |		//first modulation stage select
    					(OS16<<0) |					//0->oversampling disabled, 1->oversampling enabled
    					0x00;
    	//the above doesn't work
    	//following works
    	//UCAxBRW=0x0001;							//works at 3Mhz
    	//UCAxMCTLW = 0x00a1;
    
    	//UCAxCTLW1 = 	(3<< 0) |					//0->deglitch = 2ns, 1->deglitch = 50ns, 2->deglitch = 100ns, 3->deglitch = 200ns
    	//				0x00;
    
    	//UCAxIE |= UCRXIE;                         // Enable USCI_A0 RX interrupt
    	UCAxIFG &=~(UCAxTXIFG | UCAxRXIFG);			//clear all flag
    	UCAxIE  &=~(UCAxTXIE  | UCAxRXIE);				//disable all interrupts
    
    	//UCAxCTLW0 &= ~UCSWRST;                    // Initialize eUSCI
    	UCAxCTL1&=~(1<<0);							//0->release reset, 1->enable reset
    }
    

    My sending program looks like this:

    		//print uRAM to uart0/2
    		if (!uart0_busy()) uart0_puts(uRAM);
    

    In comparison, your problem looks like either inaccuracy frequency / baud rate, or buffer overrun.

  • btw, my code came from a MSP432 and then FR5969 so lots of it was commented out.

**Attention** This is a public forum