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 F5529 UART communication with host

Hi!

i am trying to send a string of data from msp430 F5529 to my PC via UART communication.

I have found a code example that works flawlessly with my g2553 microcontroller.

http://homepages.ius.edu/RWISMAN/C335/HTML/msp430SerialComm.htm

However, when i try it with my F5529 it does not seem to work. I understand i cannot just switch microcontrollers and assumed it will just work.

so i went ahead and did some modifications:

1. UART functionality on the f5529 is on pin 3 BIT3 tx and BIT4 rx

2. clocks initialization gave me errors, so i used the one from the f5529 UART examples

when i run the code it does not give me any errors, but the two strings do not come out on the putty terminal

i need some guidance!!! anything i should modify?

thanks in advance.

here is the modified code :

#include <msp430.h>
                                                       // Hardware-related definitions
#define UART_TXD 0x0008
#define UART_RXD 0x0010
#define UART_TBIT_DIV_2 (1000000 / (9600 * 2))         // Conditions for 9600 Baud SW UART, SMCLK = 1MHz
#define UART_TBIT (1000000 / 9600)
                                                       // Globals for full-duplex UART communication
unsigned int txData;                                   // UART internal variable for TX
unsigned char rxBuffer;                                // Received UART character

void TimerA_UART_tx(unsigned char byte);               // Function prototypes
void TimerA_UART_print(char *string);

void main(void){

  WDTCTL = WDTPW + WDTHOLD;                            // Stop WD timer
  UCA0CTL1 |= UCSWRST;                      // **Put state machine in reset**
  UCA0CTL1 |= UCSSEL_2;                     // SMCLK
  UCA0BR0 = 9;                              // 1MHz 115200 (see User's Guide)
  UCA0BR1 = 0;                              // 1MHz 115200
  UCA0MCTL |= UCBRS_1 + UCBRF_0;            // Modulation UCBRSx=1, UCBRFx=0
  UCA0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
  UCA0IE |= UCRXIE;                         // Enable USCI_A0 RX interrupt

  P3OUT = 0x00;                                        // Initialize all GPIO

  P3SEL = UART_TXD + UART_RXD;                         // Timer function for TXD/RXD pins
  P3DIR = 0xFF & ~UART_RXD;                            // Set all pins but RXD to output

                                                       // Configures Timer_A for full-duplex UART operation
  TA0CCTL0 = OUT;                                      // Set TXD Idle as Mark = '1'
  TA0CCTL1 = SCS + CM1 + CAP + CCIE;                   // Sync, Neg Edge, Capture, Int
  TA0CTL = TASSEL_2 + MC_2;                            // SMCLK, start in continuous mode

  _BIS_SR(GIE);                                        // Enable CPU interrupts

  TimerA_UART_print("This is string one\r\n");          // Send test message
  TimerA_UART_print("This is string two\r\n");

  while(1){                                            // Wait for incoming character

    _BIS_SR(LPM0_bits);                                // Enter low poser mode

    TimerA_UART_tx(rxBuffer);                          // Transmit the received data
  }
}

void TimerA_UART_tx(unsigned char byte) {              // Outputs one byte using the Timer_A UART

  while (TA0CTL & CCIE);                              // Ensure last char got TX'd

  TA0CCR0 = TA0R;                                       // Current state of TA counter

  TA0CCR0 += UART_TBIT;                                // One bit time till first bit

  TA0CCTL0 = OUTMOD0 + CCIE;                           // Set TXD on EQU0, Int

  txData = byte;                                       // Load global variable

  txData |= 0x100;                                     // Add mark stop bit to TXData

  txData <<= 1;                                        // Add space start bit
}

void TimerA_UART_print(char *string) {                 // Prints a string using the Timer_A UART

  while (*string)
      TimerA_UART_tx(*string++);
}

#pragma vector = TIMER0_A0_VECTOR                   // Timer_A UART - Transmit Interrupt Handler

   __interrupt void Timer_A0_ISR(void) {

  static unsigned char txBitCnt = 10;

  TA0CCR0 += UART_TBIT;                                // Add Offset to CCRx

  if (txBitCnt == 0) {                                 // All bits TXed?

    TA0CCTL0 &= ~CCIE;                                 // All bits TXed, disable interrupt

    txBitCnt = 10;                                     // Re-load bit counter
  }
  else {
    if (txData & 0x01)
      TA0CCTL0 &= ~OUTMOD2;                            // TX Mark '1'
    else
      TA0CCTL0 |= OUTMOD2;                             // TX Space '0'
  }
  txData >>= 1;                                        // Shift right 1 bit
  txBitCnt--;
}

#pragma vector = TIMER0_A1_VECTOR                      // Timer_A UART - Receive Interrupt Handler

  __interrupt void Timer_A1_ISR(void) {

  static unsigned char rxBitCnt = 8;

  static unsigned char rxData = 0;

  switch (__even_in_range(TA0IV, TA0IV_TAIFG)) {       // Use calculated branching

    case TA0IV_TACCR1:                                 // TACCR1 CCIFG - UART RX

         TA0CCR1 += UART_TBIT;                         // Add Offset to CCRx

         if (TA0CCTL1 & CAP) {                         // Capture mode = start bit edge

           TA0CCTL1 &= ~CAP;                           // Switch capture to compare mode

           TA0CCR1 += UART_TBIT_DIV_2;                 // Point CCRx to middle of D0
         }
         else {
           rxData >>= 1;

           if (TA0CCTL1 & SCCI)                        // Get bit waiting in receive latch
             rxData |= 0x80;
           rxBitCnt--;

           if (rxBitCnt == 0) {                        // All bits RXed?

             rxBuffer = rxData;                        // Store in global variable

             rxBitCnt = 8;                             // Re-load bit counter

             TA0CCTL1 |= CAP;                          // Switch compare to capture mode

             _BIC_SR(LPM0_EXIT);                       // wake up from low power mode.
           }
         }
         break;
   }
}

  • Your code looks a bit weird. It seems like you have fused code for using the hardware UART with code for driving a timer-based software UART.

    You enable the USCI RX interrupt, but I don't see an USCI ISR that handles the interrupt.

    Also, I see that you don't configure the clock system. The default 1MHz clock speed of the 5x family is a bit fragile (not too precise) for UART usage. Well, maybe better than the default of the other MSP families.
    But 1MHz is not a good base for driving 115200Bd UART too.
    You should set the clock to 4MHz or more if you want to use 115200Bd.
    You may run the CPU by 1MHz still (/4 divider) if you want.

**Attention** This is a public forum