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.

MSP430FR6047: UART interrupt not responding while running example code FR6047_USSSWLib_template_example

Part Number: MSP430FR6047

Hi

I am working on to receiving a data through UART to toggle LED1 while running the code FR6047_USSSWLib_template_example, I am using eUSCI_A1 Registers, for that I modified the the system_pre_init.c as following.


#include <intrinsics.h>
#include <stdint.h>
#include "msp430.h"
#include "main.h"

#ifdef __TI_COMPILER_VERSION__
int _system_pre_init(void)
#elif __IAR_SYSTEMS_ICC__
int __low_level_init(void)
#elif __GNUC__
extern int system_pre_init(void) __attribute__((constructor));
int system_pre_init(void)
#else
#error Compiler not supported!
#endif
{
    /* Insert your low-level initializations here */

    /* Disable Watchdog timer to prevent reset during */
    /* int32_t variable initialization sequences. */
    // Stop WDT
    WDTCTL = WDTPW + WDTHOLD;

    /*
     * Configure CS module
     * MCLK  = 16 MHz from DCOCLK
     * SMCLK = 8MHz from DCOCLK
     * ACLK  = LFXTCLK expected to have a 32.768 KHz
     */
	// Unlock CS registers
	CSCTL0_H = CSKEY >> 8;
#if (USS_PULSE_MODE == 2)
    // Set DCO to 16MHz
    CSCTL1 = DCORSEL | DCOFSEL_4;
    // Configure wait states to be able to use 16 MHz MCLK
    FRCTL0 = (FRCTLPW | NWAITS_2);
    // Configure clock dividers all dividers
    CSCTL3 = (DIVA__1 | DIVS__2 | DIVM__1);
#else
    // Set DCO to 8MHz
    CSCTL1 = DCORSEL | DCOFSEL_3;
    // Configure clock dividers all dividers
    CSCTL3 = (DIVA__1 | DIVS__1 | DIVM__1);
#endif
    // Set SMCLK = MCLK = DCO, ACLK = LFXTCLK
    CSCTL2 = SELA__LFXTCLK | SELS__DCOCLK | SELM__DCOCLK;
	CSCTL4 |= (LFXTDRIVE_3);
	CSCTL4 &= ~(LFXTOFF);
	CSCTL0_H = 0;

	// GPIO Configuration
	PAOUT = 0;
	PADIR = 0xFFFF;

	PBOUT = 0;
	PBDIR = 0xFFFF;

	PCOUT = 0;
	PCDIR = 0xFFFF;

	PDOUT = 0;
	PDDIR = 0xFFFF;

    PEOUT = 0;
    PEDIR = 0xFFFF;

#if APPLICATION_ENABLE_UART_DEBUG
	// GPIO Configuration for UART mode
    P1SEL0 |= (BIT2 | BIT3);
    P1SEL1 &= ~(BIT2 | BIT3);

    P1OUT &= ~BIT0;                         // Clear P1.0 output latch
    P1DIR |= BIT0;                          // For LED on P1.0


    // Configure USCI_A0 for UART mode, 8-bit data, 1 stop bit
    UCA1CTLW0 = UCSWRST;                    // Put eUSCI in reset
    UCA1CTLW0 |= UCSSEL__SMCLK;             // CLK = SMCLK

    // For BRCLK = SMCLK = 8MHz, and Baud rate = 115200 (See UG)
    UCA1BRW = 4;
    // UCBRSx (bits 7-4) = 0x55, UCBRFx (bits 3-1) = 5, UCOS16 (bit 0) = 1
    UCA1MCTLW = 0x5551;

    UCA1CTLW0 &= ~UCSWRST;                 // release from reset


    //--SETUP IRQ A1 RXIFG
           UCA1IE |= UCRXIE;                       // Enable USCI_A0 RX interrupt
           __enable_interrupt();

#endif

    /*
     * Configure LFXT GPIO pins and start
     */
	PJSEL0 |= BIT4 | BIT5;

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


    /*==================================*/
    /* Choose if segment initialization */
    /* should be done or not.           */
    /* Return: 0 to omit initialization */
    /* 1 to run initialization          */
    /*==================================*/
    return(1);
}

//--------------ISR-------------------

#pragma vector=EUSCI_A1_VECTOR
__interrupt void USCI_A1_ISR(void)
{
    if(UCA1RXBUF == 't')
    {
      P1OUT ^= BIT0;  // TOGGLE LED
    }

}

In the line 88 I enabled USCI_A1 RX interrupt and at line no 115 I have added ISR.

However when I try to send data via UART I don't get any response. But when I run a separate code as shown below the LED1 toggles, con some one tell me what I am doing wrong.

#include <msp430.h>


/**
 * main.c
 */
int main(void)
{
	WDTCTL = WDTPW | WDTHOLD;	// stop watchdog timer
	
	//Setup UART A1

	UCA1CTLW0 |= UCSWRST; //Put A1 into SW Reset

	UCA1CTLW0 |= UCSSEL__SMCLK; //BRCLK = SMCLK (115200 BAUD)
	UCA1BRW = 8;               // prescalar=8
	UCA1MCTLW = 0xD600;        //set modulation & low freq

	// -- setup ports
    P1SEL0 |= (BIT2 | BIT3);      // P1 set functions to UART A1 Rx ()
    P1SEL1 &= ~(BIT2 | BIT3);

    P1OUT &= ~BIT0;                         // Clear P1.0 output latch
    P1DIR |= BIT0;                          // For LED on P1.0


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

      UCA1CTLW0 &= ~UCSWRST;                  // release from reset



      //--SETUP IRQ A1 RXIFG
      UCA1IE |= UCRXIE;                       // Enable USCI_A0 RX interrupt
      __enable_interrupt();

      //main loop
      while(1){}   //do nothing


	return 0;
}

//--ISRs

#pragma vector=EUSCI_A1_VECTOR
__interrupt void USCI_A1_ISR(void)
    {
        if(UCA1RXBUF == 't')
        {
          P1OUT ^= BIT0;  // TOGGLE LED
        }

    }

Thanks in advance
Antony

  • Hi Antony,

    The USS Library template uses its UART to transmit data, not to receive the data. What I suspect is happening is that other processes are preventing the UART ISR that you created from getting triggered. Since the UART TXIFG share the same interrupt vector as the RXIFG, that could be the root of the problem.

    Can you add this to your ISR for me. I'm sure you're sending a 't' to the UART, but I want to confirm if the receive flag is being reached at all.

    #pragma vector=EUSCI_A1_VECTOR
    __interrupt void USCI_A1_ISR(void)
    {
        switch(__even_in_range(UCA1IV, USCI_UART_UCTXCPTIFG))
        {
            case USCI_NONE: break;
            case USCI_UART_UCRXIFG:
                P1OUT ^= BIT0;         //My guess is this won't trigger
                __no_operation();
                break;
            case USCI_UART_UCTXIFG: break;
            case USCI_UART_UCSTTIFG: break;
            case USCI_UART_UCTXCPTIFG: break;
            default: break;
        }
    }

    Regards,

    Luke

  • Hi Luke, 

    Thank you for replying.

    Your ISR works, led toggles whenever there is data in UART receive buffer, however when I send w, u,o,k,m the toggling doesn't work.

    So I tried echoing the received character and I am getting following response.

    aì3,00000000 ( Here a is the UART received from PC and ì is the echo, 3,00000000 is USS data)
    tº3,00000000
    qî3,00000000
    v»3,00000000

    Also when w, u,o,k,m is sent nothing is echoed back to PC.

    w3,00000000
    u3,00000000

    So that is why when I use if loop in ISR it doesn't enter the loop to toggle the LED. Any idea what is going on ?

    Thanks
    Antony

  • Hi Antony,

    That's good that you were able to get my ISR implemented, that shows that the UART is at least receiving something. I'm guessing that the data is being corrupted somehow, probably a timing issue.

    Can you put a scope on the TX and RX pins? This will let us see what RX is actually receiving.

    If you look at the ASCII codes for these characters you can see that the data values of the echo is way off from the expected. For w and u, I'm guessing that whatever the echo'd value is doesn't show on your terminal, that is why you don't see anything sent back. I'm guessing whatever data corruption is happening the timing issue is affecting w, u, o, k, m because of how their binaries are set.

    What baud rate are you using on the PC side? Can you send the terminal settings?

    Regards,

    Luke

  • Hi Luke,

    I am using baud rate 115200 as shown below.

    I was playing with example code  "msp430fr60x7_eusci_uart_standard_transceiver.c" and modified the code to use register USCI_A1  also initially baud rate and clock was 115200 and SMCLK, but when I use SMCLK_9600 I am able to toggle with the if condition as shown below.

    //******************************************************************************
    //   MSP430FR60xx Demo - eUSCI_A0, UART Echo received character
    //                     (ACLK 9600/SMCLK 9600/SMCLK 115200)
    //
    //   Description: The device will wait in LPM0/LPM3 (based on clock source)
    //   until a UART character is received.
    //   Then the device will echo the received character.
    //   The UART can operate using ACLK at 9600, SMCLK at 115200 or SMCLK at 9600.
    //   To configure the UART mode, change the following line:
    //
    //      #define UART_MODE       SMCLK_115200
    //      to any of:
    //      #define UART_MODE       SMCLK_115200
    //      #define UART_MODE       SMCLK_9600
    //      #define UART_MODE       ACLK_9600
    //
    //   UART RX ISR is used to handle communication.
    //   ACLK = 32.768kHz, MCLK = SMCLK = DCO 16MHz.
    //
    //
    //
    //                   MSP430FR6047
    //                 -----------------
    //            /|\ |             P2.1|<-- Receive Data (UCA0RXD)
    //             |  |                 |
    //             ---|RST          P2.0|--> Transmit Data (UCA0TXD)
    //                |                 |
    //                |             PJ.5|--- LFXOUT
    //                |                 |   |
    //                |                 |  32kHz
    //                |                 |   |
    //                |             PJ.4|--- LFXIN
    //
    //   Nima Eskandari and Ryan Meredith
    //   Texas Instruments Inc.
    //   November 2017
    //   Built with CCS V7.3
    //******************************************************************************
    
    #include <msp430.h>
    
    //******************************************************************************
    // Pin Config ******************************************************************
    //******************************************************************************
    
    #define LED_OUT     P1OUT
    #define LED_DIR     P1DIR
    #define LED0_PIN    BIT0
    #define LED1_PIN    BIT1
    
    //******************************************************************************
    // UART Initialization *********************************************************
    //******************************************************************************
    
    #define SMCLK_115200     0
    #define SMCLK_9600      1
    #define ACLK_9600       2
    
    #define UART_MODE      SMCLK_9600 //SMCLK_115200//
    
    void initUART()
    {
        // Configure USCI_A0 for UART mode
        UCA1CTLW0 = UCSWRST;                      // Put eUSCI in reset
    
    #if UART_MODE == SMCLK_115200
    
        UCA1CTLW0 |= UCSSEL__SMCLK;               // CLK = SMCLK
    
        // Baud Rate Setting
        // Use Table 30-5 in Family User Guide
        UCA1BR0 = 8;
        UCA1BR1 = 0;
        UCA1MCTLW |= UCOS16 | UCBRF_10 | 0xF700;   //0xF700 is UCBRSx = 0xF7
    
    #elif UART_MODE == SMCLK_9600
    
        UCA1CTLW0 |= UCSSEL__SMCLK;               // CLK = SMCLK
    
        // Baud Rate Setting
        // Use Table 30-5 in Family User Guide
        UCA1BR0 = 104;
        UCA1BR1 = 0;
        UCA1MCTLW |= UCOS16 | UCBRF_2 | 0xD600;   //0xD600 is UCBRSx = 0xD6
    
    #elif UART_MODE == ACLK_9600
    
        UCA1CTLW0 |= UCSSEL__ACLK;               // CLK = ACLK
        // Baud Rate calculation
        // 32768/(9600) = 3.4133
        // Fractional portion = 0.4133
        // Use Table 24-5 in Family User Guide
        UCA1BR0 = 3;                             // 32768/9600
        UCA1BR1 = 0;
        UCA1MCTLW |= 0x9200;    //0x9200 is UCBRSx = 0x92
    
    #else
        # error "Please specify baud rate to 115200 or 9600"
    #endif
    
        UCA1CTLW0 &= ~UCSWRST;                    // Initialize eUSCI
        UCA1IE |= UCRXIE;                         // Enable USCI_A0 RX interrupt
    }
    
    //******************************************************************************
    // Device Initialization *******************************************************
    //******************************************************************************
    
    void initGPIO()
    {
        // LEDs
        LED_DIR |= LED0_PIN | LED1_PIN;
        LED_OUT &= ~(LED0_PIN | LED1_PIN);         // turn off LEDs
    
        P1OUT &= ~BIT0;                         // Clear P1.0 output latch
        P1DIR |= BIT0;                          // For LED on P1.0
    
        // Configure UART
        // GPIO Configuration for UART mode
            P1SEL0 |= (BIT2 | BIT3);
            P1SEL1 &= ~(BIT2 | BIT3);
    
        // Configure PJ.5 PJ.4 for external crystal oscillator
        PJSEL0 |= BIT4 | BIT5;                    // For XT1
    
        // Disable the GPIO power-on default high-impedance mode to activate
        // previously configured port settings
        PM5CTL0 &= ~LOCKLPM5;
    }
    
    void initClockTo16MHz()
    {
        // Configure one FRAM waitstate as required by the device datasheet for MCLK
        // operation beyond 8MHz _before_ configuring the clock system.
        FRCTL0 = FRCTLPW | NWAITS_1;
    
        // Clock System Setup
        CSCTL0_H = CSKEY_H;                     // Unlock CS registers
        CSCTL1 = DCOFSEL_0;                     // Set DCO to 1MHz
        // Set SMCLK = MCLK = DCO, ACLK = LFXTCLK (VLOCLK if unavailable)
        CSCTL2 = SELA__LFXTCLK | SELS__DCOCLK | SELM__DCOCLK;
        // Per Device Errata set divider to 4 before changing frequency to
        // prevent out of spec operation from overshoot transient
        CSCTL3 = DIVA__4 | DIVS__4 | DIVM__4;   // Set all corresponding clk sources to divide by 4 for errata
        CSCTL1 = DCOFSEL_4 | DCORSEL;           // Set DCO to 16MHz
        // Delay by ~10us to let DCO settle. 60 cycles = 20 cycles buffer + (10us / (1/4MHz))
        __delay_cycles(60);
        CSCTL3 = DIVA__1 | DIVS__1 | DIVM__1;   // Set all dividers to 1 for 16MHz operation
    
        CSCTL4 &= ~LFXTOFF;
        do
        {
        CSCTL5 &= ~LFXTOFFG;                      // Clear XT1 fault flag
        SFRIFG1 &= ~OFIFG;
        }while (SFRIFG1&OFIFG);                   // Test oscillator fault flag
    
        CSCTL0_H = 0;                             // Lock CS registerss
    }
    
    //******************************************************************************
    // Main ************************************************************************
    // Enters LPM0 if SMCLK is used and waits for UART interrupts. If ACLK is used *
    // then the device will enter LPM3 mode instead. The UART RX interrupt handles *
    // the received character and echoes it.                                       *
    //******************************************************************************
    
    int main(void)
    {
      WDTCTL = WDTPW | WDTHOLD;                 // Stop Watchdog
    
      initGPIO();
      initClockTo16MHz();
      initUART();
    
    #if UART_MODE == ACLK_9600
        __bis_SR_register(LPM3_bits + GIE);       // Since ACLK is source, enter LPM3, interrupts enabled
    #else
        __bis_SR_register(LPM0_bits + GIE);       // Since SMCLK is source, enter LPM0, interrupts enabled
    #endif
      __no_operation();                         // For debugger
    }
    
    //******************************************************************************
    // UART Interrupt ***********************************************************
    //******************************************************************************
    
    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #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;
                      if(UCA1RXBUF == 't')
                             {
                                  P1OUT ^= BIT0;  // TOGGLE LED
                             }
    
          __no_operation();
          break;
        case USCI_UART_UCTXIFG: break;
        case USCI_UART_UCSTTIFG: break;
        case USCI_UART_UCTXCPTIFG: break;
      }
    }
    

    So I went back to our  FR6047_USSSWLib_template_example and changed the UART settings for SMCLK and 9600, but I am receiving USS data as shown below but when I sent t LED is toggling. I changed the baud rate of Tera term as well no change. After this I used another device Particle Argon to send and receive data to MSP430FR6047 via UART still no change.

    Also, when I am debugging the MSP code I was stepping over at certain break point I am receiving correct data in both UART TX and RX buffer regardless of baud rate, but when program is running free I get this other character. Any idea how I can fix this?

    Thanks
    Antony

  • Hi Antony,

    It's strange that you can't get the device to communicate in free run mode. Can you confirm that the unmodified example works using the connections I described in this post?

    https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/1125481/msp430fr6047-no-echo-received-while-running-the-example-code-msp430fr60x7_eusci_uart_standard_transceiver-c

    Regards,

    Evan

  • Hi Evan,

    I tried your connection and it still doesn't work. But example code msp430fr60x7_eusci_uart_standard_transceiver.c is working with the USCI_A1 register, but for FR6047_USSSWLib_template_example I am facing issue.

    Thanks
    Antony

  • Antony,

    This seems to be the same issue we are debugging in this thread:

    https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/1125481/msp430fr6047-no-echo-received-while-running-the-example-code-msp430fr60x7_eusci_uart_standard_transceiver-c

    If so, I will close this thread and we will continue to debug in the other thread. If you are facing a different issue in this thread, please reply back.

    Regards,

    Evan

  • Hi Evan,

    In this thread we are trying to debug the example code  FR6047_USSSWLib_template_example in which it measures and send the DToF. Other thread is just an example code to see the UART echo and trying to make it work with USCI_A0 register.

    I was debugging the issue I have mentioned early and I got it working by using the following configuration.

    In MSP430FR6047 I use USCI_A1 register and Clock is SMCLK and baud rate is 9600. 

      // Baud Rate Setting SMCLK 9600
           // Use Table 30-5 in Family User Guide
           UCA1BR0 = 104;
           UCA1BR1 = 0;
           UCA1MCTLW |= UCOS16 | UCBRF_2 | 0xD600;   //0xD600 is UCBRSx = 0xD6

    In the tera term or any other device if UART is configured  with baud rate 4800 I am able to get USS data and toggle LED whenever I pass the character "t" via UART.

    The code works with above configuration.

    Regards
    Antony

  • Ok thanks for the clarification Antony.

    4800 is half of 9600. Is there a chance that the clock in you FR6047_USSSWLib_template_example is running at half the speed you expect it to be?

    Regards,

    Evan

  • Hi Evan, 

    I did not change the clock settings for the FR6047_USSSWLib_template_example, I just added the UART receive interrupt, but when the code is unmodified the USS data is obtained at baud rate 115200.

    Thanks
    Antony

  • This is what I see when I run the FR6047_USSSWLib_template_example unmodified with all the jumpers on J3:

    What do you see?

**Attention** This is a public forum