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.

CCS/IWR6843: Can't get SPI working on the IWR6843

Part Number: IWR6843

Tool/software: Code Composer Studio

I have been reading through the code in the D:\ti\mmwave_sdk_03_02_00_04\packages\ti\drivers\spi\test area and have been trying to apply it to my own application.

in PlatformInit I do this:

    /* Setup the PINMUX to bring out the UART-1 */
    Pinmux_Set_OverrideCtrl(SOC_XWR68XX_PINN5_PADBE, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL);    
    Pinmux_Set_FuncSel(SOC_XWR68XX_PINN5_PADBE, SOC_XWR68XX_PINN5_PADBE_MSS_UARTA_TX);
    Pinmux_Set_OverrideCtrl(SOC_XWR68XX_PINN4_PADBD, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL);    
    Pinmux_Set_FuncSel(SOC_XWR68XX_PINN4_PADBD, SOC_XWR68XX_PINN4_PADBD_MSS_UARTA_RX);

    /* Setup the PINMUX to bring out the UART-3 */
    Pinmux_Set_OverrideCtrl(SOC_XWR68XX_PINF14_PADAJ, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL);
    Pinmux_Set_FuncSel(SOC_XWR68XX_PINF14_PADAJ, SOC_XWR68XX_PINF14_PADAJ_MSS_UARTB_TX);

    /* Set up PINMUX to bring out SPIA CS1 = E15, CLK1 = E13, MOSI1 = D13, MISO1 = E14, pins 19, 21, 23, 25 on 60pin connector */
    /* SPIA_MOSI */
    Pinmux_Set_OverrideCtrl(SOC_XWR68XX_PIND13_PADAD, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL);
    Pinmux_Set_FuncSel(SOC_XWR68XX_PIND13_PADAD, SOC_XWR68XX_PIND13_PADAD_SPIA_MOSI);

    /* SPIA_MISO */
    Pinmux_Set_OverrideCtrl(SOC_XWR68XX_PINE14_PADAE, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL);
    Pinmux_Set_FuncSel(SOC_XWR68XX_PINE14_PADAE, SOC_XWR68XX_PINE14_PADAE_SPIA_MISO);

    /* SPIA_CLK */
    Pinmux_Set_OverrideCtrl(SOC_XWR68XX_PINE13_PADAF, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL);
    Pinmux_Set_FuncSel(SOC_XWR68XX_PINE13_PADAF, SOC_XWR68XX_PINE13_PADAF_SPIA_CLK);

    /* SPIA_CS */
    Pinmux_Set_OverrideCtrl(SOC_XWR68XX_PINE15_PADAG, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL);
    Pinmux_Set_FuncSel(SOC_XWR68XX_PINE15_PADAG, SOC_XWR68XX_PINE15_PADAG_SPIA_CSN);

    /* SPI_HOST_INTR - not used, reference code */
    Pinmux_Set_OverrideCtrl(SOC_XWR68XX_PINP13_PADAA, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL);
    Pinmux_Set_FuncSel(SOC_XWR68XX_PINP13_PADAA, SOC_XWR68XX_PINP13_PADAA_SPI_HOST_INTR);

    /**********************************************************************
     * Setup the PINMUX:
     * - GPIO Output: Configure pin K13 as GPIO_2 output
     **********************************************************************/
    Pinmux_Set_OverrideCtrl(SOC_XWR68XX_PINK13_PADAZ, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL);
    Pinmux_Set_FuncSel(SOC_XWR68XX_PINK13_PADAZ, SOC_XWR68XX_PINK13_PADAZ_GPIO_2);

in initTask, I do this:

/* Init SYSDMA params */
    DMA_Params_init(&dmaParams);

    /* Open DMA driver instance 0 for SPI test */
    gDmaHandle = DMA_open(0, &dmaParams, &retVal);

    if(gDmaHandle == NULL)
       {
       printf("Open DMA driver failed with error=%d\n", retVal);
       return;
       }

    /* Initialize the UART */
    UART_init();

    /* Initialize the GPIO */
    GPIO_init();

    /* Initialize Spi */
    System_printf("Debug: SPI_init\n");
    SPI_init();

/* Setup the default SPI Parameters */
    SPI_Params_init(&spiParams);
    spiParams.frameFormat = SPI_POL0_PHA0;
    spiParams.shiftFormat = SPI_MSB_FIRST;
    //spiParams.pinMode = SPI_PINMODE_3PIN;
    spiParams.pinMode = SPI_PINMODE_4PIN_CS;
        /* Enable DMA and set DMA channels */
    spiParams.dmaEnable = 1U;
    spiParams.dmaHandle = gDmaHandle;
    //spiParams.dmaHandle = (DMA_Handle)NULL;

    //spiParams.eccEnable = 1U;
    spiParams.mode = SPI_MASTER;
    spiParams.u.masterParams.bitRate = 10000000U;
    spiParams.u.masterParams.numSlaves = 1;
    spiParams.u.masterParams.slaveProf[0].chipSelect = 0;
    spiParams.u.masterParams.slaveProf[0].ramBufLen = MIBSPI_RAM_MAX_ELEM;
    spiParams.u.masterParams.slaveProf[0].dmaCfg.txDmaChanNum =1U;
    spiParams.u.masterParams.slaveProf[0].dmaCfg.rxDmaChanNum =0U;

    /* Enable output control for SPIA 3-pin Mode */
    if(SOC_SPIOutputCtrl(gMmwMssMCB.socHandle, 0U, 0U, &errCode) < 0)
        {
        /* Debug Message: */
        System_printf ("Debug: SOC_SPIOutputCtrl failed with Error [%d]\n", errCode);
        return;
        }


    /* Open the Logging SPI Instance: */
    System_printf("Opening SPI\n");
    gMmwMssMCB.loggingSpiHandle = SPI_open(0, &spiParams);
    if (!gMmwMssMCB.loggingSpiHandle) {
        System_printf("SPI did not open");
    }



I copied this function from the test code:

static bool Test_spiWrite(const SPI_Handle handle, void* buffer, uint32_t dataLen)
{

    System_printf("datalen 0x%x\n", dataLen);
    System_printf("0x%x 0x%x\n", buffer[0], buffer[1] );

    SPI_Transaction transaction;
    bool            ret = true;
#if 1
    //Configure Data Transfer
    transaction.count = dataLen;
    transaction.txBuf = buffer;
    transaction.rxBuf = NULL;
    //transaction.arg   = NULL;

    /* Start Data Transfer */
    ret = SPI_transfer(handle, &transaction);
    if (!ret) {
                System_printf("Unsuccessful SPI transfer 0x%x\n", ret);
            } else {
                System_printf("Successful SPI transfer 0x%x\n", ret);
            }
#else
    uint32_t        loop;
    char *          pBuff = buffer;
    for (loop=0; loop<dataLen/2; loop++)
    {
        /* Configure Data Transfer */
        transaction.count = 2;
        transaction.txBuf = pBuff;
        transaction.rxBuf = NULL;
        //transaction.arg   = NULL;

        /* Start Data Transfer */
        ret = SPI_transfer(handle, &transaction);
        if (!ret) {
            System_printf("Unsuccessful SPI transfer 0x%x, loop: 0x%x\n", ret, loop);

        }
        pBuff += 2;
    }


#endif
    return ret;
}

I call it from here:

Test_spiWrite(spiHandle, (uint8_t*)&header, sizeof(MmwDemo_output_message_header));

SPI_transfer always return 0, and I don't see any activity on the output pins of the device.


Can you tell what I am missing here?

Thanks

  • Hi Derek,

    Could you provide information about your test setup. What device you are using as SPI slave in your setup?

    Thanks

    Yogesh.

  • At the moment, I am using an oscilloscope.

    What I want to do is transmit a stream of data at a faster rate than I can through the serial UART..I am not expecting to read any data.  When I run my code, the return value from the SPI_transfer function is always 0.

    I have found that I can make it work is I disable DMA and use the function like this:

       uint32_t        loop;
        char *          pBuff = buffer;
        for (loop=0; loop<dataLen/2; loop++)
        {
            /* Configure Data Transfer */
            transaction.count = 2;
            transaction.txBuf = pBuff;
            transaction.rxBuf = NULL;
            transaction.slaveIndex = 0;
            //transaction.arg   = NULL;

            /* Start Data Transfer */
            ret = SPI_transfer(handle, &transaction);
            if (!ret) {
                System_printf("Unsuccessful SPI transfer 0x%x, loop: 0x%x\n", ret, loop);

            }
            pBuff += 2;
        }


    But that is pretty slow, and I would like see if setting dmaEnable on can yield a higher data throughput.

    I have been following the examples in the SDK test/spi directory, but I may not have it quite right.

  • Hi Derek,

    I can think of two reasons that can cause SPI_transfer function to returns false:

    1)  If transaction.slaveIndex is not initialized:

       //Configure Data Transfer
       transaction.count = dataLen;
       transaction.txBuf = buffer;
       transaction.rxBuf = NULL;
       //transaction.arg   = NULL;
       /* Start Data Transfer */
       ret = SPI_transfer(handle, &transaction);

    2) If dataLen is greater than MIBSPI_RAM_MAX_ELEM.

    Could you please verify and let me know if you still see the issue.

    Thanks

    Yogesh
      
      

  • Thank you. That was indeed the problem.