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/LP-CC2652RB: CCS/LP-CC2652RB

Part Number: LP-CC2652RB
Other Parts Discussed in Thread: SYSCONFIG,

Tool/software: Code Composer Studio

Hello all,

I want to interface sd card module (SPI-based) with TI CC2652 , i have to store data in the sd card. I am receiving the incoming data from arduino via uart.
How should i start.

Thanks,

shivam 

  • I am currently using the sdraw example code after building and running the code i am getting the message "error initializing the SD Card" 
    How to correct the message.

  • Do you connect SD card?

  • I am connecting the SD card through spi interface miso - dio8

    Mosi - dio 9

    SPICLK - dio 10

    SPICS - dio 11

    I am using the sd card module breakout board that is used with Arduino sd card module.

  • Here is the picture of sd card module that i am using.

  • Try to refer to and make sure you connect all SD necessary pins correctly.

  • In this the pins are different as mentioned above.

    Is the booster module connects with sd card via SPI?

    Also the connections for booster pack are as below:

    SPI_clk : dio7

    SD_CS : dio 8/12

    SPI_MISO : dio 14

    SPI_MOSI : dio15

    Do I have to change the connections as per booster pack or they are using some other method for interface.

  • Do you read and check your hW connection?

  • Yes i have read the doc, the sd raw code is meant for this booster pack and i am using LPCC2652 so how to use this launchpad with sdraw code example.
    The SPI pin configuration is different for booster pack and cc2652, how to change the code according to cc2652.

  • According to sdraw example sysconfig, it use DIO10 as SCLK, DIO8 as MISO, DIO9 as MOSI, and DIO21 as CS. If you check the document, why do you still use different SPI pins to the document?

  • I am using different pins as they are mentioned in the pinout diagram of CC2652 launchpad.
    According to sdraw example, these pins are for booster pack which are different as compared to cc2652 LP.

  • I just test sdraw example with LP-CC2652RB and I can confirm it uses those pins.

  • Okay thanks a lot, i changed CS pin to dio 21 i think its working though i have not written anything on it yet.
    Further, i want to receive data from arduino RX/TX via UART onto cc2562 UART and store it in an SD card.

    What should be my approach.

    Thanks,

    shivam

  • You can try to combine uartecho project and sdraw project together to make it.

  • Hello YC, i tried but i am unable to successfully combine both the codes.
    Please help its important for me.
    Please take a look at the code.

    sduart.txt
    #include <file.h>
    #include <stdbool.h>
    #include <stddef.h>
    #include <stdint.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <time.h>
    #include <third_party/fatfs/ffcio.h>
    /* Driver Header files */
    #include <ti/display/Display.h>
    #include <ti/drivers/GPIO.h>
    #include <ti/drivers/SDFatFS.h>
    #include <ti/drivers/UART.h>
    /* Driver configuration */
    #include "ti_drivers_config.h"
    /* Buffer size used for the file copy process */
    #ifndef CPY_BUFF_SIZE
    #define CPY_BUFF_SIZE       2048
    #endif
    /* String conversion macro */
    #define STR_(n)             #n
    #define STR(n)              STR_(n)
    /* Drive number used for FatFs */
    #define DRIVE_NUM           0
    const char inputfile[] = "fat:"STR(DRIVE_NUM)":input.txt";
    const char outputfile[] = "fat:"STR(DRIVE_NUM)":output.txt";
    const char textarray[] = \
    "***********************************************************************\n"
    "0         1         2         3         4         5         6         7\n"
    "Hello from System Integration Lab  Ncflexe\n";
    static Display_Handle display;
    /* File name prefix for this filesystem for use with TI C RTS */
    char fatfsPrefix[] = "fat";
    unsigned char cpy_buff[CPY_BUFF_SIZE + 1];
    
    void *mainThread(void *arg0)
    {
        char input;
        const char  echoPrompt[] = "Echoing characters:\r\n";
        UART_Handle uart;
        UART_Params uartParams;
    
        SDFatFS_Handle sdfatfsHandle;
    
        /* Variables for the CIO functions */
        FILE *src, *dst;
    
        /* Variables to keep track of the file copy progress */
        unsigned int bytesRead = 0;
        unsigned int bytesWritten = 0;
        unsigned int filesize;
        unsigned int totalBytesCopied = 0;
    
        /* Call driver init functions */
        GPIO_init();
        UART_init();
        Display_init();
        SDFatFS_init();
    
        /* Configure the LED pin */
        GPIO_setConfig(CONFIG_GPIO_LED_0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
    
        /* add_device() should be called once and is used for all media types */
        add_device(fatfsPrefix, _MSA, ffcio_open, ffcio_close, ffcio_read,
            ffcio_write, ffcio_lseek, ffcio_unlink, ffcio_rename);
    
        /* Open the display for output */
        display = Display_open(Display_Type_UART, NULL);
        if (display == NULL) {
            /* Failed to open display driver */
            while (1);
        }
    
        /* Turn on user LED */
        GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_ON);
    
        Display_printf(display, 0, 0, "Starting the fatsd example\n");
        Display_printf(display, 0, 0,
            "This example requires a FAT filesystem on the SD card.\n");
        Display_printf(display, 0, 0,
            "You will get errors if your SD card is not formatted with a filesystem.\n");
    
        /* Mount and register the SD Card */
        sdfatfsHandle = SDFatFS_open(CONFIG_SDFatFS_0, DRIVE_NUM);
        if (sdfatfsHandle == NULL) {
            Display_printf(display, 0, 0, "Error starting the SD card\n");
            while (1);
        }
        else {
            Display_printf(display, 0, 0, "Drive %u is mounted\n", DRIVE_NUM);
        }
        /* Create a UART with data processing off. */
            UART_Params_init(&uartParams);
            uartParams.writeDataMode = UART_DATA_BINARY;
            uartParams.readDataMode = UART_DATA_BINARY;
            uartParams.readReturnMode = UART_RETURN_FULL;
            uartParams.baudRate = 115200;
    
            uart = UART_open(CONFIG_UART_0, &uartParams);
    
            if (uart == NULL) {
                /* UART_open() failed */
                while (1);
            }
    
            //UART_write(uart, echoPrompt, sizeof(echoPrompt));
    
            /* Loop forever echoing */
            /*while (1) {
                UART_read(uart, &input, 1);
                UART_write(uart, &input, 1);
            }*/
        /* Try to open the source file */
        src = fopen(inputfile, "r");
        if (!src) {
            Display_printf(display, 0, 0, "Creating a new file \"%s\"...",
                inputfile);
    
            /* Open file for both reading and writing */
            src = fopen(inputfile, "w+");
            if (!src) {
                Display_printf(display, 0, 0,
                    "Error: \"%s\" could not be created.\nPlease check the "
                    "Board.html if additional jumpers are necessary.\n",
                    inputfile);
                Display_printf(display, 0, 0, "Aborting...\n");
                while (1);
            }
            while (1)
            {
                        UART_read(uart, &input1, 1);
                        UART_write(uart, &input1, 1);
                        fwrite(textarray, 1, strlen(textarray), src);
                        fwrite(input1,1,strlen(input1),src);
                        fflush(src);
            }
    
            /* Reset the internal file pointer */
            rewind(src);
    
            Display_printf(display, 0, 0, "done\n");
        }
        else {
            Display_printf(display, 0, 0, "Using existing copy of \"%s\"\n",
                inputfile);
        }
    
        /* Create a new file object for the file copy */
        dst = fopen(outputfile, "w");
        if (!dst) {
            Display_printf(display, 0, 0, "Error opening \"%s\"\n", outputfile);
            Display_printf(display, 0, 0, "Aborting...\n");
            while (1);
        }
        else {
            Display_printf(display, 0, 0, "Starting file copy\n");
        }
    
        /*  Copy the contents from the src to the dst */
        while (true) {
            /*  Read from source file */
            bytesRead = fread(cpy_buff, 1, CPY_BUFF_SIZE, src);
            if (bytesRead == 0) {
                break; /* Error or EOF */
            }
    
            /*  Write to dst file */
            bytesWritten = fwrite(cpy_buff, 1, bytesRead, dst);
            if (bytesWritten < bytesRead) {
                Display_printf(display, 0, 0, "Disk Full\n");
                break; /* Error or Disk Full */
            }
    
            /*  Update the total number of bytes copied */
            totalBytesCopied += bytesWritten;
        }
    
        fflush(dst);
    
        /* Get the filesize of the source file */
        fseek(src, 0, SEEK_END);
        filesize = ftell(src);
        rewind(src);
    
        /* Close both inputfile[] and outputfile[] */
        fclose(src);
        fclose(dst);
    
        Display_printf(display, 0, 0,
            "File \"%s\" (%u B) copied to \"%s\" (Wrote %u B)\n",
            inputfile, filesize, outputfile, totalBytesCopied);
    
        /* Now output the outputfile[] contents onto the console */
        dst = fopen(outputfile, "r");
        if (!dst) {
            Display_printf(display, 0, 0, "Error opening \"%s\"\n", outputfile);
            Display_printf(display, 0, 0, "Aborting...\n");
            while (1);
        }
    
        /* Print file contents */
        while (true) {
            /* Read from output file */
            bytesRead = fread(cpy_buff, 1, CPY_BUFF_SIZE, dst);
            if (bytesRead == 0) {
                break; /* Error or EOF */
            }
            cpy_buff[bytesRead] = '\0';
            /* Write output */
            Display_printf(display, 0, 0, "%s", cpy_buff);
        }
    
        /* Close the file */
        fclose(dst);
    
        /* Stopping the SDCard */
        SDFatFS_close(sdfatfsHandle);
        Display_printf(display, 0, 0, "Drive %u unmounted\n", DRIVE_NUM);
    
        return (NULL);
    }
    
    /*
     *  ======== fatfs_getFatTime ========
     */
    int32_t fatfs_getFatTime(void)
    {
        /*
         *  FatFs uses this API to get the current time in FatTime format.  User's
         *  must implement this function based on their system's timekeeping
         *  mechanism.  See FatFs documentation for details on FatTime format.
         */
        /* Jan 1 2017 00:00:00 */
        return (0x4A210000);
    }
    

  • Can you elaborate or specify what is your problem?

  • Yes sure, my final goal is receiv string characters from Arduino to cc2652 via UART and save those characters into sd card via SPI.

    For now I want to verify whether I can receive characters from Arduino tx/rx to cc2652 and to view the received characters on cc2652 side serial port. Not just by connecting TX of debugger.

  • When i am combining both the codes, i am unable to get the receive the string characters from arduino uart is there any function or logic which i can use to receive characters from arduino. In arduino the similar thing is if (Serial.available()). How can i do the same here.

  • I remember you had been able to receive UART data from Arduino. What did you do to make it doesn’t work now?

  • I don't know, but I am doing the same thing flashing UART echo code to ti cc2652 LP and connecting Arduino TX/RX to CC2652 RX/TX. But I am not getting the data.

    Is there anything else I need to do apart from this?

  • I had shown you how to do it at