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.

RTOS/CC2640: Adding SPI driver to a project and reading ADS1220

Part Number: CC2640
Other Parts Discussed in Thread: ADS1220, , ADS1292

Tool/software: TI-RTOS

Hello,

I'm really confused about adding a SPI code to my program. I want to read ADS1220 by SPI. I've followed many posts, but couldn't get my answer. here is my question: What is the difference between the following link tutorial and the code I added? 

processors.wiki.ti.com/.../Cc2640_Adding_a_UART_or_SPI_driver_to_a_Sample_Project

The code I found from sensor tag example and from the .h and .c files of SPI driver is:

    SPI_Params_init(&SPIparams);
    SPIparams.transferMode        = SPI_MODE_BLOCKING;
    SPIparams.bitRate  			  = 1000000;
    SPIparams.mode                = SPI_MASTER;
    SPIparams.dataSize            = 8;
    SPIhandle = SPI_open(0, &SPIparams);
    if (!SPIhandle) {
        System_printf("SPI did not open");
    }
    else {
        System_printf("SPI-0 initialized\n");
    }

and for reading:

   //////////////////////// SPI Reading /////////////////////////
    const uint8_t *buf =0;
        spiTransaction.count = 1;
        spiTransaction.txBuf = (void*)buf;
        spiTransaction.arg    = NULL;
        spiTransaction.rxBuf = NULL;
        int_fast16_t ret;


        ret = SPI_transfer(SPIhandle, &spiTransaction);
        if (!ret) {
             System_printf("Unsuccessful SPI transfer");
        }

The mentioned link is really complicated and when I follow it, there are many things undefined and it seems it's not done in SensorTag as well. Why do I have to add the TL and so on?

Now, my problem is on SPI_transfer in above code. It hangs there and I can't understand why. Even when I put a probe on SCLK, MISO or MOSI pins, there is no signal on that. Do I need to have more steps to be done? and initialize the PINs? Do I need to add PIN_open(&pinState, BoardSpiInitTable); ? How the SPI understand which pins are assigned? Only if I add a table like the following, the compiler will understand?

#define Board_SPI0_MISO             IOID_18
#define Board_SPI0_MOSI             IOID_19
#define Board_SPI0_CLK              IOID_17

I do appreciate your help as I'm really exhausted and confused about different definitions and codes. 

Amir

  • Hi Amir,

    The TL is used to communicate with a PC through UART or SPI. This is not your case since you want to communicate with the ADS1220 through SPI.

    You only need to add the SPI code to your project.

    You mention that you want to read, yet, you only assign a buffer to write. And that buffer points to the address 0.

    amirhossein shahshahani said:
    Now, my problem is on SPI_transfer in above code. It hangs there and I can't understand why. Even when I put a probe on SCLK, MISO or MOSI pins, there is no signal on that. Do I need to have more steps to be done? and initialize the PINs? Do I need to add PIN_open(&pinState, BoardSpiInitTable); ? How the SPI understand which pins are assigned? Only if I add a table like the following, the compiler will understand?

    All your SPI IOs should be defined in the BoardSpiInitTable (or GPIOInitTable) and you should call:

    PIN_init(BoardGpioInitTable)

    The function should return PIN_SUCCESS

    amirhossein shahshahani said:
    #define Board_SPI0_MISO IOID_18

    #define Board_SPI0_MOSI IOID_19

    #define Board_SPI0_CLK IOID_17

    These defines should already be in a Board.h or CC2640.h file

    You should have a CC2640.c file (the file name might change depending on how your created your project) that looks like this:

    /* SPI configuration structure, describing which pins are to be used */
    const SPICC26XXDMA_HWAttrsV1 spiCC26XXDMAHWAttrs[CC1350STK_SPICOUNT] = {
        {
            .baseAddr           = SSI0_BASE,
            .intNum             = INT_SSI0_COMB,
            .intPriority        = ~0,
            .swiPriority        = 0,
            .powerMngrId        = PowerCC26XX_PERIPH_SSI0,
            .defaultTxBufValue  = 0,
            .rxChannelBitMask   = 1<<UDMA_CHAN_SSI0_RX,
            .txChannelBitMask   = 1<<UDMA_CHAN_SSI0_TX,
            .mosiPin            = Board_SPI0_MOSI,
            .misoPin            = Board_SPI0_MISO,
            .clkPin             = Board_SPI0_CLK,
            .csnPin             = Board_SPI0_CSN
        },
        {
            .baseAddr           = SSI1_BASE,
            .intNum             = INT_SSI1_COMB,
            .intPriority        = ~0,
            .swiPriority        = 0,
            .powerMngrId        = PowerCC26XX_PERIPH_SSI1,
            .defaultTxBufValue  = 0,
            .rxChannelBitMask   = 1<<UDMA_CHAN_SSI1_RX,
            .txChannelBitMask   = 1<<UDMA_CHAN_SSI1_TX,
            .mosiPin            = Board_SPI1_MOSI,
            .misoPin            = Board_SPI1_MISO,
            .clkPin             = Board_SPI1_CLK,
            .csnPin             = Board_SPI1_CSN
        }
    };

    This is how TI-RTOS knows which IOs to use for your SPI.

    In your project., make sure that you also call

    Board_initGeneral();
    Board_initSPI();

    Regards,

    Michel

    EDIT:
    I found this thread which has some SPI code to communicate with an ADS1292 if you want to see it.

  • Hello,

    Thank you for the clear respond. I checked and I had all parts you mentioned. Still, I have the same issue with SPI_transfer. And no signal on any GPIOs. is there any conflict between peripherals? My I2C seemed working, but I've just disabled it. What should I check to debug and update you?

    Thank you,

    Amir