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/MSP430F5438A-EP: My UART communication code prints out nothing or '@' character with random time on the terminal

Part Number: MSP430F5438A-EP
Other Parts Discussed in Thread: MSP430F5438A

Tool/software: Code Composer Studio

Dear community members, 

Hi, I am a beginner of the TI board, MSP430F5438A, and now I am testing UART communication with UCA1, which is through USB.

I (thought I) configured out and set all the registers for the UART communication appropriately, so I launched the terminal that CCS provides with the settings I've made.

The settings I've made is written in the function 'halUsbInit()' which is in the code below, and I also have written some comments for you.

With the settings, I launched terminal with: Baud rate = 57600, Data bits =  7, Parity bits = NONE , Stop bits = 1, and Control Flow = NONE.

However, the problem is, the terminal prints out nothing when I run the code below, and the stranger thing is that it sometimes prints out '@' character!

Would you suggest me some cause or a solution for me?

What I have checked is:

UCA1TXBUF register and find it out that it stores the data I wanted finely.

Register value by printing them out on LCD to check if it was modified finely --> was OK.

Thank you very much for your time.

void halUsbInit(void)
{
unsigned char i;

for (i = 0; i < 255; i++)
   halUsbReceiveBuffer[i] = '\0';

bufferSize = 0;
USB_PORT_SEL |= USB_PIN_RXD + USB_PIN_TXD;
USB_PORT_DIR |= USB_PIN_TXD; // PORT_DIR(HI) : TXD
USB_PORT_DIR &= ~USB_PIN_RXD; // PORT_DIR(LO) : RXD

UCA1CTL1 |= 0x00//UCSWRST; //Reset State, UCSI_A1 Control 1, this op. modifies the lowest bit
UCA1CTL0 = UCMODE_0; // UCSI_A1 Control 0 = UCMODE_0; UCMODE_0 denotes UART mode
  // this mods. last 2nd, 3rd bits, can be modified only when UCSWRST=1, and seems to be UART mode since UCMODE_0 is 0x00 macro

UCA1CTL0 |= UC7BIT; // 7bit comm. , UCA1CTL0: UCSI_A1 control 0 --> 1: 7bits, 0: 8bits
UCA1CTL1 |= UCSSEL_2; //clock selection: SMCLK
//UCSSEL: MACRO FOR: 0x80 = 1000 0000 : Denotes SMCLK-------/
UCA1BR0 = 138; // 8Mhz/57600=138, UCAxBR0: USCI_Ax baud rate control 0,
UCA1BR1 = 0; // UCAxBR1: USCI_Ax baud rate control 1
  // BR0: low byte of clock & BR1: high byte of clock --> forms 16-bit val (UCAxBR0 + UCAxBR1 * 256)
  // for this case, that is 0000 0001 0001 0000

UCA1MCTL = 0xE; //14 -> 1110 : oversampling disabled, second modulation (111)
UCA1CTL1 &= ~UCSWRST; // RESET mode OFF
UCA1IE |= 0x01; // RECIEVE interrupt enabled

__bis_SR_register(GIE); // Enable Interrupts
__no_operation();

}

void halUsbShutDown(void)
{
UCA1IE &= ~UCRXIE; // Disable back RX interrupt
UCA1CTL1 = UCSWRST; //Reset State
USB_PORT_SEL &= ~(USB_PIN_RXD + USB_PIN_TXD); // get rid of the assigned RX, TX pins away
USB_PORT_DIR |= USB_PIN_TXD;
USB_PORT_DIR |= USB_PIN_RXD;
USB_PORT_OUT &= ~(USB_PIN_TXD + USB_PIN_RXD);
}

void halUsbSendChar(char* character,int i)
{
char* ERRC="LOOP ";
char* NEXTOPC ="PR ";

if(UCA1IFG & UCTXIFG)

   halLcdPrintLine(NEXTOPC, 5+i, 0);

while (!(UCA1IFG & UCTXIFG))
   {
      halLcdPrintLine(ERRC, 1, 0);
   }
    //UCA1IFG: interrupt flag register, UCTXIFG : 1 bit from UCA1IFG, 0: no interrupt, 1: interrupt
    // for this case, if two are the same -> get out of while, if diff-> in while loop forever, which means some undesired error happened

UCA1TXBUF = *character; //UCA1TXBUF: 8-bit register, stores a 8-bit char.
}

/**
* main.c
*/
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer
P1DIR |= BIT1;

char REG_BUF[15]={0,};

halLcdInit();
halLcdBackLightInit();
halLcdClearScreen();

halLcdBackLightInit();
halLcdClearScreen();
// halLcdPrintLine("Baudrate = 57600", 0, 0);
// halUsbInit();

int i;
char character[17]={'E', 'F', 0};
for (i =0 ; i < 3 ; i++)
{
  halUsbInit();

  halUsbSendChar( (character + i) , i);

  char buf[3]={0,}; 
  buf[0]=UCA1TXBUF;

  halLcdPrint(buf, 0);

  __delay_cycles(100000);

  halUsbShutDown();
  volatile unsigned int k;

  P1OUT ^= BIT1;

  k = 20000;
  do k--;
  while(k != 0);
}
//halUsbShutDown();

return 0;
}

  • Hello Donghyeon,

    Your UCA1 UART initialization is based from a 8 MHz SMCLK source but are you sure that your clocks have been properly set up as such? Your UCS initialization code has not been provided if so. You also need to put the USCI logic into a reset state (UCA1CTL1 |= UCSWRST;) before modifying any registers, clearing the software reset enable afterwards. Have you referred to the MSP-EXP430F5438 User Experience code example?

    Regards,
    Ryan
  • Thank you very much! Actually, I also had referred the experience example codes, however, I could not figure out how to set up the clock settings from there... would you suggest me a way or a document that I may refer to to set up the communication clock? Or, should I measure them manually? Thank you!
  • /*modified reply*//*additional one*/
    After I studied about UCS registers, I made setup like written below.

    /*UCS settings*/
    UCSCTL1 |= 0x0001; // modulation ENABLE
    UCSCTL2 = 0x0100; // set FLLD 0(D=1), FLLN 2^8 (N=2^8)
    UCSCTL3 = 0x0000; // set FLLREF = XT1CLK, FLLRDIV = 000b (n = 1)
    UCSCTL4 = 0x0030; // SELS = 000b : select SMCLK --> DCOCLK , others: not important in this code
    UCSCTL5 = 0x0000; // All CLK DIV.FACTOR = 000b --> f/1
    UCSCTL6 = 0x0080; // XT1DRIVE LOWEST CURRENT COMSUMPTION MODE, XTS 0b, SMCLK ON, XT1 ON. ##BYPASS CAP. VAL???

    /*UCA1CTL0,1 settings*/
    UCA1CTL0 |= 0xE8;//UC7BIT=0x10; // 8bit comm. ,even parity, MSB First
    UCA1CTL1 |= 0xB5;//B5= 1011 0101
    // I also have reset state, before doing this modification

    Therefore, now I am sure of it that the clock I am using is 8Mhz with baud rate 115200.

    However, the code still does not work.
    but there's one thing got better(not sure if it is really a better thing); it now prints � kind of letter each time it sends a character to UCA1TXBUF.
    (before, it printed out sometimes inconsistently, however, it shows a constant behaviour now.)


    The question is;
    1) what should I try to debug this situation?
    2) I again tried to use the sample code provided, and it does not work; am I missing something when loading the program on my board?
    3) What is bypass capacitance value for this register and how should I set it up?

    Thank you very much for your help
    repectfully,

  • Your UCS register settings require a lot of improvement, please refer to msp430x54xA_UCS_2.c for an example of how to set MCLK & SMCLK to 8 MHz. From reading the MSP-EXP430F5438 Experimenter Board Users Guide (SLAU263) I also don't think that baud rates above 57600 are supported, and anyways your USCI settings are still incorrect. You should be using logic analyzer or oscilloscope screenshots to evaluate your communication lines. If the sample code as packaged does not work then there could be an issue with the hardware setup (jumper configurations) or terminal settings. The XCAP bits from UCSCTL6 refer to the integrated effective load capacitance for XT1 pre-populated on the MSP-EXP430F5438, values are listed in Section 5.15 of the Datasheet. You should study the HAL_UCS.c functions of the User Experience code.

    Regards,
    Ryan

**Attention** This is a public forum