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/CC1350: how to connect External sd card to cc1350 ?

Part Number: CC1350

Tool/software: Code Composer Studio

I am using CC1350 . I want to use external memory for storage . I used External SD card module for that . Pin configuration is as follows 

VCC :- 3v3

Gnd:- Gnd

MOSI :- DIO9

MISO :- DIO8 

SCK :- DIO10

CS :- DIO11

In the code I used Sd_open and its working fine 

but SD_initailize is not returning any value 

Here is the Code

#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

/* Driver Header files */
#include <ti/drivers/GPIO.h>
#include <ti/drivers/SD.h>

/* Example/Board Header files */
#include "Board.h"

/* Buffer size used for the file copy process */
#define BUFFSIZE 10

/* Starting sector to write/read to */
#define STARTINGSECTOR 0

#define BYTESPERKILOBYTE 1024

/*
 * Set this constant to 1 in order to write to the SD card.
 * WARNING: Running this example with WRITEENABLE set to 1 will cause
 * any filesystem present on the SD card to be corrupted!
 */
#define WRITEENABLE 0

unsigned char textarray[BUFFSIZE];

unsigned char cpy_buff[BUFFSIZE];

/*
 * ======== mainThread ========
 * Task to perform a raw write and read from the SD card.
 * Note: Running this application will cause any filesystem on the
 * SD card to become corrupted!
 */
void *mainThread(void *arg0)
{
    static int_fast16_t result;
    uint_fast32_t cardCapacity;
    uint_fast32_t totalSectors;
    uint_fast32_t sectorSize;
    uint_fast32_t sectors;
    int i;
    SD_Handle sdHandle;

    GPIO_init();
    SD_init();

    /* Configure the LED pin */
    GPIO_setConfig(Board_GPIO_LED0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);

    /* Turn on user LED */
    GPIO_write(Board_GPIO_LED0, Board_GPIO_LED_ON);

    printf("Starting the SD example\n");

// System_flush();

    /* Initialize the array to write to the SD card */
    for (i = 0; i < BUFFSIZE; i++)
    {
        textarray[i] = i & 0xFF;
    }

    /* Mount and register the SD Card */
    sdHandle = SD_open(Board_SD0, NULL);
    if (sdHandle == NULL)
    {
        printf("Error starting the SD card\n");
// System_flush();
        while (1)
            ;
    }

// result = SD_initialize(sdHandle);
    if (SD_initialize(sdHandle) != SD_STATUS_SUCCESS)
    {
        printf("Error initializing the SD card\n");
// System_flush();
        while (1)
            ;
    }

    totalSectors = SD_getNumSectors(sdHandle);
    sectorSize = SD_getSectorSize(sdHandle);
    cardCapacity = (totalSectors / BYTESPERKILOBYTE) * sectorSize;

    printf("There are %u total sectors on the SD card.\n", totalSectors);
// System_flush();
    printf("The Read/Write sector size is %u bytes\n", sectorSize);
// System_flush();
    printf("The total card capacity is %u KB\n", cardCapacity);
// System_flush();

    /* Calculate number of sectors taken up by the array by rounding up */
    sectors = (sizeof(textarray) + sectorSize - 1) / sectorSize;

#if (WRITEENABLE)
    printf("Writing the array...\n");
// System_flush();

    result = SD_write(sdHandle, textarray, STARTINGSECTOR, sectors);
    if (result != SD_STATUS_SUCCESS)
    {
        printf("Error writing to the SD card\n");
// System_flush();
        while (1);
    }
#endif

    printf("Reading the array...\n");
// System_flush();
    result = SD_read(sdHandle, cpy_buff, STARTINGSECTOR, sectors);
    if (result != SD_STATUS_SUCCESS)
    {
        printf("Error reading from the SD card\n");
// System_flush();
        while (1)
            ;
    }

    /* Compare data read from the SD card with expected values */
    for (i = 0; i < BUFFSIZE; i++)
    {
        if (cpy_buff[i] != textarray[i])
        {
            printf("Data read from SD card differed from expected value\n");
// System_flush();
            printf(" Expected value for index %d: %d, got %d\n", i,
                   textarray[i], cpy_buff[i]);
// System_flush();
            printf("Run the example with WRITEENABLE = 1 to write expected values to the SD card\n");
// System_flush();
            break;
        }
    }

    if (i == BUFFSIZE)
    {
        printf("Data read from SD card matched expected values\n");
// System_flush();
    }

    SD_close(sdHandle);

    return (NULL);
}

  • Hi,

    When posting code onto the forum, please use the code formatting tool marked by the </> button. This allows the code to be easily read and can help you get support faster on the forums. I've modified your previous post to reflect the use of the tool.

    It looks like you're developing from the sdraw example. The default pin for the SD CS line is on DIO_21 (see gpioPinConfigs and sdspiHwAttrs in CC1350_LAUNCHXL.c). Did you try connecting the CS to that instead?

    Should further investigation be required, please post logic analyzer screenshots.



    Regards,
    Toby