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.

CC3220S-LAUNCHXL: Simple SPI Loopback

Part Number: CC3220S-LAUNCHXL
Other Parts Discussed in Thread: CC3220S, CC3220SF

I am trying to create a loopback, connecting a physical wire between MOSI and MISO pins using SPII. I'm also trying to read the MOSI and CLK signal with an oscilloscope, but they only show a flat line. The UART loopback example code works fine. There really isn't any example code for SPI on the CC3220S, but it doesn't seem like something like this should be too hard. My code is this:

    #define MSGSIZE 20
    SPI_Handle      spi;
    SPI_Params      spiParams;
    SPI_Transaction spiTransaction;
    uint8_t         transmitBuffer[MSGSIZE];
    uint8_t         receiveBuffer[MSGSIZE];
    bool            transferOK;
    
    
    
    SPI_Params_init(&spiParams);  // Initialize SPI parameters
    //default parameters
    spiParams.transferMode = SPI_MODE_BLOCKING;
    spiParams.transferTimeout = SPI_WAIT_FOREVER;
    spiParams.transferCallbackFxn = NULL;
    spiParams.mode = SPI_MASTER;
    spiParams.bitRate = 1000000;
    spiParams.dataSize = 8;       // 8-bit data size
    spiParams.frameFormat = SPI_POL0_PHA0;
    spiParams.custom = NULL;
    
    spi = SPI_open(Board_SPI0, &spiParams);
    if (spi == NULL) {
        while (1);  // SPI_open() failed
    }

    
    for(i = 0; i < MSGSIZE; i++){
        transmitBuffer[i] = i;
        receiveBuffer[i] = 0;
    }
    
    // Fill in transmitBuffer
    spiTransaction.count = MSGSIZE;
    spiTransaction.txBuf = transmitBuffer;
    spiTransaction.rxBuf = receiveBuffer;
    

    while(1){
        transferOK = SPI_transfer(spi, &spiTransaction);
        if (!transferOK) {
            GPIO_write(Board_GPIO_LED0, Board_GPIO_LED_OFF);
            // Error in SPI or transfer already in progress.
        }
    }

I turn a LED off if there is a transfer problem, but the LED never turns off. I have P05 as CLK, P06 as MISO, P07 as MOSI, and P08 as CS. I'm measuring CLK and MOSI on the oscilloscope, and MOSI and MISO are also physically connected by a wire.

Any help as to why SPI is not producing any bitsream or a nudge in the right direction would be appreciated. Thanks.

  • Hi,

    Have you called SPI_init() before SPI_open()? Are you able to get past the if (spi == NULL)?

    You are using Board_SPI0.
    Have you modified the pins in SPICC32XXDMA_HWAttrsV1[Board_SPI0] in CC3220SF_LAUNCHXL.c?


    Regards,
    Toby

  • Yes, I call SPI_init() before SPI_open(). I am also able to get past spi==NULL. This is my SPICC32XXDMA_HWAttrsV1.

    const SPICC32XXDMA_HWAttrsV1 spiCC3220SDMAHWAttrs[CC3220S_LAUNCHXL_SPICOUNT] = {
    /* index 0 is reserved for LSPI that links to the NWP */
    {
    .baseAddr = LSPI_BASE,
    .intNum = INT_LSPI,
    .intPriority = (~0),
    .spiPRCM = PRCM_LSPI,
    .csControl = SPI_SW_CTRL_CS,
    .csPolarity = SPI_CS_ACTIVEHIGH,
    .pinMode = SPI_4PIN_MODE,
    .turboMode = SPI_TURBO_OFF,
    .scratchBufPtr = &spiCC3220SDMAscratchBuf[CC3220S_LAUNCHXL_SPI0],
    .defaultTxBufValue = 0,
    .rxChannelIndex = UDMA_CH12_LSPI_RX,
    .txChannelIndex = UDMA_CH13_LSPI_TX,
    .minDmaTransferSize = 100,
    .mosiPin = SPICC32XXDMA_PIN_NO_CONFIG,
    .misoPin = SPICC32XXDMA_PIN_NO_CONFIG,
    .clkPin = SPICC32XXDMA_PIN_NO_CONFIG,
    .csPin = SPICC32XXDMA_PIN_NO_CONFIG
    },
    {
    .baseAddr = GSPI_BASE,
    .intNum = INT_GSPI,
    .intPriority = (~0),
    .spiPRCM = PRCM_GSPI,
    .csControl = SPI_HW_CTRL_CS,
    .csPolarity = SPI_CS_ACTIVELOW,
    .pinMode = SPI_4PIN_MODE,
    .turboMode = SPI_TURBO_OFF,
    .scratchBufPtr = &spiCC3220SDMAscratchBuf[CC3220S_LAUNCHXL_SPI1],
    .defaultTxBufValue = 0,
    .rxChannelIndex = UDMA_CH6_GSPI_RX,
    .txChannelIndex = UDMA_CH7_GSPI_TX,
    .minDmaTransferSize = 100,
    .mosiPin = SPICC32XXDMA_PIN_07_MOSI,
    .misoPin = SPICC32XXDMA_PIN_06_MISO,
    .clkPin = SPICC32XXDMA_PIN_05_CLK,
    .csPin = SPICC32XXDMA_PIN_08_CS,
    }
    };


    In board.h, there is already the line:
    #define Board_SPI0 CC3220S_LAUNCHXL_SPI1

    so I'm pretty sure it goes to the second one in the array, where MOSI=pin7, MISO=pin6, and CLK=pin5.

    Also for loopback, I just realized you need a master and a slave device, not just a single device, but I should still be able to read the CLK pin and MOSI pin on an oscilloscope if I understand this correctly. I'm still not getting a signal on the CLK pin for my master device. I just want to try to get a clock signal from CLK and a digital waveform from MOSI, and work from there. Thanks.
  • Are there SPI example codes for the TI-CC3220S besides the one in the drivers/SPI.h file?