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.

LAUNCHXL-F28379D: SPI external loopback

Part Number: LAUNCHXL-F28379D


#include "driverlib.h"
#include "device.h"

// Globals
//
volatile uint16_t sData[2];         // Send data buffer
volatile uint16_t rData[2];         // Receive data buffer
volatile uint16_t rDataPoint = 0;   // To keep track of where we are in the   // data stream to check received data

// Function Prototypes

void initSPIBMaster(void);
void initSPIASlave(void);
void configGPIOs(void);
__interrupt void spibTxFIFOISR(void);
__interrupt void spiaRxFIFOISR(void);

void main(void)
{
    uint16_t i;
    Device_init();
    Device_initGPIO();
    Interrupt_initModule();
    Interrupt_initVectorTable();
    Interrupt_register(INT_SPIB_TX, &spibTxFIFOISR);
    Interrupt_register(INT_SPIA_RX, &spiaRxFIFOISR);
    
    configGPIOs();
    initSPIBMaster();
    initSPIASlave();

    for(i = 0; i < 2; i++)
    {
        sData[i] = i;
        rData[i]= 0;
    }

    Interrupt_enable(INT_SPIA_RX);
    Interrupt_enable(INT_SPIB_TX);

    EINT;
    ERTM;
}

// Function to configure SPI B as master with FIFO enabled.
void initSPIBMaster(void)
{
    SPI_disableModule(SPIB_BASE); // Must put SPI into reset before configuring it

    // SPI configuration. Use a 500kHz SPICLK and 16-bit word size.
    SPI_setConfig(SPIB_BASE, DEVICE_LSPCLK_FREQ, SPI_PROT_POL0PHA0, SPI_MODE_MASTER, 500000, 16);
    SPI_disableLoopback(SPIB_BASE);
    SPI_setEmulationMode(SPIB_BASE, SPI_EMULATION_FREE_RUN);
    SPI_enableFIFO(SPIB_BASE);     // FIFO and interrupt configuration
    SPI_clearInterruptStatus(SPIB_BASE, SPI_INT_TXFF);
    SPI_setFIFOInterruptLevel(SPIB_BASE, SPI_FIFO_TX2, SPI_FIFO_RX2);
    SPI_enableInterrupt(SPIB_BASE, SPI_INT_TXFF);

    SPI_enableModule(SPIB_BASE); // Configuration complete. Enable the module.
}

// Function to configure SPI A as slave with FIFO enabled.

void initSPIASlave(void)
{
    // Must put SPI into reset before configuring it
    //
    SPI_disableModule(SPIA_BASE);
    SPI_reset(SPIA_BASE);

    // SPI configuration. Use a 500kHz SPICLK and 16-bit word size.
    
    SPI_setConfig(SPIA_BASE, DEVICE_LSPCLK_FREQ, SPI_PROT_POL0PHA0,SPI_MODE_SLAVE, 500000, 16);
    SPI_disableLoopback(SPIA_BASE);
    SPI_setEmulationMode(SPIA_BASE, SPI_EMULATION_FREE_RUN);

    // FIFO and interrupt configuration
    
    SPI_enableFIFO(SPIA_BASE);
    SPI_clearInterruptStatus(SPIA_BASE, SPI_INT_RXFF);
    SPI_setFIFOInterruptLevel(SPIA_BASE, SPI_FIFO_TX2, SPI_FIFO_RX2);
    SPI_enableInterrupt(SPIA_BASE, SPI_INT_RXFF);
    SPI_resetRxFIFO(SPIA_BASE);
    SPI_resetTxFIFO(SPIA_BASE);
    
    // Configuration complete. Enable the module.
    SPI_enableModule(SPIA_BASE);
}

// Configure GPIOs for external loopback.

void configGPIOs(void)
{
    GPIO_setPinConfig(GPIO_59_SPISOMIA);
    GPIO_setPinConfig(GPIO_58_SPISIMOA);
    GPIO_setPinConfig(GPIO_61_SPISTEA);
    GPIO_setPinConfig(GPIO_60_SPICLKA);

    GPIO_setPinConfig(GPIO_66_SPISTEB);
    GPIO_setPinConfig(GPIO_63_SPISIMOB);
    GPIO_setPinConfig(GPIO_64_SPISOMIB);
    GPIO_setPinConfig(GPIO_65_SPICLKB);
}
// SPI A Transmit FIFO ISR
//
__interrupt void spibTxFIFOISR(void)
{
    uint16_t i;
    // Send data
    //
    for(i = 0; i < 2; i++)
    {
       SPI_writeDataNonBlocking(SPIB_BASE, sData[i]);
    }
    // Increment data for next cycle
    //
    for(i = 0; i < 2; i++)
    {
       sData[i] = sData[i] + 1;
    }
    // Clear interrupt flag and issue ACK
    
    SPI_clearInterruptStatus(SPIB_BASE, SPI_INT_TXFF);
    Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP6);
}

// SPI B Receive FIFO ISR
//
 __interrupt void spiaRxFIFOISR(void)
{
    uint16_t i;

    //
    // Read data
    //
    for(i = 0; i < 2; i++)
    {
        rData[i] = SPI_readDataNonBlocking(SPIA_BASE);
    }

    //
    // Check received data
    //
    for(i = 0; i < 2; i++)
    {
        if(rData[i] != (rDataPoint + i))
        {
            // Something went wrong. rData doesn't contain expected data.
            Example_Fail = 1;
//            ESTOP0;
        }
    }

    rDataPoint++;

    // Clear interrupt flag and issue ACK
    SPI_clearInterruptStatus(SPIA_BASE, SPI_INT_RXFF);
    Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP6);

    Example_PassCount++;
}
this is similar kind of example as ex3 SPI external lookback mode given, but I have changed the SPI A and B pin as per my launchpad f28379d but in debug section proprer data is not received by slave (only -1 and 0 I can see in rData array).

Please look into the code and let me know what i am missing.

Thanks & Regards,
Jay