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.

CC2650: SPI - SD card call

Part Number: CC2650


Hello,

Could you please give me any help about how I can build an SPI communication between CC2650EM-7ID-RD and a SD card through spi? I use the corresponding libraries and also, I change the Board.c file, according to the following lines: 

/* Include drivers */
#include "SDSPICC2650.h"
#include <ti/drivers/SDSPI.h>
/* SPI objects */
SDSPICC2650_Object sdspiCC2650_Object[CC2650_SPICOUNT];

/* SDSPI configuration structure, describing which pins are to be used */
const SDSPICC2650_HWAttrs sdspiCC2650HWAttrs[CC2650_SPICOUNT] = {
  {
    .baseAddr=SSI0_BASE,  // or I declare SSI3_
    .powerMngrId = PERIPH_SSI0,
    .pinSCK=Board_SPI0_CLK,
    .pinMISO=Board_SPI0_MISO,
    .pinMOSI=Board_SPI0_MOSI,
    .pinCS=Board_SPI0_CSN
    }
};


PIN_Handle ledPinHandle;  // for the SD card
PIN_State newPinState;

PIN_Config ledPinTable[] = {
    Board_SPI0_CSN| PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
    Board_SPI0_MISO | PIN_INPUT_EN | PIN_PULLDOWN,
    Board_SPI0_MOSI | PIN_INPUT_EN | PIN_PULLDOWN,
    Board_SPI0_CLK | PIN_INPUT_EN | PIN_PULLDOWN,
    PIN_TERMINATE
};
​Do you see that something is wrong? I have seen the following posts
[1]
[2]

[3] 192.237.145.96/.../560104

and as I can understand, I follow the same logic, but the SPI doesn't respond and also, when I call the function which open SPI and tries to read/write, the BLE stops to advertise. I create a function SDcommunication(), where I init SDSPI_init() and I start to write and read one char buffer[30] (for example). I call the "SD communication()" inside the main() or inside the "SimpleBLEPeripheral_taskFxn()" , but nothing happens. Only BLE stops to advertise. SPI does not respond. Could you please help me with any quideline? Everything seems to be logical, but the SPI doesn't respond.

void SDcommunication(void)    
{
    SDSPI_Handle sdspiHandle;
    SDSPI_Params sdspiParams;
    SDSPI_init();
    SDSPI_Params_init(&sdspiParams);
    sdspiHandle = SDSPI_open(Board_SDSPI0, DRIVE_NUM, &sdspiParams);
    f_write().....
    SDSPI_close(sdspiHandle);
}

Thank you in advance for your time,

  • You should not use the SDSPI APIs with C26xx as it's not made for CC26xx. You should just use SPI_Transfer and make it a SD card protocol.
  • Hello Christin,

    thank you for your message. Could you please give me a small example ? 

    Also, could you please let me know which bitRate I could use? The manual mentions more than 2MHz. Have you ever tried this? I am looking forward to hearing from you.

    Thank you,

  • The max SPI speed is 4M Hz.
  • Hi,

    We don't have SDSPI example, but you can just implement the protocol by using SPI transfer. As long you sent it the correct data, then it should work. I have seen others success communicating with SD card using CC26xx SPI apis.

    You will have to do some modification as for SD card protocol, the MISO has to be set to pull-up while our SPI protocol initialize to a different config than that.

    What I can recommend you to do is to take a look at MSP432 SDSPI driver and implement one for CC26xx. In the MSP432 SDSPI driver, it also includes how to read/write to SD card.

    The TI-RTOS for MSP432 can be downloaded here :
    www.ti.com/.../MSP432-RTOS
    C:\ti\tirtos_msp43x_2_20_00_06\products\tidrivers_msp43x_2_20_00_08\packages\ti\drivers\sdspi
  • Hello,

    I would like to thank you a lot for your help. Should I use another SSI, for example SSI2 or SSI3 and to define it in the "Board.c"?
    Also, should I define other parameters apart from "bitRate"? Should I define CPOL CPHA mode for the clock and where?

    Thank you in advance for your time,
  • You can find the example code of how to initialize SPI in SPICC26XXDMA.h or the documentation of TI-RTOS driver which comes with the TI-RTOS or BLE stack installation. (ex : C:/ti/tirtos_cc13xx_cc26xx_2_20_01_08/docs/Documentation_Overview_cc13xx_cc26xx.html)

     *  // Callback function
     *  static void transferCallback(SPI_Handle handle, SPI_Transaction *transaction)
     *  {
     *      // Start another transfer
     *      SPI_transfer(handle, transaction);
     *  }
     *
     *  static void taskFxn(UArg a0, UArg a1)
     *  {
     *      SPI_Handle handle;
     *      SPI_Params params;
     *      SPI_Transaction transaction;
     *      uint8_t buf[16];                  // Receive and transmit buffer
     *
     *      // Init SPI and specify non-default parameters
     *      SPI_Params_init(&params);
     *      params.bitRate             = 1000000;
     *      params.frameFormat         = SPI_POL1_PHA1;
     *      params.mode                = SPI_SLAVE;
     *      params.transferMode        = SPI_MODE_CALLBACK;
     *      params.transferCallbackFxn = transferCallback;
     *
     *      // Configure the transaction
     *      transaction.count = 16;
     *      transaction.txBuf = buf;
     *      transaction.rxBuf = buf;
     *
     *      // Open the SPI and initiate the first transfer
     *      handle = SPI_open(Board_SPI, &params);
     *      SPI_transfer(handle, &transaction);
     *
     *      // Wait forever
     *      while(true);
     *  }

  • Dear Christin,

    Thank you very much for your help. It is really valuable because I still have the same problem with SPI.

    I follow MSP430 library as you told in a previous message and my SDSPI_open() function is the following and with the following command,I believe that I say to the SPI to work with CPOL, CPHA = 0 in Master mode. Am I in the right path? Thank you a lot for your valuable time.

    --> SSIConfigSetExpClk(hwAttrs->baseAddr, freq.lo, SSI_FRF_MOTO_MODE_0, SSI_MODE_MASTER, 400000, 8);



    SDSPI_Handle SDSPICC2650_open(SDSPI_Handle handle,
    
                               unsigned char drv,
    
                               SDSPI_Params *params)
    
    {
    
       DRESULT                   dresult;
    
       FRESULT                   fresult;
    
       unsigned int              key;
    
       xdc_runtime_Types_FreqHz  freq;  
    
       TCHAR                     path[3];
    
       SDSPICC2650_Object         *object = handle->object;
    
       SDSPICC2650_HWAttrs const  *hwAttrs = handle->hwAttrs;
    
       object->driveNumber = drv;
    
       Hwi_restore(key);
    
       /* Store the SDSPI parameters */
    
       if (params == NULL) {
    
           /* No params passed in, so use the defaults */
    
           params = (SDSPI_Params *) &SDSPI_defaultParams;
    
       }
    
      object->bitRate = (object->diskState == STA_NOINIT) ? 400000 : params->bitRate;
    
       IOCPinTypeSsiMaster(hwAttrs->baseAddr, hwAttrs->pinMISO, hwAttrs->pinMOSI,hwAttrs->pinCS,hwAttrs->pinSCK);
    
       /* Pin used for Chip Select */
    
       IOCPinTypeGpioOutput(hwAttrs->pinCS);
    
       /* Raise the chip select pin */
    
       PIN_setOutputValue(ledPinHandle, hwAttrs->pinCS, 0);  
    
       /* Register power dependency - i.e. power up and enable clock for SPI. */
    
       Power_setDependency(hwAttrs->powerMngrId);
    
       BIOS_getCpuFreq(&freq);
    
       SSIConfigSetExpClk(hwAttrs->baseAddr, freq.lo, SSI_FRF_MOTO_MODE_0,
    
                          SSI_MODE_MASTER, 400000, 8);
    
       Log_print2(Diags_USER1, "SDSPI:(%p) CPU freq: %d; SDSPI freq to 400000 kHz",
    
                  hwAttrs->baseAddr, freq.lo);
    
       SSIEnable(hwAttrs->baseAddr);
    
       /* Register the new disk_*() functions */
    
       dresult = disk_register(object->driveNumber,
    
                               SDSPICC2650_diskInitialize,
    
                               SDSPICC2650_diskStatus,
    
                               SDSPICC2650_diskRead,
    
                               SDSPICC2650_diskWrite,
    
                               SDSPICC2650_diskIOctrl);
    
       fresult = f_mount(&(object->filesystem), path, 0);
    
       if (fresult != FR_OK) {
    
           Log_error2("SDSPI:(%p) drive %d not mounted",
    
                       hwAttrs->baseAddr, object->driveNumber);
    
           SDSPICC2650_close(handle);
    
           return (NULL);
    
       }
    
       /* Store the new SDSPI handle for this FatFs drive number */
    
       sdspiHandles[drv] = handle;
    
       Log_print1(Diags_USER1, "SDSPI:(%p) opened", hwAttrs->baseAddr);
    
       return (handle);
    
    }

  • Dear Christin,

    I can read/write raw data through SPI, by using callback function. The problem is when I try to interface it with a SD Card. I follow the MSP432 example and I cannot understand why my SPI doesn't respond. To be more precise, sometimes the SPI gives MISO/MOSI signals, sometimes doesn't give any signal and other times, a message is apeared to my logic analyzer: " the clock settings don't match with the initial (idle) state", provided that I give specific declaration for the clock POL and PHAse (defined at 0 and 0)!
    Do you understand which is the problem?
  • Have you modified CC26XX SPI driver ( SPICC26XXDMA.c)so that the MISO (has to be set to pull-up)pin is configured correctly?
    I don't see any IO initialization in your code.

    You should modify the SPICC26XXDMA.c file to make sure the pin_init is correct. The pin initialization for SPI module can be found in function SPICC26XXDMA_initIO
  • Hello Christin,

    Before I call the SDSPI_init(), I build the following pin table:
    PIN_Config SPIPinTable[] = {
    Board_SPI0_CSN| PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
    Board_SPI0_MISO | PIN_INPUT_EN | PIN_PULLDOWN,
    Board_SPI0_MOSI | PIN_INPUT_EN | PIN_PULLDOWN,
    Board_SPI0_CLK | PIN_INPUT_EN | PIN_PULLDOWN,
    PIN_TERMINATE
    };

    PIN_Handle SPIPinHandle; // for the SD card
    SPIPinHandle = PIN_open(&newPinState, SPIPinTable); // Open SD pins

    I have declared them as pulldown!
    I will see again what you mention to me concerning the "SPICC26XXDMA.c" .

    Kind regards,
  • Please take a look at SPICC26XXDMA file and use the APIs there instead of using it with a pin driver, this would make it easier.

    Because not only you need to configure the pin as pull down, you also need to set pin mux to use it for SSI protocol.
  • Hello,

    [1] Could someone give me officially the declarations for the 4 pins of SPI (MISO, MOSI, SCK, CS) if I would like for the SPI to work with a clock in CPOL=CPHA=0 ?

    [2] Also, I use master mode for the SPI. Is it right?

    [3] How can I say to SSI to work with MSB or LSB first?

    [4] With which command could I assign a clock frequency to the SSI ?

    Thank you,