//########################################################################### // // FILE: Example_2803xECanBack2Back.c // // TITLE: eCAN back to back example // //! \addtogroup f2803x_example_list //!

eCAN back to back (ecan_back2back)

//! //! This example tests eCAN by transmitting data back-to-back at high speed //! without stopping. The received data is verified. Any error is flagged. //! MBX0 transmits to MBX16, MBX1 transmits to MBX17 and so on.... //! //! This example uses the self-test mode of the CAN module. i.e. the //! transmission/reception happens within the module itself (even the required //! ACKnowldege is generated internally in the module). Therefore, there is no //! need for a CAN transceiver to run this particular test case and no activity //! will be seen in the CAN pins/bus. Because everything is internal, there is //! no need for a 120-ohm termination resistor. Note that a real-world CAN //! application needs a CAN transceiver and termination resistors on both ends //! of the bus. //! //! \b Watch \b Variables \n //! - PassCount //! - ErrorCount //! - MessageReceivedCount // // //########################################################################### // $TI Release: F2803x Support Library v2.01.00.00 $ // $Release Date: Thu Oct 18 15:46:42 CDT 2018 $ // $Copyright: // Copyright (C) 2009-2018 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 // // Prototype statements // void mailbox_check(int32 T1, int32 T2, int32 T3); void mailbox_read(int16 i); // // Globals // Uint32 ErrorCount; Uint32 PassCount; Uint32 MessageReceivedCount; Uint32 TestMbox1 = 0; Uint32 TestMbox2 = 0; Uint32 TestMbox3 = 0; // // Main // void main(void) { Uint16 j; struct ECAN_REGS ECanaShadow; InitSysCtrl(); InitECanGpio(); DINT; InitPieCtrl(); IER = 0x0000; IFR = 0x0000; InitPieVectTable(); MessageReceivedCount = 0; ErrorCount = 0; PassCount = 0; InitECana(); // Initialize eCAN-A module // Mailboxes can be written to 16-bits or 32-bits at a time // Write to the MSGID field of TRANSMIT mailboxe MBOX0 ECanaMboxes.MBOX0.MSGID.all = 0x9555AAA0; // Configure Mailboxes 0 as Tx, 16 as Rx // Since this write is to the entire register (instead of a bit // field) a shadow register is not required. ECanaRegs.CANMD.all = 0xFFFF0000; // Enable all Mailboxes */ // Since this write is to the entire register (instead of a bit // field) a shadow register is not required. ECanaRegs.CANME.all = 0xFFFFFFFF; // Specify that 8 bits will be sent/received ECanaMboxes.MBOX0.MSGCTRL.bit.DLC = 8; // Write to the mailbox RAM field of MBOX0 - 15 ECanaMboxes.MBOX0.MDL.all = 0x9555AAA0; ECanaMboxes.MBOX0.MDH.all = 0x89ABCDEF; // Since this write is to the entire register (instead of a bit // field) a shadow register is not required. EALLOW; ECanaRegs.CANMIM.all = 0xFFFFFFFF; // Configure the eCAN for self test mode // Enable the enhanced features of the eCAN. EALLOW; ECanaShadow.CANMC.all = ECanaRegs.CANMC.all; ECanaShadow.CANMC.bit.STM = 0; // Configure CAN for self-test mode ECanaRegs.CANMC.all = ECanaShadow.CANMC.all; EDIS; // Begin transmitting for(;;) { ECanaRegs.CANTRS.all = 0x0000FFFF; // Set TRS for all transmit mailboxes while(ECanaRegs.CANTA.all != 0x0000FFFF ) {} // Wait for all TAn bits to be set.. ECanaRegs.CANTA.all = 0x0000FFFF; // Clear all TAn MessageReceivedCount++; DELAY_US(900000); }}