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.

AM2634-Q1: How Can I use FIFO for Transmitting and Receiving data on UART

Part Number: AM2634-Q1
Other Parts Discussed in Thread: TMDSCNCD263, TMDSHSECDOCK

Tool/software:

I am using this TMDSCNCD263 board and this is the IO Extender TMDSHSECDOCK.

I have one requirement in my project like I need to give input on UART then i have to receive that input data on same UART after that i need to transmit that received data using UART FIFO and after some delay i have to read the UART FIFO and print on the console. My Data is 64bytes

Here is my code 

#include <string.h>
#include <kernel/dpl/DebugP.h>
#include "ti_drivers_config.h"
#include "ti_drivers_open_close.h"
#include "ti_board_open_close.h"
#include <time.h>

#define APP_UART_BUFSIZE (200U)
#define APP_UART_RECEIVE_BUFSIZE (64U)

uint8_t gUartBuffer[APP_UART_BUFSIZE];
uint8_t gUartReceiveBuffer[APP_UART_RECEIVE_BUFSIZE];
volatile uint32_t gNumBytesRead = 0U, gNumBytesWritten = 0U;

#define APP_UART_ASSERT_ON_FAILURE(transferOK, transaction) \
do { \
if((SystemP_SUCCESS != (transferOK)) || (UART_TRANSFER_STATUS_SUCCESS != transaction.status)) \
{ \
DebugP_assert(FALSE); /* UART TX/RX failed!! */ \
} \
} while(0)

void delay_ms(int milliseconds)
{
clock_t start_time = clock();
while (clock() < start_time + milliseconds * (CLOCKS_PER_SEC / 1000));
}

void uart_echo(void *args)
{
int32_t transferOK;
UART_Transaction trans;

Drivers_open();
Board_driversOpen();

DebugP_log("[UART] Echo example started ...\r\n");

UART_Transaction_init(&trans);

/* Send entry string */
gNumBytesWritten = 0U;
trans.buf = &gUartBuffer[0U];
strncpy((char *)trans.buf, "This is uart echo test blocking mode\r\nPlease input 64 bytes...\r\n", APP_UART_BUFSIZE);
trans.count = strlen((char *)trans.buf);
transferOK = UART_write(gUartHandle[CONFIG_UART_CONSOLE], &trans);
APP_UART_ASSERT_ON_FAILURE(transferOK, trans);

/* Read 64 bytes from UART console */
gNumBytesRead = 0U;
trans.buf = &gUartReceiveBuffer[0U];
trans.count = APP_UART_RECEIVE_BUFSIZE;
transferOK = UART_read(gUartHandle[CONFIG_UART_CONSOLE], &trans);
APP_UART_ASSERT_ON_FAILURE(transferOK, trans);
gNumBytesRead = trans.count;

/* Transmit the received data back */
DebugP_log("Transmitting %d bytes back: %.*s\r\n", gNumBytesRead, gNumBytesRead, gUartReceiveBuffer);
gNumBytesWritten = 0U;
trans.buf = &gUartReceiveBuffer[0U];
trans.count = gNumBytesRead;
transferOK = UART_write(gUartHandle[CONFIG_UART_CONSOLE], &trans);
if (transferOK != SystemP_SUCCESS) {
DebugP_log("UART write error occurred!\r\n");
} else {
DebugP_log("Successfully transmitted %d bytes\r\n", gNumBytesRead);
}
APP_UART_ASSERT_ON_FAILURE(transferOK, trans);


/* Delay for a short time to allow data transmission to complete */
ClockP_usleep(100000);

/* Prepare buffer for echoed data */
gNumBytesRead = 0U;
trans.buf = &gUartReceiveBuffer[0U];
trans.count = APP_UART_RECEIVE_BUFSIZE; // Adjust to the maximum size expected

/* Read the echoed data */
transferOK = UART_read(gUartHandle[CONFIG_UART_CONSOLE], &trans);
if (!transferOK) {
DebugP_log("UART read error occurred!\r\n");
} else {
gNumBytesRead = trans.count;
DebugP_log("Echoed %d bytes: %.*s\r\n", gNumBytesRead, gNumBytesRead, gUartReceiveBuffer);
}

/* Send exit string */
DebugP_log("All tests have passed!!\r\n");

Board_driversClose();
Drivers_close();
}

I can easily received the input data on uart but i am not sure after receiving data it transmitting back on same uart with FIFO or not. If it is using FIFO the i am not able to read back the data using FIFO

Can any help in in this regards

 

  • Hi Swati,

    I went through your code, but im failing to understand what the exact issue here is. Can you please in short help me understand what is the exact issue being faced?

    Regards,
    Shaunak

  • Hi Shaunak,

    Actually I need to check the FIFO for transmitting and receiving data in UART, So for this i was doing is First Transmitting data on UART and the receiving it on same UART but with some delay

  • Hi Swati, 

    I tried running your code and was able to successfully perform:

    1. Write the "This is uart echo test blocking mode\r\nPlease input 64 bytes.string using UART write

    2. Read the 64 byte input

    3. Then transmit the received data back on UART using UART write, then have a delay of 100ms

    4. Then read back the echoed data, only thing I changed was the error check in the last UART read, instead of 

    if (!transferOK) {
    DebugP_log("UART read error occurred!\r\n");
    } else {
    gNumBytesRead = trans.count;
    DebugP_log("Echoed %d bytes: %.*s\r\n", gNumBytesRead, gNumBytesRead, gUartReceiveBuffer);
    }

    I use 

    /* Read the echoed data */
        transferOK = UART_read(gUartHandle[CONFIG_UART_CONSOLE], &trans);
        APP_UART_ASSERT_ON_FAILURE(transferOK, trans);
        gNumBytesRead = trans.count;
        DebugP_log("Echoed %d bytes: %.*s\r\n", gNumBytesRead, gNumBytesRead, gUartReceiveBuffer);

    My Console output:

    The code is working, UART FIFO will be used for Tx and Rx but im unsure what the exact question here is? The second UART Read that you do is also being done from the UART console where the user will input data. After delay, do you want to directly read the UART FIFO and not get the 64B from user input? Because the code posted above in the question will read the UART console input from the user and not from the FIFO.

    Please elaborate if my understanding (the 4 points above) is what you are trying to achieve as well.

    I am able to write and read from the same UART (64 Bytes in this case).

    Regards,
    Shaunak

  • Hi Shaunak,

    yesterday i did the same which you suggested and i am also successfully done with this testing.

    Thanks for your support and Time

  • Hi Swati,

    Glad to know it worked!

    Thanks and best regards,
    Shaunak