| //############################################################################# | = | //############################################################################# | 
| // | // | |
| // FILE: sci_ex3_echoback.c | // FILE: sci_ex3_echoback.c | |
| // | // | |
| // TITLE: SCI echoback example. | // TITLE: SCI echoback example. | |
| // | // | |
| //! \addtogroup driver_example_list | //! \addtogroup driver_example_list | |
| //! <h1>SCI Echoback</h1> | //! <h1>SCI Echoback</h1> | |
| //! | //! | |
| //! This test receives and echo-backs data through the SCI-A port. | //! This test receives and echo-backs data through the SCI-A port. | |
| //! | //! | |
| //! A terminal such as 'putty' can be used to view the data from | //! A terminal such as 'putty' can be used to view the data from | |
| //! the SCI and to send information to the SCI. Characters received | //! the SCI and to send information to the SCI. Characters received | |
| //! by the SCI port are sent back to the host. | //! by the SCI port are sent back to the host. | |
| //! | //! | |
| //! \b Running \b the \b Application | //! \b Running \b the \b Application | |
| //! Open a COM port with the following settings using a terminal: | //! Open a COM port with the following settings using a terminal: | |
| //! - Find correct COM port | //! - Find correct COM port | |
| //! - Bits per second = 9600 | //! - Bits per second = 9600 | |
| //! - Data Bits = 8 | //! - Data Bits = 8 | |
| //! - Parity = None | //! - Parity = None | |
| //! - Stop Bits = 1 | //! - Stop Bits = 1 | |
| //! - Hardware Control = None | //! - Hardware Control = None | |
| //! | //! | |
| //! The program will print out a greeting and then ask you to | //! The program will print out a greeting and then ask you to | |
| //! enter a character which it will echo back to the terminal. | //! enter a character which it will echo back to the terminal. | |
| //! | //! | |
| //! \b Watch \b Variables \n | //! \b Watch \b Variables \n | |
| //! - loopCounter - the number of characters sent | //! - loopCounter - the number of characters sent | |
| //! | //! | |
| //! \b External \b Connections \n | //! \b External \b Connections \n | |
| //! Connect the SCI-A port to a PC via a USB cable. | //! Connect the SCI-A port to a PC via a USB cable. | |
| //! Refer to the hardware user guide for the UART/USB connector information. | //! Refer to the hardware user guide for the UART/USB connector information. | |
| // | // | |
| //############################################################################# | //############################################################################# | |
| // | <> | // $TI Release: F2837xD Support Library v3.11.00.00 $ | 
| // $Release Date: 10-14-2021 $ | // $Release Date: Sun Oct 4 15:55:24 IST 2020 $ | |
| // $Copyright: | = | // $Copyright: | 
| // Copyright (C) 2013-2021 Texas Instruments Incorporated - http://www.ti.com/ | <> | // Copyright (C) 2013-2020 Texas Instruments Incorporated - http://www.ti.com/ | 
| // | = | // | 
| // Redistribution and use in source and binary forms, with or without | // Redistribution and use in source and binary forms, with or without | |
| // modification, are permitted provided that the following conditions | // modification, are permitted provided that the following conditions | |
| // are met: | // are met: | |
| // | // | |
| // Redistributions of source code must retain the above copyright | // Redistributions of source code must retain the above copyright | |
| // notice, this list of conditions and the following disclaimer. | // notice, this list of conditions and the following disclaimer. | |
| // | // | |
| // Redistributions in binary form must reproduce the above copyright | // Redistributions in binary form must reproduce the above copyright | |
| // notice, this list of conditions and the following disclaimer in the | // notice, this list of conditions and the following disclaimer in the | |
| // documentation and/or other materials provided with the | // documentation and/or other materials provided with the | |
| // distribution. | // distribution. | |
| // | // | |
| // Neither the name of Texas Instruments Incorporated nor the names of | // Neither the name of Texas Instruments Incorporated nor the names of | |
| // its contributors may be used to endorse or promote products derived | // its contributors may be used to endorse or promote products derived | |
| // from this software without specific prior written permission. | // from this software without specific prior written permission. | |
| // | // | |
| // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| // $ | // $ | |
| //############################################################################# | //############################################################################# | |
| // | // | |
| // Included Files | // Included Files | |
| // | // | |
| #include "driverlib.h" | #include "driverlib.h" | |
| #include "device.h" | #include "device.h" | |
| // | // | |
| // Defines | // Defines | |
| // | // | |
| // Define AUTOBAUD to use the autobaud lock feature | // Define AUTOBAUD to use the autobaud lock feature | |
| //#define AUTOBAUD | //#define AUTOBAUD | |
| // | // | |
| // Globals | // Globals | |
| // | // | |
| uint16_t loopCounter = 0; | uint16_t loopCounter = 0; | |
| // | // | |
| // Main | // Main | |
| // | // | |
| void main(void) | void main(void) | |
| { | { | |
| uint16_t receivedChar; | uint16_t receivedChar; | |
| unsigned char *msg; | unsigned char *msg; | |
| uint16_t rxStatus = 0U; | uint16_t rxStatus = 0U; | |
| // | // | |
| // Configure PLL, disable WD, enable peripheral clocks. | // Configure PLL, disable WD, enable peripheral clocks. | |
| // | // | |
| Device_init(); | Device_init(); | |
| // | // | |
| // Disable pin locks and enable internal pullups. | // Disable pin locks and enable internal pullups. | |
| // | // | |
| Device_initGPIO(); | Device_initGPIO(); | |
| // | // | |
| // Configuration for the SCI Rx pin. | // Configuration for the SCI Rx pin. | |
| // | // | |
| GPIO_setMasterCore(DEVICE_GPIO_PIN_SCIRXDA, GPIO_CORE_CPU1); | <> | GPIO_setMasterCore(11U, GPIO_CORE_CPU1); //chose a RXB pin from pin mux in TRM | 
| GPIO_setPinConfig(DEVICE_GPIO_CFG_SCIRXDA); | GPIO_setPinConfig(GPIO_11_SCIRXDB); | |
| GPIO_setDirectionMode(DEVICE_GPIO_PIN_SCIRXDA, GPIO_DIR_MODE_IN); | GPIO_setDirectionMode(11U, GPIO_DIR_MODE_IN); | |
| GPIO_setPadConfig(DEVICE_GPIO_PIN_SCIRXDA, GPIO_PIN_TYPE_STD); | GPIO_setPadConfig(11U, GPIO_PIN_TYPE_PULLUP); | |
| GPIO_setQualificationMode(DEVICE_GPIO_PIN_SCIRXDA, GPIO_QUAL_ASYNC); | GPIO_setQualificationMode(11U, GPIO_QUAL_ASYNC); | |
| = | ||
| // | // | |
| // Configuration for the SCI Tx pin. | // Configuration for the SCI Tx pin. | |
| // | // | |
| GPIO_setMasterCore(DEVICE_GPIO_PIN_SCITXDA, GPIO_CORE_CPU1); | <> | GPIO_setMasterCore(10U, GPIO_CORE_CPU1); | 
| GPIO_setPinConfig(DEVICE_GPIO_CFG_SCITXDA); | GPIO_setPinConfig(GPIO_10_SCITXDB); | |
| GPIO_setDirectionMode(DEVICE_GPIO_PIN_SCITXDA, GPIO_DIR_MODE_OUT); | GPIO_setDirectionMode(10U, GPIO_DIR_MODE_OUT); | |
| GPIO_setPadConfig(DEVICE_GPIO_PIN_SCITXDA, GPIO_PIN_TYPE_STD); | GPIO_setPadConfig(10U, GPIO_PIN_TYPE_STD); | |
| GPIO_setQualificationMode(DEVICE_GPIO_PIN_SCITXDA, GPIO_QUAL_ASYNC); | GPIO_setQualificationMode(10U, GPIO_QUAL_ASYNC); | |
| = | ||
| // | // | |
| // Initialize interrupt controller and vector table. | // Initialize interrupt controller and vector table. | |
| // | // | |
| Interrupt_initModule(); | Interrupt_initModule(); | |
| Interrupt_initVectorTable(); | Interrupt_initVectorTable(); | |
| // | // | |
| // Initialize SCIA and its FIFO. | <> | // Initialize SCIB and its FIFO. | 
| // | = | // | 
| SCI_performSoftwareReset(SCIA_BASE); | <> | SCI_performSoftwareReset(SCIB_BASE); | 
| = | ||
| // | // | |
| // Configure SCIA for echoback. | <> | // Configure SCIB for echoback. | 
| // | = | // | 
| SCI_setConfig(SCIA_BASE, DEVICE_LSPCLK_FREQ, 9600, (SCI_CONFIG_WLEN_8 | | <> | SCI_setConfig(SCIB_BASE, DEVICE_LSPCLK_FREQ, 9600, (SCI_CONFIG_WLEN_8 | | 
| SCI_CONFIG_STOP_ONE | | = | SCI_CONFIG_STOP_ONE | | 
| SCI_CONFIG_PAR_NONE)); | SCI_CONFIG_PAR_NONE)); | |
| SCI_resetChannels(SCIA_BASE); | <> | SCI_resetChannels(SCIB_BASE); | 
| SCI_resetRxFIFO(SCIA_BASE); | SCI_resetRxFIFO(SCIB_BASE); | |
| SCI_resetTxFIFO(SCIA_BASE); | SCI_resetTxFIFO(SCIB_BASE); | |
| SCI_clearInterruptStatus(SCIA_BASE, SCI_INT_TXFF | SCI_INT_RXFF); | SCI_clearInterruptStatus(SCIB_BASE, SCI_INT_TXFF | SCI_INT_RXFF); | |
| SCI_enableFIFO(SCIA_BASE); | SCI_enableFIFO(SCIB_BASE); | |
| SCI_enableModule(SCIA_BASE); | SCI_enableModule(SCIB_BASE); | |
| SCI_performSoftwareReset(SCIA_BASE); | SCI_performSoftwareReset(SCIB_BASE); | |
| = | ||
| #ifdef AUTOBAUD | #ifdef AUTOBAUD | |
| // | // | |
| // Perform an autobaud lock. | // Perform an autobaud lock. | |
| // SCI expects an 'a' or 'A' to lock the baud rate. | // SCI expects an 'a' or 'A' to lock the baud rate. | |
| // | // | |
| SCI_lockAutobaud(SCIA_BASE); | <> | SCI_lockAutobaud(SCIB_BASE); | 
| #endif | = | #endif | 
| // | // | |
| // Send starting message. | // Send starting message. | |
| // | // | |
| msg = "\r\n\n\nHello World!\0"; | msg = "\r\n\n\nHello World!\0"; | |
| SCI_writeCharArray(SCIA_BASE, (uint16_t*)msg, 17); | <> | SCI_writeCharArray(SCIB_BASE, (uint16_t*)msg, 17); | 
| msg = "\r\nYou will enter a character, and the DSP will echo it back!\n\0"; | = | msg = "\r\nYou will enter a character, and the DSP will echo it back!\n\0"; | 
| SCI_writeCharArray(SCIA_BASE, (uint16_t*)msg, 62); | <> | SCI_writeCharArray(SCIB_BASE, (uint16_t*)msg, 62); | 
| = | ||
| for(;;) | for(;;) | |
| { | { | |
| msg = "\r\nEnter a character: \0"; | msg = "\r\nEnter a character: \0"; | |
| SCI_writeCharArray(SCIA_BASE, (uint16_t*)msg, 22); | <> | SCI_writeCharArray(SCIB_BASE, (uint16_t*)msg, 22); | 
| = | ||
| // | // | |
| // Read a character from the FIFO. | // Read a character from the FIFO. | |
| // | // | |
| receivedChar = SCI_readCharBlockingFIFO(SCIA_BASE); | <> | receivedChar = SCI_readCharBlockingFIFO(SCIB_BASE); | 
| = | ||
| rxStatus = SCI_getRxStatus(SCIA_BASE); | <> | rxStatus = SCI_getRxStatus(SCIB_BASE); | 
| if((rxStatus & SCI_RXSTATUS_ERROR) != 0) | = | if((rxStatus & SCI_RXSTATUS_ERROR) != 0) | 
| { | { | |
| // | // | |
| //If Execution stops here there is some error | //If Execution stops here there is some error | |
| //Analyze SCI_getRxStatus() API return value | //Analyze SCI_getRxStatus() API return value | |
| // | // | |
| ESTOP0; | ESTOP0; | |
| } | } | |
| // | // | |
| // Echo back the character. | // Echo back the character. | |
| // | // | |
| msg = " You sent: \0"; | msg = " You sent: \0"; | |
| SCI_writeCharArray(SCIA_BASE, (uint16_t*)msg, 13); | <> | SCI_writeCharArray(SCIB_BASE, (uint16_t*)msg, 13); | 
| SCI_writeCharBlockingFIFO(SCIA_BASE, receivedChar); | SCI_writeCharBlockingFIFO(SCIB_BASE, receivedChar); | |
| = | ||
| // | // | |
| // Increment the loop count variable. | // Increment the loop count variable. | |
| // | // | |
| loopCounter++; | loopCounter++; | |
| } | } | |
| } | } | |
| // | // | |
| // End of File | // End of File | |
| // | // | |