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.

MSP430FR2355 Launchpad SPI



Hello everyone,

could someone please help with SPI issue, I am trying to modify example and use it but it just doesn't want to work (Big tnx in advance!).

#include "driverlib.h"
#include "Board.h"

uint16_t i;
uint8_t RXData = 0, TXData = 0;
uint8_t check = 0;




//Desired Timeout for XT1 initialization
#define CS_XT1_TIMEOUT 50000


//Desired Timeout for XT2 initialization**
#define CS_XT2_TIMEOUT 0


//XT1 Crystal Frequency being used
#define CS_XT1_CRYSTAL_FREQUENCY    32768


//Variable to store returned STATUS_SUCCESS or STATUS_FAIL
uint8_t returnValue = 0;


//Variable to store current clock values
uint32_t clockValue;




void main(void)
{
    //Stop Watchdog Timer
    WDT_A_hold(WDT_A_BASE);

    // --------------------- EXTERNAL CRYSTAL ---------------------------------


    //Port select XT1
    GPIO_setAsPeripheralModuleFunctionInputPin(
        GPIO_PORT_P2,
        GPIO_PIN6 + GPIO_PIN7,
        GPIO_SECONDARY_MODULE_FUNCTION
    );


    // --------------------- EXTERNAL CRYSTAL ---------------------------------



    // ----------------------- SPI -------------------------------

    // CS SIGNAL
    GPIO_setAsOutputPin(GPIO_PORT_P3,GPIO_PIN6);
    //Set all CS pins High
    GPIO_setOutputHighOnPin(GPIO_PORT_P3,GPIO_PIN6);



    GPIO_setAsPeripheralModuleFunctionInputPin(
        GPIO_PORT_P4,
        GPIO_PIN4 + GPIO_PIN5 + GPIO_PIN6 + GPIO_PIN7,
        GPIO_PRIMARY_MODULE_FUNCTION
    );

    // ----------------------- SPI -------------------------------




    // --------------------- EXTERNAL CRYSTAL ---------------------------------


    //Initializes the XT1 and XT2 crystal frequencies being used
        CS_setExternalClockSource(CS_XT1_CRYSTAL_FREQUENCY);

        //Initialize XT1. Returns STATUS_SUCCESS if initializes successfully
        returnValue = CS_turnOnXT1LFWithTimeout(CS_XT1_DRIVE_0,CS_XT1_TIMEOUT);

        //Select XT1 as ACLK source
        CS_initClockSignal(CS_ACLK,CS_XT1CLK_SELECT,CS_CLOCK_DIVIDER_1);

        //Select XT1 as SMCLK source
        CS_initClockSignal(CS_SMCLK,CS_XT1CLK_SELECT,CS_CLOCK_DIVIDER_1);

        //clear all OSC fault flag
        CS_clearAllOscFlagsWithTimeout(1000);

        //Enable oscillator fault interrupt
        SFR_enableInterrupt(SFR_OSCILLATOR_FAULT_INTERRUPT);

    // --------------------- EXTERNAL CRYSTAL ---------------------------------


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


    if (STATUS_FAIL == EUSCI_A_UART_init(EUSCI_A0_BASE, &uart_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);


    // ----------------------- SPI -------------------------------

    //Initialize Master
    EUSCI_B_SPI_initMasterParam spi_param = {0};
    spi_param.selectClockSource = EUSCI_B_SPI_CLOCKSOURCE_SMCLK;
    spi_param.clockSourceFrequency = CS_getSMCLK();
    spi_param.desiredSpiClock = 1000;
    spi_param.msbFirst = EUSCI_B_SPI_MSB_FIRST;
    spi_param.clockPhase = EUSCI_B_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT;
    spi_param.clockPolarity = EUSCI_B_SPI_CLOCKPOLARITY_INACTIVITY_HIGH;
    spi_param.spiMode = EUSCI_B_SPI_4PIN_UCxSTE_ACTIVE_HIGH; //EUSCI_B_SPI_3PIN;
    EUSCI_B_SPI_initMaster(EUSCI_B0_BASE, &spi_param);

    //Enable SPI module
    EUSCI_B_SPI_enable(EUSCI_B0_BASE);

    EUSCI_B_SPI_clearInterrupt(EUSCI_B0_BASE,EUSCI_B_SPI_RECEIVE_INTERRUPT);

    // Enable USCI_B0 RX interrupt
    EUSCI_B_SPI_enableInterrupt(EUSCI_B0_BASE,EUSCI_B_SPI_RECEIVE_INTERRUPT);


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

    // ----------------------- SPI -------------------------------



    // Enable global interrupts
    __enable_interrupt();
    while (1)
    {

        TXData = 0x55;


        // ---------------------- SPI ----------------------
        //Set all CS pins Low
        GPIO_setOutputLowOnPin(GPIO_PORT_P3,GPIO_PIN6);
        //Wait for slave to initialize
          __delay_cycles(100);

        //USCI_B0 TX buffer ready?
        while (!EUSCI_B_SPI_getInterruptStatus(EUSCI_B0_BASE,
                  EUSCI_B_SPI_TRANSMIT_INTERRUPT)) ;

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


        //Set all CS pins High
        GPIO_setOutputHighOnPin(GPIO_PORT_P3,GPIO_PIN6);
        //Wait for slave to initialize
          __delay_cycles(100);
        // ---------------------- SPI ----------------------


        __delay_cycles(10000);


    }
}


#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=USCI_B0_VECTOR
__interrupt
#elif defined(__GNUC__)
__attribute__((interrupt(USCI_B0_VECTOR)))
#endif
void USCI_B0_ISR (void)
{
    switch (__even_in_range(UCB0IV, USCI_SPI_UCTXIFG))
    {
        case USCI_SPI_UCRXIFG:      // UCRXIFG

            break;
        default:
            break;
    }
}


**Attention** This is a public forum