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.

MSP430FR4133: ISR for

Part Number: MSP430FR4133

We currently need to read characters from Serial Input, but we are unable to correctly trigger the ISRs.

We've tried the code example from the resource explorer but doesn't seem to be working.

We are using an RFID module (EM-18 Reader Module) that operates with a baud rate of 9600. (We've verified that the sensor works)

Here's our code:

#include <msp430.h> 
#include "driverlib/MSP430FR2xx_4xx/eusci_a_uart.h"

#define GPIO_PIN0                                                      (0x0001)
#define GPIO_PIN1                                                      (0x0002)
#define GPIO_PORT_P1                                                          1
#define GPIO_PRIMARY_MODULE_FUNCTION                                     (0x01)


void Init_UART(void)
{
    //Configure UART pins, which maps them to a COM port over the USB cable
    //Set P1.0 and P1.1 as Secondary Module Function Input.
    GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1, GPIO_PIN1, GPIO_PRIMARY_MODULE_FUNCTION);
    GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P1, GPIO_PIN0, GPIO_PRIMARY_MODULE_FUNCTION);

    /*
     * UART Configuration Parameter. These are the configuration parameters to
     * make the eUSCI A UART module to operate with a 9600 baud rate. These
     * values were calculated using the online calculator that TI provides at:
     * software-dl.ti.com/.../index.html
     */

    //SMCLK = 1MHz, Baudrate = 9600
    //UCBRx = 6, UCBRFx = 8, UCBRSx = 17, UCOS16 = 1
    EUSCI_A_UART_initParam param = {0};
        param.selectClockSource = EUSCI_A_UART_CLOCKSOURCE_SMCLK;
        param.clockPrescalar    = 6;
        param.firstModReg       = 13;
        param.secondModReg      = 34;
        param.parity            = EUSCI_A_UART_NO_PARITY;
        param.msborLsbFirst     = EUSCI_A_UART_LSB_FIRST;
        param.numberofStopBits  = EUSCI_A_UART_ONE_STOP_BIT;
        param.uartMode          = EUSCI_A_UART_MODE;
        param.overSampling      = 1;

    if(STATUS_FAIL == EUSCI_A_UART_init(EUSCI_A0_BASE, &param))
    {
        return;
    }

    EUSCI_A_UART_enable(EUSCI_A0_BASE);

    EUSCI_A_UART_clearInterrupt(EUSCI_A0_BASE, EUSCI_A_UART_RECEIVE_INTERRUPT);

    // Enable EUSCI_A0 RX interrupt
    EUSCI_A_UART_enableInterrupt(EUSCI_A0_BASE, EUSCI_A_UART_RECEIVE_INTERRUPT);
}
//
void conditionalBlink()
{
    PM5CTL0 &= ~LOCKLPM5;                   // Disable the GPIO power-on default high-impedance mode
                                              // to activate previously configured port settings
    P4DIR |= 0x01;                          // Set P4.0 to output direction



    for(;;) {
        volatile unsigned int i;            // volatile to prevent optimization

        P4OUT ^= 0x01;                      // Toggle P4.0 using exclusive-OR

        i = 10000;                          // SW Delay
        do i--;
        while(i != 0);
    }

}

/**
 * main.c
 */

void wait_for_char(){

    volatile int i=0;
    for(i=0;i<1000;i++){}

}

volatile unsigned char buffer[256];
volatile unsigned int bufpos = 0;
char process_flag = 0;

int main(void)
{

    volatile uint8_t receivedChar = 'q';
    int i = 0;
	WDTCTL = WDTPW | WDTHOLD;	// stop watchdog timer
	PM5CTL0 &= ~LOCKLPM5;                   // Disable the GPIO power-on default high-impedance mode



	//__disable_interrupt();

	Init_UART();
	__enable_interrupt();



	while(1)
	{
	    if( process_flag)
	    {
	        //EUSCI_A_UART_transmitData (EUSCI_A0_BASE, );
	        conditionalBlink();

	        process_flag = 0;
	        break;
	    }

	}




	return 0;


#pragma vector=USCIAB1RX_VECTOR
__interrupt void USCI0RX_ISR (void)
{
    conditionalBlink();
    buffer[bufpos] = UCA0RXBUF;
    bufpos++;
    if(bufpos == 255)
    {
        process_flag = 1;
        bufpos = 0;
    }
}

Currently it doesn't seem to be entering the ISR.

Any suggestions would be very helpful.

  • > #pragma vector=USCIAB1RX_VECTOR

    Where did this vector name come from? I don't see it in msp430fr4133.h. (The G2 series had something like this. Is your MCU name set correctly in CCS?)

    Anyway, I recommend:

    > #pragma vector=USCI_A0_VECTOR

  • Thanks for the reply!

    So we've decided to use the UART loopback example that texas instruments provides.

    However, we still aren't able to get into the ISR.

    We've modified the parameters according to the calculator here: http://software-dl.ti.com/msp430/msp430_public_sw/mcu/msp430/MSP430BaudRateConverter/index.html

    Here's our code below:

    /* --COPYRIGHT--,BSD
     * Copyright (c) 2017, 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.
     * --/COPYRIGHT--*/
    //******************************************************************************
    //!  EUSCI_A0 External Loopback test using EUSCI_A_UART_init API
    //!
    //!  Description: This demo connects TX to RX of the MSP430 UART
    //!  The example code shows proper initialization of registers
    //!  and interrupts to receive and transmit data.
    //!
    //!  SMCLK = MCLK = BRCLK = DCOCLKDIV = ~1MHz, ACLK = 32.768kHz
    //!
    //!
    //!           MSP430FR2xx_4xx Board
    //!             -----------------
    //!       RST -|          UCA0TXD|----|
    //!            |                 |    |
    //!            |                 |    |
    //!            |          UCA0RXD|----|
    //!            |                 |
    //!
    //! This example uses the following peripherals and I/O signals. You must
    //! review these and change as needed for your own board:
    //! - UART peripheral
    //! - GPIO Port peripheral (for UART pins)
    //! - UCA0TXD
    //! - UCA0RXD
    //!
    //! This example uses the following interrupt handlers. To use this example
    //! in your own application you must add these interrupt handlers to your
    //! vector table.
    //! - USCI_A0_VECTOR.
    //******************************************************************************
    #include "driverlib.h"
    #include "Board.h"
    
    uint16_t i;
    uint8_t RXData = 0, TXData = 0;
    uint8_t check = 0;
    
    
    void conditionalBlink(){
        P4DIR |= 0x01;                          // Set P4.0 to output direction
    
         for(;;) {
             volatile unsigned int i;            // volatile to prevent optimization
    
             P4OUT ^= 0x01;                      // Toggle P4.0 using exclusive-OR
    
             i = 10000;                          // SW Delay
             do i--;
             while(i != 0);
         }
    }
    
    void main(void)
    {
        //Stop Watchdog Timer
        WDT_A_hold(WDT_A_BASE);
    
        //Set ACLK = REFOCLK with clock divider of 1
        CS_initClockSignal(CS_ACLK,CS_REFOCLK_SELECT,CS_CLOCK_DIVIDER_1);
        //Set SMCLK = DCO with frequency divider of 1
        CS_initClockSignal(CS_SMCLK,CS_DCOCLKDIV_SELECT,CS_CLOCK_DIVIDER_1);
        //Set MCLK = DCO with frequency divider of 1
        CS_initClockSignal(CS_MCLK,CS_DCOCLKDIV_SELECT,CS_CLOCK_DIVIDER_1);
    
        //Configure UART pins
        GPIO_setAsPeripheralModuleFunctionInputPin(
            GPIO_PORT_UCA0TXD,
            GPIO_PIN_UCA0TXD,
            GPIO_FUNCTION_UCA0TXD
        );
        GPIO_setAsPeripheralModuleFunctionInputPin(
            GPIO_PORT_UCA0RXD,
            GPIO_PIN_UCA0RXD,
            GPIO_FUNCTION_UCA0RXD
        );
    
        /*
         * Disable the GPIO power-on default high-impedance mode to activate
         * previously configured port settings
         */
        PMM_unlockLPM5();
    
        //Configure UART
        //SMCLK = 1MHz, Baudrate = 115200
        //UCBRx = 8, UCBRFx = 0, UCBRSx = 0xD6, UCOS16 = 0
        EUSCI_A_UART_initParam param = {0};
        param.selectClockSource = EUSCI_A_UART_CLOCKSOURCE_SMCLK;
        param.clockPrescalar = 6;
        param.firstModReg = 8;
        param.secondModReg = 17;
        param.parity = EUSCI_A_UART_NO_PARITY;
        param.msborLsbFirst = EUSCI_A_UART_LSB_FIRST;
        param.numberofStopBits = EUSCI_A_UART_ONE_STOP_BIT;
        param.uartMode = EUSCI_A_UART_MODE;
        param.overSampling = EUSCI_A_UART_OVERSAMPLING_BAUDRATE_GENERATION;
    
        if (STATUS_FAIL == EUSCI_A_UART_init(EUSCI_A0_BASE, &param)) {
            return;
        }
    
        EUSCI_A_UART_enable(EUSCI_A0_BASE);
    
        EUSCI_A_UART_clearInterrupt(EUSCI_A0_BASE,
            EUSCI_A_UART_RECEIVE_INTERRUPT);
    
        // Enable USCI_A0 RX interrupt
        EUSCI_A_UART_enableInterrupt(EUSCI_A0_BASE,
            EUSCI_A_UART_RECEIVE_INTERRUPT);
    
        // Enable global interrupts
        __enable_interrupt();
        while (1)
        {
            // Increment TX data
            TXData = TXData+1;
            // Load data onto buffer
            EUSCI_A_UART_transmitData(EUSCI_A0_BASE, TXData);
            while(check != 1);
            check = 0;
        }
    }
    //******************************************************************************
    //
    //This is the USCI_A0 interrupt vector service routine.
    //
    //******************************************************************************
    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector=USCI_A0_VECTOR
    __interrupt
    #elif defined(__GNUC__)
    __attribute__((interrupt(USCI_A0_VECTOR)))
    #endif
    void EUSCI_A0_ISR(void)
    {
    
        conditionalBlink();
        switch(__even_in_range(UCA0IV,USCI_UART_UCTXCPTIFG))
        {
            case USCI_NONE: break;
            case USCI_UART_UCRXIFG:
                RXData = EUSCI_A_UART_receiveData(EUSCI_A0_BASE);
                // Check value
                if(!(RXData == TXData))
                {
                    while(1);
                }
                check =1;
                break;
           case USCI_UART_UCTXIFG: break;
           case USCI_UART_UCSTTIFG: break;
           case USCI_UART_UCTXCPTIFG: break;
        }
    }

  • We've also realized that connecting the tx pin from our module to the tx pin of the board, we get  the correct value displayed on the serial output (putty serial Com port).

    When we step through the code in debug mode, we don't get any value stored in the TX Buffer.

  • How are you doing the loopback? Are you connecting the RXD/TXD pins on J1 or on J101 (MCU side)? If you're using J1, have you removed the jumpers from the J101 RXD/TXD  pins?

    Also, you should probably remove the jumper on JP1 (P1.0 LED).

  • Thanks for your advice,

    So, all we have is a jumper that goes from the TXD of our RFID Reader, to the RXD of the MCU (Pin 1.1).

    Is there any additional wiring that's needed ??, I'm not quite sure what you mean by removing the jumpers from the J101 RXD/TXD pins.

    Thanks again.

  • When I saw the P4.0 LED, I supposed you were using the Launchpad, but looking back I see you never said that. What platform are you using?

    The EM-18 data sheet I found said it runs at 5V (presumably logic as well). Does your platform have level shifters?

    Anyway, I see you've restarted the discussion over at

    https://e2e.ti.com/support/microcontrollers/msp430/f/166/t/821659

  •  You saved our asses. We're now going to pass this class because of you. It was the jumpers, thanks for bringing us to our attention. You are a guru indeed.

**Attention** This is a public forum