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: Code for receiving data from another micro controller to CC2652RB-LP via UART

Part Number: LP-CC2652RB


Tool/software: Code Composer Studio

Hello, i have to receive data from arduino RX/TX to TX/RX of CC2562RB LP via UART. What code i should use i have tried Uart Echo but unable to view the data when i am trying to view it in Serial port of CC2652 RB-LP.

Thanks,

shivam

  • Hello Shivam,

    Did you configure the terminal correctly?

    https://dev.ti.com/tirex/explore/content/simplelink_academy_cc13x2_26x2sdk_4_10_01_00/modules/debug/debugging_output/debugging_output.html#software

    Dd you plug the launchpad directly into your computer instead of through a separate usb hub.

  • Yes Erik it got solved i was on it the whole day.
    Anyways, thanks for your reply.
    Can you suggest me how i can write the received uart characters into an SD card.

    regards,

    shivam

  • No eirik, the help there is regarding connections with sd card hardware module. I have done that interface and i am able to verify the sd card connections and create a txt file. Now i want to write the incoming uart characters which i am unable to do.

    It would be a great help if you can let me know what changes i need to make in fatsd example code to write the incoming uart characters in the created input txt file.

    Thanks a lot, i appreciate your support.

    regards,

    shivam

  • Hello Shivam,

    I don't have a ready made solution for you, but you can reference the cpy_buff array in fatsd.c for how to transfer bytes. You can, For example, collect a few bytes from UART and place those in a similar array and try to write those values to your SD card with the fwrite function. Eventually you can make a linked list as I described for you here:

    https://e2e.ti.com/support/tools/ccs/f/81/p/916306/3386935#3386935

  • Yes that's exactly what i want to do, but is it necessary to use linked list. I mean as uart_read & uart_write take char datatype as an input parameter.
    can't i just use these char values and store it in textarray directly as in fatsd example code something below:

    char c = uart_read(uart, &input, 1);

    for(int i =0; i< strlen (textarray); i++)

    textarray[i] = c;

    }

    fwrite (textarray, 1, strlen(textarray), src);

    Thanks a lot for your support eirik. I appreciate your inputs.

    Sorry for my programming concepts, i have always been using arduino. This is my first time with TI platform, i hope i love it.

    Thanks,

    shivam

  • Hello Shivam,

    Yes, I believe this will work although this will be an array of i number of identical characters as you simply copy the same character from UART into textarray. 

    http://www.cplusplus.com/reference/cstdio/fwrite/

  • Hi eirik,

    Its not working. 
    Neither i am able to receive characters nor i am able to write it in the sd card.

    Take a look at the attached file.

    #include <file.h>
    #include <stdbool.h>
    #include <stdint.h>
    #include <stddef.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/UART.h>
    #include <ti/drivers/SDFatFS.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";
    char textarray[100];
    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;
        unsigned int i=0;
        UART_Handle uart;
        UART_Params uartParams;
        SDFatFS_Handle sdfatfsHandle;
        /* Variables for the CIO functions */
        FILE *src;
        unsigned int filesize;
    /* 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);
    /* Turn on user LED */
        GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_ON);
    /* 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);
        }
        /* Loop forever echoing */
        while (1)
        {
            
            /* 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);
                           }
    
            for (i=0; i < strlen (textarray); i++ )
            {
                char c = UART_read(uart, &input, 1);
                UART_write(uart, &input, 1);
                textarray [i] = c;
            }
            /* 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);
                }
            fwrite (textarray,1,strlen(textarray),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);
                }
    }
    }
    
    /*
     *  ======== 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);
    }
    
    
    
    
    
    

    regards,

    shivam