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.

MSP430FR6989: backchannel UART problem

Part Number: MSP430FR6989
Other Parts Discussed in Thread: MSP430WARE,

Dear, 

I am a beginner user of the MSP430 (FR6989). For a project I am working on, I need the MSP430 to send data to my PC (so the backchannel seems like the way to go). I wanted to start by useing some example code given by TI themselves, mainly: msp430fr69xx_euscia0_uart_01.c. Which is the following code: 

 

#include <msp430.h>

int main(void)
{
  WDTCTL = WDTPW | WDTHOLD;                 // Stop Watchdog

  // Configure GPIO
  P2SEL0 |= BIT0 | BIT1;                    // USCI_A0 UART operation
  P2SEL1 &= ~(BIT0 | BIT1);

  // Disable the GPIO power-on default high-impedance mode to activate
  // previously configured port settings
  PM5CTL0 &= ~LOCKLPM5;

  // Startup clock system with max DCO setting ~8MHz
  CSCTL0_H = CSKEY >> 8;                    // Unlock clock registers
  CSCTL1 = DCOFSEL_3 | DCORSEL;             // Set DCO to 8MHz
  CSCTL2 = SELA__VLOCLK | SELS__DCOCLK | SELM__DCOCLK;
  CSCTL3 = DIVA__1 | DIVS__1 | DIVM__1;     // Set all dividers
  CSCTL0_H = 0;                             // Lock CS registers

  // Configure USCI_A0 for UART mode
  UCA0CTLW0 = UCSWRST;                      // Put eUSCI in reset
  UCA0CTLW0 |= UCSSEL__SMCLK;               // CLK = SMCLK
  // 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
  UCA0BR0 = 52;                             // 8000000/16/9600
  UCA0BR1 = 0x00;
  UCA0MCTLW |= UCOS16 | UCBRF_1 | 0x4900;
  UCA0CTLW0 &= ~UCSWRST;                    // Initialize eUSCI
  UCA0IE |= UCRXIE;                         // Enable USCI_A0 RX interrupt

  __bis_SR_register(LPM3_bits | GIE);       // Enter LPM3, interrupts enabled
  __no_operation();                         // For debugger
}

#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=USCI_A0_VECTOR
__interrupt void USCI_A0_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(USCI_A0_VECTOR))) USCI_A0_ISR (void)
#else
#error Compiler not supported!
#endif
{
  switch(__even_in_range(UCA0IV, USCI_UART_UCTXCPTIFG))
  {
    case USCI_NONE: break;
    case USCI_UART_UCRXIFG:
      while(!(UCA0IFG&UCTXIFG));
      UCA0TXBUF = UCA0RXBUF;
      __no_operation();
      break;
    case USCI_UART_UCTXIFG: break;
    case USCI_UART_UCSTTIFG: break;
    case USCI_UART_UCTXCPTIFG: break;
  }
}

Of which I have changed nothing. I uploaded the code using Code Composer Studio (compiled using gcc). The of this code says: 

Description: This demo echoes back characters received via a PC serial port.
SMCLK/ DCO is used as a clock source and the device is put in LPM3
The auto-clock enable feature is used by the eUSCI and SMCLK is turned off
when the UART is idle and turned on when a receive edge is detected.
Note that level shifter hardware is needed to shift between RS232 and MSP
voltage levels.

However, when I then use Putty on the Port (for me COM11 MPS Application UART1), Putty show an empty terminal in which I am unable to type anything (and nothing is received). I put the Baud Rate of Putty at 9600 (which the code alse seems to do). 

How come I cannot echo anything, or read anything? I am probably missing something very basic, but I have no clue what it is. 

Thanks!

  • The backchannel UART on the FR6989 Launchpad is UCA1, rather than UCA0. [Ref Launchpad guide (SLAU627A) Sec 2.2.4] That the Example uses UCA0 does seem like a missed opportunity.

    Perhaps the simplest solution is to remove the RXD/TXD jumpers from the "bridge" header (J101) and patch the P2.0 (J1.8) pin to TXD and P2.1 (J2.19) pin to RXD.

    Alternatively, you could change the program to use UCA1 instead of UCA0. Besides the register references, you need to change the PSEL references to set P3.4/5 ("P3SEL0 |= (BIT4|BIT5)") [Ref Data Sheet (SLAS789D) Table 6-25] and change to "vector=USCI_A1_VECTOR".

  • Correct

    /* --COPYRIGHT--,BSD_EX
     * Copyright (c) 2014, Texas Instruments Incorporated
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     *
     * *  Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     * *  Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the distribution.
     *
     * *  Neither the name of Texas Instruments Incorporated nor the names of
     *    its contributors may be used to endorse or promote products derived
     *    from this software without specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     *
     *******************************************************************************
     *
     *                       MSP430 CODE EXAMPLE DISCLAIMER
     *
     * MSP430 code examples are self-contained low-level programs that typically
     * demonstrate a single peripheral function or device feature in a highly
     * concise manner. For this the code may rely on the device's power-on default
     * register values and settings such as the clock configuration and care must
     * be taken when combining code from several examples to avoid potential side
     * effects. Also see www.ti.com/grace for a GUI- and www.ti.com/msp430ware
     * for an API functional library-approach to peripheral configuration.
     *
     * --/COPYRIGHT--*/
    //******************************************************************************
    //  MSP430FR69xx Demo - eUSCI_A0 UART echo at 9600 baud using BRCLK = 8MHz
    //
    //  Description: This demo echoes back characters received via a PC serial port.
    //  SMCLK/ DCO is used as a clock source and the device is put in LPM3
    //  The auto-clock enable feature is used by the eUSCI and SMCLK is turned off
    //  when the UART is idle and turned on when a receive edge is detected.
    //  Note that level shifter hardware is needed to shift between RS232 and MSP
    //  voltage levels.
    //
    //  The example code shows proper initialization of registers
    //  and interrupts to receive and transmit data.
    //  To test code in LPM3, disconnect the debugger.
    //
    //  ACLK = VLO, MCLK =  DCO = SMCLK = 8MHz
    //
    //                MSP430FR6989
    //             -----------------
    //       RST -|     P2.0/UCA0TXD|----> PC (echo)
    //            |                 |
    //            |                 |
    //            |     P2.1/UCA0RXD|<---- PC
    //            |                 |
    //
    //   William Goh
    //   Texas Instruments Inc.
    //   April 2014
    //   Built with IAR Embedded Workbench V5.60 & Code Composer Studio V6.0
    //******************************************************************************
    // modified by: Peter Spevak
    //
    // last change: April 7th 2020
    //
    // 04/07/2020 changing the UART to eUSCIA1, as this is the UART for
    //            backchannel on virtual COM port to PC
    //
    //*****************************************************************************
    #include <msp430.h>

    int main(void)
    {
      WDTCTL = WDTPW | WDTHOLD;                 // Stop Watchdog

      // Configure GPIO
      //P2SEL0 |= BIT0 | BIT1;                    // USCI_A0 UART operation         // 04/07/2020
      //P2SEL1 &= ~(BIT0 | BIT1);                                                   // 04/07/2020
      P3SEL0 |= BIT4 + BIT5;                    // eUSCI_A1 UART                    // 04/07/2020
      P3SEL1 &= ~(BIT4 + BIT5);                 // eUSCI_A1 UART                    // 04/07/2020

      // Disable the GPIO power-on default high-impedance mode to activate
      // previously configured port settings
      PM5CTL0 &= ~LOCKLPM5;

      // Startup clock system with max DCO setting ~8MHz
      CSCTL0_H = CSKEY >> 8;                    // Unlock clock registers
      CSCTL1 = DCOFSEL_3 | DCORSEL;             // Set DCO to 8MHz
      CSCTL2 = SELA__VLOCLK | SELS__DCOCLK | SELM__DCOCLK;
      CSCTL3 = DIVA__1 | DIVS__1 | DIVM__1;     // Set all dividers
      CSCTL0_H = 0;                             // Lock CS registers

      // Configure USCI_A0 for UART mode
      /*UCA0CTLW0 = UCSWRST;                      // Put eUSCI in reset             // 04/07/2020
      UCA0CTLW0 |= UCSSEL__SMCLK;               // CLK = SMCLK
      // 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
      UCA0BR0 = 52;                             // 8000000/16/9600
      UCA0BR1 = 0x00;
      UCA0MCTLW |= UCOS16 | UCBRF_1 | 0x4900;
      UCA0CTLW0 &= ~UCSWRST;                    // Initialize eUSCI
      UCA0IE |= UCRXIE;                         // Enable USCI_A0 RX interrupt
    */

      // Configure USCI_A1 for UART mode
      UCA1CTLW0 = UCSWRST;                      // Put eUSCI in reset               // 04/07/2020
      UCA1CTLW0 |= UCSSEL__SMCLK;               // CLK = SMCLK                      // 04/07/2020
      // 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
      UCA1BR0 = 52;                             // 8000000/16/9600                  // 04/07/2020
      UCA1BR1 = 0x00;                                                               // 04/07/2020
      UCA1MCTLW |= UCOS16 | UCBRF_1 | 0x4900;                                       // 04/07/2020
      UCA1CTLW0 &= ~UCSWRST;                    // Initialize eUSCI                 // 04/07/2020
      UCA1IE |= UCRXIE;                         // Enable USCI_A0 RX interrupt      // 04/07/2020

      __bis_SR_register(LPM3_bits | GIE);       // Enter LPM3, interrupts enabled
      __no_operation();                         // For debugger
    }

    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector=USCI_A0_VECTOR
    __interrupt void USCI_A0_ISR(void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(USCI_A0_VECTOR))) USCI_A0_ISR (void)
    #else
    #error Compiler not supported!
    #endif
    {
      switch(__even_in_range(UCA0IV, USCI_UART_UCTXCPTIFG))
      {
        case USCI_NONE: break;
        case USCI_UART_UCRXIFG:
          while(!(UCA0IFG&UCTXIFG));
          UCA0TXBUF = UCA0RXBUF;
          __no_operation();
          break;
        case USCI_UART_UCTXIFG: break;
        case USCI_UART_UCSTTIFG: break;
        case USCI_UART_UCTXCPTIFG: break;
      }
    }

    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)            // 04/07/2020
    #pragma vector=USCI_A1_VECTOR
    __interrupt void USCI_A1_ISR(void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(USCI_A1_VECTOR))) USCI_A1_ISR (void)
    #else
    #error Compiler not supported!
    #endif
    {
      switch(__even_in_range(UCA1IV, USCI_UART_UCTXCPTIFG))
      {
        case USCI_NONE: break;
        case USCI_UART_UCRXIFG:
          while(!(UCA1IFG&UCTXIFG));
          UCA1TXBUF = UCA1RXBUF;
          __no_operation();
          break;
        case USCI_UART_UCTXIFG: break;
        case USCI_UART_UCSTTIFG: break;
        case USCI_UART_UCTXCPTIFG: break;
      }
    }

  • Thank you, 

    I think I am now able to write something to the MSP.

    However, it does not seem to echo anything back. 
    Even when I put code like: 

    while (1){
    UCA1TXBUF = '1';
    __no_operation();
    }

    Which should just send  '1' constantly, nothing gets send to the pc, or at least Putty cannot read it. 

    With kind regards

  • Thank you, 

    I think I can now write to the MSP. 

    However, nothing gets echoed back to me. 
    Even when I write something like:

    while(1){

    UCA1TXBUF = '1';
    __no_operation();

    }

    Nothing gets printed to putty. 

    Thanks in regards.

  • Hello Yannick,

    the code sequence you have written there cannot work. You need to check, whether the UART TX channel is still busy or not, as the TX buffer will always try transmitting at the point of writing to it. This might corrupt the state machine of the eUSCI or the content of the data you're transmitting you'll be writing at the speed of the code execution to TX buffer, while the data rate is 9600.

    You need this kind of instruction sequence.e.g. when inserting this into the ISR I have posted you can see as a response not the echo but the "U" from MSP430.

    while(!(UCA1IFG&UCTXIFG));
          //UCA1TXBUF = UCA1RXBUF;                                                  // 04/07/2020
          UCA1TXBUF = 0x55;                                                         // 04/07/2020

    Best regards

    Peter

  • Hello Peter, 

    Works perfect now!!
    Thank you!

  • Thanks, Peter.

    Can I nominate your code for inclusion in TIREX? This question seems to come up every few weeks. The FR2355 Launchpad is the same way.

  • hi Peter,

    I now tried to do the same thing with the ACLK as a clock, however, it will not work, and I cannot seem to find any sources on how this is done with the UCA1 (back-channel)
    This is my code:

    #include <msp430.h>
    
    int main(void)
    {
      WDTCTL = WDTPW | WDTHOLD;                 // Stop Watchdog
    
      // Configure GPIO
      P3SEL0 |= BIT4 + BIT5;                    // eUSCI_A1 UART
      P3SEL1 &= ~(BIT4 + BIT5);                 // eUSCI_A1 UART
    
      // Disable the GPIO power-on default high-impedance mode to activate
      // previously configured port settings
      PM5CTL0 &= ~LOCKLPM5;
      
      // XT1 Setup
      CSCTL0_H = CSKEY >> 8; // Unlock CS registers
      CSCTL2 = SELA__LFXTCLK | SELS__DCOCLK | SELM__DCOCLK;
      CSCTL3 = DIVA__1 | DIVS__1 | DIVM__1; // Set all dividers
      CSCTL4 &= ~LFXTOFF;
      do
      {
      CSCTL5 &= ~LFXTOFFG; // Clear XT1 fault flag
      SFRIFG1 &= ~OFIFG;
      }while (SFRIFG1&OFIFG); // Test oscillator fault flag
      CSCTL0_H = 0; // Lock CS registers
    
      // Configure USCI_A1 for UART mode
      UCA1CTLW0 = UCSWRST; // Put eUSCI in reset
      UCA1CTLW0 |= UCSSEL__ACLK; // CLK = ACLK
      UCA1BR0 = 3; // 9600 baud
      UCA1MCTLW |= 0x5300; // 32768/9600 - INT(32768/9600)=0.41
      // UCBRSx value = 0x53 (See UG)
      UCA1BR1 = 0;
      UCA1CTL1 &= ~UCSWRST; // Initialize eUSCI
      UCA1IE |= UCRXIE; // Enable USCI_A0 RX interrupt
    
      __bis_SR_register(LPM3_bits | GIE); // Enter LPM3, interrupts enabled
      __no_operation();
    }
    
    
    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)            // 04/07/2020
    #pragma vector=USCI_A1_VECTOR
    __interrupt void USCI_A1_ISR(void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(USCI_A1_VECTOR))) USCI_A1_ISR (void)
    #else
    #error Compiler not supported!
    #endif
    {
      switch(__even_in_range(UCA1IV, USCI_UART_UCTXCPTIFG))
      {
        case USCI_NONE: break;
        case USCI_UART_UCRXIFG:
          while(!(UCA1IFG&UCTXIFG));
          UCA1TXBUF = 0x55;
          __no_operation();
          break;
        case USCI_UART_UCTXIFG: break;
        case USCI_UART_UCSTTIFG: break;
        case USCI_UART_UCTXCPTIFG: break;
      }
    }



    The ACLK should be set acoordingly (following the example software), and is "attached" to the USCI_A1. However it does not seem to be working? 
    Can USCI_A1 not use ACLK?

    With kind regards and many thanks in advance,
    Yannick Daelemans

  • Hi Bruce,

    thanks, I'll make that proposal.

    Best regards

    Peter

  • Hello Yannick,

    this should be possible, but potentially related to LPM3 operation, clock availability and startup time. Please check if it works, when going only down to LPM0.

    Best regards

    Peter

  • Hi Peter, 

    I have been able to do it with the ACLK, however when I now try to delete the LPM3 (because I do not wnat to let it go into Low Power Mode since I need the CPU) I only get unreadable data in Putty. 
    I have made a Forum post about it today: http://e2e.ti.com/support/microcontrollers/msp430/f/166/t/896821
    In the code you can see that I also set MCLK and SMCLK to 16MHz and set the appropriate FRAM waiting states. 

    With kind regards, 
    Yannick

  • Hi Yannick,

    as you have created a new thread on the additional aspect, and as I have seen as colleague is already addressing it, I would recommend to close this one, as we basically resolved the initial, and even some consecutive problems.

    Best regards

    Peter

**Attention** This is a public forum