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.

TMS320F28020: Using SCI for receiving messages of lengths from 1-20 bytes

Part Number: TMS320F28020
Other Parts Discussed in Thread: C2000WARE

Hi All,

I'm looking for some advice on a good way to implement the SCI module to receive messages ranging from 10 to 20 bytes.  I acknowledge the need for a parsing routine to discern each message, but that doesn't seem challenging since each message ends with a carriage return and line feed.  I'm just looking for help in receiving the data into an array.

I've imported the Driverlib example code, "Example_F2802xSci_FFDLB.c" from TIREX, and it is talking to external devices.  However, that code uses a four level fifo, which doesn't seem optimal for receiving varying length messages.  Here's the code for reference:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//#############################################################################
//
// File: Example_F2802xSci_FFDLB.c
//
// Title: F2802x Device SCI FIFO Digital Loop Back Test.
//
//! \addtogroup example_list
//! <h1>SCI FIFO Digital Loop Back</h1>
//!
//! This test uses the loopback test mode of the SCI module to send
//! characters starting with 0x00 through 0xFF. The test will send
//! a character and then check the receive buffer for a correct match.
//!
//! Watch Variables:
//! - LoopCount - Number of characters sent
//! - ErrorCount - Number of errors detected
//! - SendChar - Character sent
//! - ReceivedChar - Character received
//
//#############################################################################
// $TI Release: F2802x Support Library v3.05.00.00 $
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Here's a logic analyzer image of one of the longer messages:

And here's a short one:

Questions:

1. I don't need to use an isr, but should I?

2. Should I abandon the fifo in favor of a streaming approach?

3. Can you point me to a TI app note that would address these questions?

4. Can you point me to some example code?

Thanks in advance!
robin

  • Hi Robin,

    1. I don't need to use an isr, but should I?

    This depends on what you have going on in your overall application. If you are only using this device for the serial communication then you could get way with not using an ISR. If there are other components involved that the CPU needs to handle then I would encourage the use of an ISR. 

    2. Should I abandon the fifo in favor of a streaming approach?

    Since you receiving messaging between 10 and 20 bytes, I do think the streaming approach would be the easier option. Our FIFO level only goes up to 4 on this device. 

    3. Can you point me to a TI app note that would address these questions?

    Unfortunately, we do not have any app notes that would cover these topics.

    4. Can you point me to some example code?

    The only example code that we do have is within C2000Ware.

    Best Regards,

    Marlyn

  • Thanks for the quick response, Marlyn.

    To switch from a fifo to a streaming approach, I performed the following:

    1. Commented out the fifo initialization calls:

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    //
    // scia_fifo_init - Initialize the SCI FIFO
    //
    void scia_fifo_init()
    {
    // SCI_enableFifoEnh(mySci);
    // SCI_resetTxFifo(mySci);
    // SCI_clearTxFifoInt(mySci);
    // SCI_resetChannels(mySci);
    // SCI_setTxFifoIntLevel(mySci, SCI_FifoLevel_Empty);
    // SCI_resetRxFifo(mySci);
    // SCI_clearRxFifoInt(mySci);
    // SCI_setRxFifoIntLevel(mySci, SCI_FifoLevel_4_Words);
    return;
    }
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    2. Left the non-fifo SCI initialization as it was:

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    void scia_init()
    {
    CLK_enableSciaClock(myClk);
    //
    // 1 stop bit, No loopback, No parity,8 char bits, async mode,
    // idle-line protocol
    //
    SCI_disableParity(mySci);
    SCI_setNumStopBits(mySci, SCI_NumStopBits_One);
    SCI_setCharLength(mySci, SCI_CharLength_8_Bits);
    //
    // enable TX, RX, internal SCICLK, Disable RX ERR, SLEEP, TXWAKE
    //
    SCI_enableTx(mySci);
    SCI_enableRx(mySci);
    SCI_enableTxInt(mySci);
    SCI_enableRxInt(mySci);
    // SCI_enableLoopBack(mySci);
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    3. Changed the bit of code that waits for a byte to be received FROM THIS:

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    while(SCI_getRxFifoStatus(mySci) == SCI_FifoStatus_Empty)
    {
    greenSwPressed = (GPIO_getData(myGpio, GRN_SW)) ? 0 : 1;
    redSwPressed = (GPIO_getData(myGpio, RED_SW)) ? 0 : 1;
    if(redSwPressed & !redLED)
    {
    GPIO_setHigh(myGpio, RED_LED);
    } else if(!redSwPressed & !redLED)
    {
    GPIO_setLow(myGpio, RED_LED);
    }
    if(greenSwPressed & !greenLED)
    {
    GPIO_setHigh(myGpio, GREEN_LED);
    } else if(!greenSwPressed & !greenLED)
    {
    GPIO_setLow(myGpio, GREEN_LED);
    }
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    4. TO THIS:

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    while(SCI_isRxDataReady(mySci) != true)
    {
    greenSwPressed = (GPIO_getData(myGpio, GRN_SW)) ? 0 : 1;
    redSwPressed = (GPIO_getData(myGpio, RED_SW)) ? 0 : 1;
    if(redSwPressed & !redLED)
    {
    GPIO_setHigh(myGpio, RED_LED);
    } else if(!redSwPressed & !redLED)
    {
    GPIO_setLow(myGpio, RED_LED);
    }
    if(greenSwPressed & !greenLED)
    {
    GPIO_setHigh(myGpio, GREEN_LED);
    } else if(!greenSwPressed & !greenLED)
    {
    GPIO_setLow(myGpio, GREEN_LED);
    }
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    5. Upon receipt of a byte in the SCIRXBUF, here's the code that pulls in a message:

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    byteReceived = SCI_getData(mySci);
    if(byteReceived != 10 && byteReceived != 13)
    {
    receivedByteFlag = 1;
    message[rdvWordCount++] = (char)byteReceived;
    rdvWordCount &= 0x7F; //rdv Limit buffer range to 0-127
    }
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    And it works splendidly.

    I may opt for using an isr for the receive function.  It works without it, but that just seems a cleaner approach.  I'm sure there'll be more refinements along the way, but this provided the functionality I was looking for.

    Thank you,
    robin