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.

TMS570LC4357: Transmission and Reception using SCI

Part Number: TMS570LC4357
Other Parts Discussed in Thread: TMDX570LC43HDK, HALCOGEN

Hello team,

I want to transmit and receive message over SCI using Hercules Eval board (TMDX570LC43HDK). I’m able to transmit the required string through the code. However, I’m facing some issues with the received information. Picture below shows the flowchart of what exactly I want to achieve with the code. Also attached is the Terminal snapshot.

Below is my code snippet. Can you please help me with what I’ve been doing wrong?

 

/* USER CODE BEGIN (0) */
#include "HL_sci.h"
/* USER CODE END */

/* Include Files */

#include "HL_sys_common.h"

/* USER CODE BEGIN (1) */
static unsigned char command;
/* USER CODE END */

/** @fn void main(void)
*   @brief Application main function
*   @note This function is empty by default.
*
*   This function is called after startup.
*   The user can use this function to implement the application.
*/

/* USER CODE BEGIN (2) */
/* USER CODE END */

char text_send[]="Are you there??\n\r";
char resp1_send[]="Yeah!!!\n\r";
char resp2_send[]="Nope!!!\n\r";
//char text_recv[4]="\0";
char *text_recv;
char y[] = "yeah";
char n[] = "nope";

void main(void)
{
/* USER CODE BEGIN (3) */
    _enable_IRQ();

    sciInit();
    while(1)
    {
        sciSend(sciREG1, strlen(text_send), text_send);

        sciReceive(sciREG1, 4, *text_recv);
        command = strcmp(*text_recv, y);
        if (command == 1)
            //printf("Input is %s", y);
            sciSend(sciREG1, strlen(resp1_send), resp1_send);
        else
            //printf("Input is Nope");
            sciSend(sciREG1, strlen(resp2_send), resp2_send);
    }
/* USER CODE END */

}

/* USER CODE BEGIN (4) */
void sciNotification(sciBASE_t *sci, uint32 flags)
{
    sciSend(sci, 1, (unsigned char *)&command);
    sciReceive(sci, 1, (unsigned char *)&command);
}

void esmGroup1Notification(int bit)
{
    return;
}

void esmGroup2Notification(int bit)
{
    return;
}

/* USER CODE END */
 

Another query on the same line I’m facing is sending the counter value. I’ve written a code that transmits the counter value. The counter is initialized with value = 0 and then incremented upto 10000. Once the counter reaches 10000, it is reset to 0. This entire process is repeated infinitely. However, the issue is, no transmission is visible on the Terminal Program (Putty). Code snippet for the same is shown below. Can you please also help me with this?

/* USER CODE BEGIN (0) */
#include "HL_sci.h"
/* USER CODE END */
/* Include Files */
#include "HL_sys_common.h"
/* USER CODE BEGIN (1) */
/* USER CODE END */
/* USER CODE BEGIN (2) */
/* USER CODE END */

void main(void)
{
/* USER CODE BEGIN (3) */
    sciInit();
    unsigned long int counter1 = 0;
    while(1)
    {
        while (counter1 <10000)
        {
            while(sciIsTxReady(sciREG1) != 0)
            {
                sciSendByte(sciREG1, char(counter1));
            }
        }
        counter1 = 0;
    }
/* USER CODE END */
}

/* USER CODE BEGIN (4) */
/* USER CODE END */
 

Thanks!

H C Trivedi

  • Hi,

    1. I suggest to use interrupt mode for SCI receive

    2. Does Terminal (Putty) have the same SCI settings? 

    I don't see any instruction to increase the counter1, and don't think "char(counter1)" is correct.  --> the correct one is (char)(counter1++)

    Please try the SCI example code from HALCoGen help

  • Thanks for the prompt response Wang. I could make some progress on the same. Please find my code snippet below.

    /* USER CODE BEGIN (0) */
    #include "HL_sci.h"
    /* USER CODE END */
    
    /* Include Files */
    
    #include "HL_sys_common.h"
    
    /* USER CODE BEGIN (1) */
    char text_send[] = "Are you there?? \n \r";
    char resp1_send[] = "Yes, I'm!! \n \r";
    char resp2_send[] = "Nope, I'm not!! \n \r";
    static unsigned char command;
    unsigned int * data1;
    static int count1 = 0;
    /* USER CODE END */
    
    /** @fn void main(void)
    *   @brief Application main function
    *   @note This function is empty by default.
    *
    *   This function is called after startup.
    *   The user can use this function to implement the application.
    */
    
    /* USER CODE BEGIN (2) */
    /* USER CODE END */
    
    int main(void)
    {
    /* USER CODE BEGIN (3) */
        _enable_IRQ();
    
        sciInit();
        sciSend(sciREG1, strlen(text_send), text_send);
        //sciSend(sciREG1, 21, (unsigned char *)"Please press a key!! \r\n");
        //sciReceive(sciREG1, 1, (unsigned char *)&command);
        sciReceive(sciREG1, 4, &data1);
    
        while(1);
    
    /* USER CODE END */
    
        return 0;
    }
    
    
    /* USER CODE BEGIN (4) */
    void sciNotification(sciBASE_t *sci, uint32 flags)
    {
    
        /*if (command == 'y')
            //printf("Input is %s", y);
            sciSend(sciREG1, strlen(resp1_send), resp1_send);
        else if (command == 'n')
            sciSend(sciREG1, strlen(resp2_send), resp2_send);
        else
            //printf("Input is Nope");
            //sciSend(sciREG1, strlen(resp2_send), resp2_send);
            //sciSend(sci, 1, (unsigned char *) &command);
            sciSend(sci, 4, count1);
    
        count1++;*/
    
    
        if (strcmp(*data1, "yeah"))
            //printf("Input is %s", y);
            sciSend(sciREG1, strlen(resp1_send), resp1_send);
        else if (strcmp(*data1, "nope"))
            sciSend(sciREG1, strlen(resp2_send), resp2_send);
        else
            //printf("Input is Nope");
            //sciSend(sciREG1, strlen(resp2_send), resp2_send);
            //sciSend(sci, 1, (unsigned char *) &command);
            sciSend(sciREG1, strlen(*data1), *data1);
    
        sciSend(sciREG1, strlen(*data1), *data1);
        sciReceive(sci, 1, (unsigned char *) &command);
    }
    
    void esmGroup1Notification(int bit)
    {
        return;
    }
    
    void esmGroup2Notification(int bit)
    {
        return;
    }
    /* USER CODE END */
    

    I could use interrupt to receive the data. Progress made in line with my asked queries is as follows:

    1. I can now receive the data.
    2. using the received data, I can make required execution of commands.

    However, in line with my previous queries, I've been facing two issues:

    1. I still am not able to send the counter value over UART.
    2. I'm not able to receive and process the string input. for example, if you look at the code snippet provided, I can receive a single character and process the same (commented out in the code). however, while I define the integer pointer and use the sciReceive, I'm not able to proceed in the similar manner. Can you please look at it and share your thoughts? Basically I want to carry out the same thing as I mentioned in point 2 above, but instead of character, I want to use the strings.

    Thanks,

    H C Trivedi

  • Hello,

    To print a number, you need to convert the number to string or character first using the ASCII table. I wrote a function for you as a reference:

    void UART_send32BitData(sciBASE_t *sci, uint32_t data)
    {
         uint8_t c_get ;
         volatile int i = 0;
         for( i = 8 ; i > 0 ; i-- )
         {
              c_get = (data >> 28) & 15 ;
              if( c_get > 9 )
                   c_get += 7 ;
              c_get += 48 ;

              while ((sci->FLR & SCI_TX_INT) == 0) { /* wait */ };
              sci->TD = c_get;
              data = data << 4 ;
         }
    }

  • Can you please look at it and share your thoughts? Basically I want to carry out the same thing as I mentioned in point 2 above, but instead of character, I want to use the strings.

    A string in C is an array of characters followed by a NULL terminator. You can copy the received char array "comman[]" to s string:

    strncpy(string, command, 10);  //10 is the size of array command 

    string[10] = "\0";

    There are so many example code in the web for converting a number to a string or a string to a number.  

  • Thanks for the prompt response Wang. I'm working on the workaround you suggested and I'll get back to you in a while.

    Regards,

    H C Trivedi