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.

MSP-EXP430FR5994: Setting up SPI communication on UCB1

Part Number: MSP-EXP430FR5994
Other Parts Discussed in Thread: MSP430WARE, MSP430FR5994

Dear all,

I just started developing for the MSP430FR5994 µC using the evaluation board and the MSP430Ware. I want to get SPI communication working to test it out so I connected an oscilloscope to the UCB1 interface (P5.2 for clock and P5.0 for MOSI). I modified the example code in eusci_a_spi to work with eusci_b instead. However, I see nothing. The code looks like:

#include <msp430.h>
#include "driverlib.h"


//!         Tested on MSP430FR5969
//!                 -----------------
//!            /|\ |                 |
//!             |  |                 |
//!    Master---+->|RST              |
//!                |                 |
//!                |             P2.0|-> Data Out (UCA0SIMO)
//!                |                 |
//!                |             P2.1|<- Data In (UCA0SOMI)
//!                |                 |
//!                |             P1.5|-> Serial Clock Out (UCA0CLK)
//!
//! This example uses the following peripherals and I/O signals.  You must
//! review these and change as needed for your own board:
//! - SPI peripheral
//! - GPIO Port peripheral (for SPI pins)
//! - UCA0SIMO
//! - UCA0SOMI
//! - UCA0CLK
//!
//! 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
//!
//*****************************************************************************


uint8_t RXData =0;
uint8_t TXData = 0;

void main(void)
{
    volatile uint16_t i;

    WDTCTL = WDTPW | WDTHOLD;               // Stop watchdog timer

    //Set P1.0 as an output pin.
    /*

     * Select Port 1
     * Set Pin 0 as output
     */
    GPIO_setAsOutputPin(
        GPIO_PORT_P1,
        GPIO_PIN0
    );
    //Set P1.0 as Output Low.
    /*

    * Select Port 1
    * Set Pin 0 to output Low.
    */
    GPIO_setOutputLowOnPin(
        GPIO_PORT_P1,
        GPIO_PIN0
    );

    // Configure Pins for LFXIN
    //Set PJ.4 and PJ.5 as Primary Module Function Input.
    /*

    * Select Port J
    * Set Pin 4, 5 to input Primary Module Function, (LFXIN).
    */
    GPIO_setAsPeripheralModuleFunctionInputPin(
        GPIO_PORT_PJ,
        GPIO_PIN4 + GPIO_PIN5,
        GPIO_PRIMARY_MODULE_FUNCTION
    );

    //Set external frequency for XT1
    CS_setExternalClockSource(32768,0);
    //Set DCO frequency to max DCO setting
    CS_setDCOFreq(CS_DCORSEL_0,CS_DCOFSEL_3);
    //Select XT1 as the clock source for ACLK with no frequency divider
    CS_initClockSignal(CS_ACLK,CS_LFXTCLK_SELECT,CS_CLOCK_DIVIDER_1);
    //Start XT1 with no time out
    CS_turnOnLFXT(CS_LFXT_DRIVE_0);

    // Configure SPI pins
    // Configure Pins for UCA0CLK
    //Set P1.5 as Secondary Module Function Input.
    /*

    * Select Port 1
    * Set Pin 5 to input Secondary Module Function, (UCA0CLK).
    */
    GPIO_setAsPeripheralModuleFunctionInputPin(
        GPIO_PORT_P1,
        GPIO_PIN5,
        GPIO_SECONDARY_MODULE_FUNCTION
    );
    // Configure Pins for UCA0TXD/UCA0SIMO, UCA0RXD/UCA0SOMI
    //Set P2.0, P2.1 as Secondary Module Function Input.
    /*

    * Select Port 2
    * Set Pin 0, 1 to input Secondary Module Function, (UCA0TXD/UCA0SIMO, UCA0RXD/UCA0SOMI).
    */
    GPIO_setAsPeripheralModuleFunctionInputPin(
        GPIO_PORT_P2,
        GPIO_PIN0 + GPIO_PIN1,
        GPIO_SECONDARY_MODULE_FUNCTION
    );

    /*
     * Disable the GPIO power-on default high-impedance mode to activate
     * previously configured port settings
     */
    PMM_unlockLPM5();

    //Initialize Master
    EUSCI_B_SPI_initMasterParam param = {0};
    param.selectClockSource = EUSCI_B_SPI_CLOCKSOURCE_ACLK;
    param.clockSourceFrequency = CS_getACLK();
    param.desiredSpiClock = 500000;
    param.msbFirst = EUSCI_B_SPI_MSB_FIRST;
    param.clockPhase = EUSCI_B_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT;
    param.clockPolarity = EUSCI_B_SPI_CLOCKPOLARITY_INACTIVITY_HIGH;
    param.spiMode = EUSCI_B_SPI_3PIN;
    EUSCI_B_SPI_initMaster(EUSCI_B1_BASE, &param);

    //Enable SPI module
    EUSCI_B_SPI_enable(EUSCI_B1_BASE);

    //Clear receive interrupt flag
    EUSCI_B_SPI_clearInterrupt(EUSCI_B1_BASE,
          EUSCI_B_SPI_RECEIVE_INTERRUPT
          );

    // Enable USCI_A0 RX interrupt
    EUSCI_B_SPI_enableInterrupt(EUSCI_B1_BASE,
                         EUSCI_B_SPI_RECEIVE_INTERRUPT);

    //Wait for slave to initialize
    __delay_cycles(100);

    TXData = 0x1;                             // Holds TX data

    P1DIR |= 0x01;                          // Set P1.0 to output direction, blink function for debug
    P6DIR |= 0x04;                          // Set P6.2 to output direction, for debug

    //USCI_A0 TX buffer ready?
    while(1) {
        while (!EUSCI_B_SPI_getInterruptStatus(EUSCI_B1_BASE,
                  EUSCI_B_SPI_TRANSMIT_INTERRUPT)) ;

        //Transmit Data to slave
        EUSCI_B_SPI_transmitData(EUSCI_B1_BASE, TXData);

        i = 10000;                          // SW Delay
        do i--;
        while(i != 0);
        P1OUT ^= 0x01;                      // Toggle P1.0 using exclusive-OR
        P6OUT ^= 0x04;                      // Toggle P6.2 using exclusive-OR
    }


    __bis_SR_register(LPM0_bits + GIE);      // CPU off, enable interrupts
    __no_operation();                       // Remain in LPM0


}

#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 USCI_A0_ISR (void)
{
    switch (__even_in_range(UCA0IV,4)){
        //Vector 2 - RXIFG
        case 2:
            //USCI_A0 TX buffer ready?
            while (!EUSCI_A_SPI_getInterruptStatus(EUSCI_A0_BASE,
                       EUSCI_A_SPI_TRANSMIT_INTERRUPT)) ;

            RXData = EUSCI_A_SPI_receiveData(EUSCI_A0_BASE);

            //Increment data
            TXData++;

            //Send next value
            EUSCI_A_SPI_transmitData(EUSCI_A0_BASE,
                            TXData
                            );

            //Delay between transmissions for slave to process information
            __delay_cycles(40);

            break;
        default: break;
    }
}

The only additional modification from the original code is that I added blinking to the LED as a debug thing.

  • Thank you for your question regarding the MSP430FR5994 and SPI.

    Take a look at the end of your code. You will need to modify the EUSCI_A interrupt handler to match the EUSCI_B you have implemented.

**Attention** This is a public forum