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.

TMS570LS1224: Issue of internal loopback test for UART poll mode

Part Number: TMS570LS1224
Other Parts Discussed in Thread: LAUNCHXL2-TMS57012, , HALCOGEN

Hi,

I'm verifying communication via UART on the launchpad of LAUNCHXL2-TMS57012, which will drive RS485 transceiver. Test of sending and receiving a single character in poll mode is successful. However, the test of sending and receiving multiple characters is failed. The testing characters are "abcdefg". The phenominon seems like it can only receive some specific characters such as "fg" or "efg" or "gefg" instead of "abcdefg". Please help me find out why this happened.

The following are my test procedure.

1) I use SCI in internal loopback mode. The configurations are like below.

2) I use RTICompare0 counter0 to trigger sending 7 characters of "abcdefg" in poll mode every 200 ms. The configurations are like below.

3) I use pin clk of mibspi3 port (driving a yellow LED) to indicate sending 7 characters of "abcdefg" in poll mode every 200 ms, and bit 1 of gio portb (driving USR LED A)to indicate correct receiving characters. I use pin cs3 of mibspi3 port (input) to switch the conditions between expected character of "abcdefg" and specific characters "fg" or "efg" or "gefg" in order to observe which characters are received on earth. The configurations are like below.

4) Buffer of receiving was observed once when the program stopped by breakpoint.

4) The test code is like below.

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

/* Include Files */

#include "sys_common.h"

/* USER CODE BEGIN (1) */
#include "gio.h"
#include "mibspi.h"
#include "sci.h"
#include "rti.h"
/* 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) */
unsigned char txBuffer[7]={'a','b','c','d','e','f','g'};
unsigned char rxBuffer[7];
int len=7;
/* USER CODE END */

int main(void)
{
/* USER CODE BEGIN (3) */
    gioInit();
    mibspiInit();//PIN_CLK for output; PIN_CS3 for input
    sciInit();

    /* Enable interrupt */
    _enable_IRQ();

    while(sciIsIdleDetected(sciREG));
    sciEnableLoopback(sciREG, Digital_Lbk);

    rtiInit();
    /* Enable RTI compare 0 notification */
    rtiEnableNotification(rtiNOTIFICATION_COMPARE0);
    /* Start counter */
    rtiStartCounter(rtiCOUNTER_BLOCK0);

    while(1)
    {
        gioToggleBit(gioPORTB, 2);

        rxBuffer[0]=0;
        rxBuffer[1]=0;
        rxBuffer[2]=0;
        rxBuffer[3]=0;
        rxBuffer[4]=0;
        rxBuffer[5]=0;
        rxBuffer[6]=0;
        sciReceive(sciREG, len, rxBuffer);
        if(1==gioGetBit(mibspiPORT3, PIN_CS3))  //Changing the condition online to confirm received characters in rxBuff are wrong online.  pin9@J5, 0:pin2@J3 or pin1@J5, 1:pin1@J2
        {
            if(rxBuffer[0]=='a'&&rxBuffer[1]=='b'&&rxBuffer[2]=='c'&&rxBuffer[3]=='d'&&rxBuffer[4]=='e'&&rxBuffer[5]=='f'&&rxBuffer[6]=='g')
                gioToggleBit(gioPORTB, 1);
        }
        else
        {
            if((rxBuffer[0]=='f'&&rxBuffer[1]=='g')
             ||(rxBuffer[0]=='e'&&rxBuffer[1]=='f'&&rxBuffer[2]=='g')
             ||(rxBuffer[0]=='g'&&rxBuffer[1]=='e'&&rxBuffer[2]=='f'&&rxBuffer[3]=='g')) //Characters were observed by setting break points at line of while(1) after next else
                gioToggleBit(gioPORTB, 1);
            else
                while(1);
        }
    }
/* USER CODE END */

    return 0;
}


/* USER CODE BEGIN (4) */
void rtiNotification(uint32 notification)
{
        sciSend(sciREG, len, txBuffer);
        gioToggleBit(mibspiPORT3, PIN_CLK);//pin7@J2, 0:pin2@J3
}
/* USER CODE END */

best regards

Datïan

  • Hello,

    Please call sciReceive(sciREG, len, rxBuffer) before starting the RTI counter.

    If sciReceive() is not called, the SCI ISR uses LEN=0 to read the incoming chars. 

  • Thanks again. I'll check it.

    regards

    Datïan

  • Hi, QJ.

    To make sure my modification is identical to your suggestion, I attach the modification as below. Left side is original. The red circle is added part. I'm afraid the program will be blocked by sciReceive.

    regards

    Datïan

  • Hello Ditian,

    I am sorry. This way is good for interrupt mode, not for polling mode. For polling mode, please check the RX flag before reading the data. This is an example:

    for (i=0; i<len; i++)

    {

    while ((UART->FLR & 0x4) == 4);
    while ((UART->FLR & (uint32)SCI_TX_INT) == 0U);
    UART->TD = text[i];

    while ((UART->FLR & (uint32)SCI_RX_INT) == 0U);
    rxdata[i] = (UART->RD & 0x000000FFU);

    };

    for(i=0; i<len; i++){

    if(rxdata[i] != text[i])
    err++;

    }

  • Hello QJ,

    Many thanks for your sample code. It works indeed, but not solves my issue. What I concern is test of sending and receiving multiple character, not only character by character .

    In sci.c I found the functions of sciSend and sciReceive. According to the names, I think the functions of sciSend and sciReceive are for multiple characters. The description of sciReceive function also shows it is possible to call sciReceive in poll mode. But I failed to do that.

    regards

    Datïan

  • Hi Datian,

    In my example code, len is the number of characters you want to tx and rx.

    if using single buffer mode, and TX and RX on the same device, there is no way to send multiple characters first, then read them later.

    If you want to transfer multiple chars, please consider to use multi-buffer mode.

  • Thank you QJ.

    Would you like to give me some references about multi-butter mode or uart for TMS570LS1224 in more detail?

    kind regards

    Datïan

  • Hello,

    Please read 29.2.5 SCI Multi-Buffered Mode in TRM SPNU515C.pdf

  • Hi QJ,

    Many thanks for your information. Sometimes I can not find what I want, although I believe it might be somewhere.

    regards

    Datïan

  • Hi Datian,

    You don't have to use multi-buffered mode. The code you gave you is good enough to check if the received char is the same as the transmitted data.

  • QJ Wang said:

    Hi Datian,

    You don't have to use multi-buffered mode. The code you gave you is good enough to check if the received char is the same as the transmitted data.

    Hi QJ,

    Thank you very much for you thinking it good enough. I wrote this code in order to verify using uart to send and receiving mulptiple characters. This code proves it failed. The most sad thing is I don't know why it failed. Could you help me to find out why or give me some demo for modifying it ? Please have a look at the new added annotations of if-else block in while(1) in main function, which might make you comprehend my intention and sufferning.

    kind regards

    Datïan

  • Hello Datïan,

    As I said, your code won't work well. If you use sciSend() to transmit a group of characters, the received data in SCIRD is overwritten before you read them out using sciReceive(). Please use my example code to send/receive one character by one character.

  • Hello QJ,

    Many thanks. I will change my design. Would you like to teach me how to use uart in ISR mode, like receiving multiple characters by calling sciReceive without waiting for characters received, making ISR function handles the receiving matter which is trigered by interrupt signal ?

    warm regards

    Datïan

  • Hello Datian,

    Nothing special.

    1. Enable the interrupts: 

    •    Device level: _enable_IRQ()
    •    VIM level: use HALCoGen to enable channel 13 for linsci module
    •    SCI module level: use HALCoGen to enable RX interrupt

    2. Call sciReceive(sciREG1, length, &rx_data[0]) to define the block size (length) and location for the received data (rx_data[]).

    3. The received the data will be stored in rx_data[] automatically 

    3. Process the data in rx_data[]

  • Hello QJ,

    Thank you very much. I'll try it immediately.

    kind regards

    Datïan

  • Hello QJ,
    I want to use a global variable modified in ISR function of receiving for controlling while loop in main function. Where could I find the ISR function ?
    regards
    Datïan

  • Hello,

    If SCI RX or TX interrupt are enabled, and the SCI interrupt in VIM is enabled, the HALCoGen generates the SCI interrupt routine (ISR). It is located in sci.c.

  • Hello QJ,

    Thank you very much for your picture. I'm afraid I missed something. What I find about ISR in SCI.c is about LIN, but not sci. I know the pins of rx/tx of SCI and HET1_6/13 are multiplexed, and I know the channel 13 is for LIN or SCI2 as well. I don't know which channel of VIM is for SCI.

    best regards

    Datïan

  • Hello QJ,

    I use linsci to continue my test for uart ISR mode. The received characters are "fgefgef", "gefgefg", "fgefgef". The expected characters might be "abcdefg". My test code is as below. Is there something wrong or I missed this time ?

    /* USER CODE BEGIN (0) */
    /* USER CODE END */
    
    /* Include Files */
    
    #include "sys_common.h"
    
    /* USER CODE BEGIN (1) */
    #include "gio.h"
    #include "mibspi.h"
    #include "sci.h"
    #include "rti.h"
    /* 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) */
    unsigned char txBuffer[7]={'a','b','c','d','e','f','g'};
    unsigned char rxBuffer[7];
    int len=7;
    int myRx = 0;
    
    /* USER CODE END */
    
    int main(void)
    {
    /* USER CODE BEGIN (3) */
        gioInit();
        mibspiInit();//PIN_CLK for output; PIN_CS3 for input
        sciInit();
    
        while(sciIsIdleDetected(scilinREG));
        sciEnableLoopback(scilinREG, Digital_Lbk);
    
        /* Enable interrupt */
        _enable_IRQ();
    
        sciReceive(scilinREG, len, rxBuffer);
    
        rtiInit();
        /* Enable RTI compare 0 notification */
        rtiEnableNotification(rtiNOTIFICATION_COMPARE0);
        /* Start counter */
        rtiStartCounter(rtiCOUNTER_BLOCK0);
    
        while(1)
        {
            gioToggleBit(gioPORTB, 2);
    
            while(myRx==0);
    
            if(myRx==1)
            {
                myRx=0;
    
                if(0==gioGetBit(mibspiPORT3, PIN_CS3))  //Changing the condition online to confirm received characters in rxBuff are wrong online.  pin9@J5, 0:pin2@J3 or pin1@J5, 1:pin1@J2
                {
                    if(rxBuffer[0]=='a'&&rxBuffer[1]=='b'&&rxBuffer[2]=='c'&&rxBuffer[3]=='d'&&rxBuffer[4]=='e'&&rxBuffer[5]=='f'&&rxBuffer[6]=='g')
                    {
                        gioToggleBit(gioPORTB, 1);
                        rxBuffer[0]=0;
                        rxBuffer[1]=0;
                        rxBuffer[2]=0;
                        rxBuffer[3]=0;
                        rxBuffer[4]=0;
                        rxBuffer[5]=0;
                        rxBuffer[6]=0;
                        sciReceive(scilinREG, len, rxBuffer);
                    }
                }
                else
                {
                    if((rxBuffer[0]=='f'&&rxBuffer[1]=='g'&&rxBuffer[2]=='e'&&rxBuffer[3]=='f'&&rxBuffer[4]=='g'&&rxBuffer[5]=='e'&&rxBuffer[6]=='f')
                     ||(rxBuffer[0]=='g'&&rxBuffer[1]=='e'&&rxBuffer[2]=='f'&&rxBuffer[3]=='g'&&rxBuffer[4]=='e'&&rxBuffer[5]=='f'&&rxBuffer[6]=='g')
                     ||(rxBuffer[0]=='e'&&rxBuffer[1]=='f'&&rxBuffer[2]=='g'&&rxBuffer[3]=='e'&&rxBuffer[4]=='f'&&rxBuffer[5]=='g'&&rxBuffer[6]=='e')) //Characters were observed by setting break points at line of while(1) after next else
                    {
                        gioToggleBit(gioPORTB, 1);
                        rxBuffer[0]=0;
                        rxBuffer[1]=0;
                        rxBuffer[2]=0;
                        rxBuffer[3]=0;
                        rxBuffer[4]=0;
                        rxBuffer[5]=0;
                        rxBuffer[6]=0;
                        sciReceive(scilinREG, len, rxBuffer);
                    }
                    else
                        while(1);
                }
    
            }
        }
    /* USER CODE END */
    
        return 0;
    }
    
    
    /* USER CODE BEGIN (4) */
    void rtiNotification(uint32 notification)
    {
        sciSend(scilinREG, len, txBuffer);
    }
    
    void sciNotification(sciBASE_t *sci, uint32 flags)
    {
        if(flags==SCI_RX_INT)
        {
            gioToggleBit(mibspiPORT3, PIN_CLK);//pin7@J2, 0:pin2@J3, indicating receiving
            myRx=1;
        }
    }
    /* USER CODE END */

    kind regards

    Datïan

  • Hello,

    The interrupts for SCI module are VIM Channel 64 and Channel 74:

  • Hello,

    I told you that the data in SCIRD may be overwritten. 

  • Hello QJ,

    Thank you very much for your help. With your support and information, this issue is finally solved. I changed my design. I use timer ISR to trigger sending. Sending function is called by a while loop inside main function in poll mode I think. Receving function works in interrupt mode. Then it works.

     warm regards

    Datïan

  • Good news, Datian.