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:
//############################################################################# // // 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 $ // $Release Date: 10-19-2021 $ // $Copyright: // Copyright (C) 2009-2021 Texas Instruments Incorporated - http://www.ti.com/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions // are met: // // Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the // distribution. // // Neither the name of Texas Instruments Incorporated nor the names of // its contributors may be used to endorse or promote products derived // from this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // $ //############################################################################# // // Included Files // #include "DSP28x_Project.h" // Device Headerfile and Examples Include File #include <stdio.h> #include <file.h> #include "common/include/adc.h" #include "common/include/clk.h" #include "common/include/flash.h" #include "common/include/gpio.h" #include "common/include/pie.h" #include "common/include/pll.h" #include "common/include/sci.h" #include "common/include/wdog.h" // // Function Prototypes // void scia_init(void); void scia_fifo_init(void); void scia_xmit(int a); void error(void); // // Globals // uint16_t LoopCount; uint16_t ErrorCount; ADC_Handle myAdc; CLK_Handle myClk; FLASH_Handle myFlash; GPIO_Handle myGpio; PIE_Handle myPie; SCI_Handle mySci; // // Main // void main(void) { uint16_t SendChar; uint16_t ReceivedChar; CPU_Handle myCpu; PLL_Handle myPll; WDOG_Handle myWDog; // // Initialize all the handles needed for this application // myAdc = ADC_init((void *)ADC_BASE_ADDR, sizeof(ADC_Obj)); myClk = CLK_init((void *)CLK_BASE_ADDR, sizeof(CLK_Obj)); myCpu = CPU_init((void *)NULL, sizeof(CPU_Obj)); myFlash = FLASH_init((void *)FLASH_BASE_ADDR, sizeof(FLASH_Obj)); myGpio = GPIO_init((void *)GPIO_BASE_ADDR, sizeof(GPIO_Obj)); myPie = PIE_init((void *)PIE_BASE_ADDR, sizeof(PIE_Obj)); myPll = PLL_init((void *)PLL_BASE_ADDR, sizeof(PLL_Obj)); mySci = SCI_init((void *)SCIA_BASE_ADDR, sizeof(SCI_Obj)); myWDog = WDOG_init((void *)WDOG_BASE_ADDR, sizeof(WDOG_Obj)); // // Perform basic system initialization // WDOG_disable(myWDog); CLK_enableAdcClock(myClk); (*Device_cal)(); // // Select the internal oscillator 1 as the clock source // CLK_setOscSrc(myClk, CLK_OscSrc_Internal); // // Setup the PLL for x10 /2 which will yield 50Mhz = 10Mhz * 10 / 2 // PLL_setup(myPll, PLL_Multiplier_10, PLL_DivideSelect_ClkIn_by_2); // // Disable the PIE and all interrupts // PIE_disable(myPie); PIE_disableAllInts(myPie); CPU_disableGlobalInts(myCpu); CPU_clearIntFlags(myCpu); // // If running from flash copy RAM only functions to RAM // #ifdef _FLASH memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize); #endif // // Setup GPIO // GPIO_setPullUp(myGpio, GPIO_Number_28, GPIO_PullUp_Enable); GPIO_setPullUp(myGpio, GPIO_Number_29, GPIO_PullUp_Disable); GPIO_setQualification(myGpio, GPIO_Number_28, GPIO_Qual_ASync); GPIO_setMode(myGpio, GPIO_Number_28, GPIO_28_Mode_SCIRXDA); GPIO_setMode(myGpio, GPIO_Number_29, GPIO_29_Mode_SCITXDA); // // Setup a debug vector table and enable the PIE // PIE_setDebugIntVectorTable(myPie); PIE_enable(myPie); LoopCount = 0; ErrorCount = 0; scia_init(); // Initialize SCI for digital loop back scia_fifo_init(); // Initialize the SCI FIFO // // Send a character starting with 0 // SendChar = 0; // // Send Characters forever starting with 0x00 and going through 0xFF. // After sending each, check the receive buffer for the correct value // for(;;) { SCI_putDataBlocking(mySci, SendChar); while(SCI_getRxFifoStatus(mySci) == SCI_FifoStatus_Empty) { } // // Check received character // ReceivedChar = SCI_getData(mySci); if(ReceivedChar != SendChar) { error(); } // // Move to the next character and repeat the test // SendChar++; // // Limit the character to 8-bits // SendChar &= 0x00FF; LoopCount++; } } // // Step 7. Insert all local Interrupt Service Routines (ISRs) and // functions here: // // // error - // void error(void) { ErrorCount++; __asm(" ESTOP0"); // Uncomment to stop the test here for (;;) { } } // // scia_init - // 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); //SCI BRR = LSPCLK/(SCI BAUDx8) - 1 #if (CPU_FRQ_50MHZ) SCI_setBaudRate(mySci, SCI_BaudRate_9_6_kBaud); #elif (CPU_FRQ_40MHZ) SCI_setBaudRate(mySci, (SCI_BaudRate_e)129); #endif SCI_enable(mySci); return; } // // 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; } // // End of File //
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