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.
Tool/software: Code Composer Studio
i want transmit multiple data fot CANA TO CANB but canb can't catch .Was wrong with my code? p.s i can transmit one data
//########################################################################### // Description: //! \addtogroup f2833x_example_list //! <h1>eCAN back to back (ecan_back2back)</h1> //! //! 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.... \n //! This program illustrates the use of self-test mode //! //! 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: F2833x/F2823x Header Files and Peripheral Examples V142 $ // $Release Date: November 1, 2016 $ // $Copyright: Copyright (C) 2007-2016 Texas Instruments Incorporated - // http://www.ti.com/ ALL RIGHTS RESERVED $ //########################################################################### #include "DSP28x_Project.h" // Device Headerfile and Examples Include File // Prototype statements for functions found within this file. void mailbox_check(int32 T1, int32 T2, int32 T3); void mailbox_read(int16 i); void Canb_config(void); // Global variable for this example Uint32 ErrorCount; Uint32 PassCount; Uint32 MessageReceivedCount; long loopcount = 0; Uint32 TestMbox1 = 0; Uint32 TestMbox2 = 0; Uint32 TestMbox3 = 0; Uint32 Speed=0,Rpm_1=0,Rpm_2=0; Uint32 WaterTemp=0,Temp_Sign_Value=0,Room_Temp=0,Fuel=0; Uint32 Battery=0; Uint32 Mileage_1=0,Mileage_2=0,Mileage_3=0,MaxSpeed=0,AveSpeed=0; Uint32 all_parameter_1=0,all_parameter_2=0,all_parameter_3=0,all_parameter_4=0; int switch1=0; void main(void) { Uint16 j; // eCAN control registers require read/write access using 32-bits. Thus we // will create a set of shadow registers for this example. These shadow // registers will be used to make sure the access is 32-bits and not 16. struct ECAN_REGS ECanaShadow; // Step 1. Initialize System Control: // PLL, WatchDog, enable Peripheral Clocks // This example function is found in the DSP2833x_SysCtrl.c file. InitSysCtrl(); // Step 2. Initialize GPIO: // This example function is found in the DSP2833x_Gpio.c file and // illustrates how to set the GPIO to it's default state. // InitGpio(); // Skipped for this example // For this example, configure CAN pins using GPIO regs here // This function is found in DSP2833x_ECan.c InitECanGpio(); // Step 3. Clear all interrupts and initialize PIE vector table: // Disable CPU interrupts DINT; // Initialize PIE control registers to their default state. // The default state is all PIE interrupts disabled and flags // are cleared. // This function is found in the DSP2833x_PieCtrl.c file. InitPieCtrl(); // Disable CPU interrupts and clear all CPU interrupt flags: IER = 0x0000; IFR = 0x0000; // Initialize the PIE vector table with pointers to the shell Interrupt // Service Routines (ISR). // This will populate the entire table, even if the interrupt // is not used in this example. This is useful for debug purposes. // The shell ISR routines are found in DSP2833x_DefaultIsr.c. // This function is found in DSP2833x_PieVect.c. InitPieVectTable(); InitECan(); // Step 4. Initialize all the Device Peripherals: // This function is found in DSP2833x_InitPeripherals.c // InitPeripherals(); // Not required for this example // Step 5. User specific code, enable interrupts: MessageReceivedCount = 0; ErrorCount = 0; PassCount = 0; // Mailboxes can be written to 16-bits or 32-bits at a time // Write to the MSGID field of TRANSMIT mailboxes MBOX0 - 15 ECanaMboxes.MBOX0.MSGID.all = 0x00040000; ECanaMboxes.MBOX1.MSGID.all = 0x00080001; ECanaMboxes.MBOX2.MSGID.all = 0x000F0002; ECanaMboxes.MBOX3.MSGID.all = 0x00100003; ECanaMboxes.MBOX4.MSGID.all = 0x00140004; ECanaMboxes.MBOX5.MSGID.all = 0x00180005; ECanaMboxes.MBOX6.MSGID.all = 0x001F0006; ECanaMboxes.MBOX7.MSGID.all = 0x00000007; ECanaMboxes.MBOX8.MSGID.all = 0x00000008; ECanaMboxes.MBOX9.MSGID.all = 0x00000009; ECanaMboxes.MBOX10.MSGID.all = 0x0000000A; ECanaMboxes.MBOX11.MSGID.all = 0x0000000B; ECanaMboxes.MBOX12.MSGID.all = 0x0000000C; ECanaMboxes.MBOX13.MSGID.all = 0x0000000D; ECanaMboxes.MBOX14.MSGID.all = 0x0000000E; ECanaMboxes.MBOX15.MSGID.all = 0x0000000F; // Configure Mailboxes 0-15 as Tx, 16-31 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;// 0-15tx 16-31rx // 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 = 0x0000FFFF; // Specify that 8 bits will be sent/received ECanaMboxes.MBOX0.MSGCTRL.bit.DLC = 1; ECanaMboxes.MBOX1.MSGCTRL.bit.DLC = 5; ECanaMboxes.MBOX2.MSGCTRL.bit.DLC = 5; ECanaMboxes.MBOX3.MSGCTRL.bit.DLC = 5; ECanaMboxes.MBOX4.MSGCTRL.bit.DLC = 2; ECanaMboxes.MBOX5.MSGCTRL.bit.DLC = 7; ECanaMboxes.MBOX6.MSGCTRL.bit.DLC = 8; ECanaMboxes.MBOX7.MSGCTRL.bit.DLC = 8; ECanaMboxes.MBOX8.MSGCTRL.bit.DLC = 8; ECanaMboxes.MBOX9.MSGCTRL.bit.DLC = 8; ECanaMboxes.MBOX10.MSGCTRL.bit.DLC = 8; ECanaMboxes.MBOX11.MSGCTRL.bit.DLC = 8; ECanaMboxes.MBOX12.MSGCTRL.bit.DLC = 8; ECanaMboxes.MBOX13.MSGCTRL.bit.DLC = 8; ECanaMboxes.MBOX14.MSGCTRL.bit.DLC = 8; ECanaMboxes.MBOX15.MSGCTRL.bit.DLC = 8; // Write to the mailbox RAM field of MBOX0 - 15 ECanaMboxes.MBOX0.MDL.all = 0xFFFFFFFF; ECanaMboxes.MBOX0.MDH.all = 0x89ABCDEF; ECanaMboxes.MBOX1.MDL.all = 0x6F646464; ECanaMboxes.MBOX1.MDH.all = 0x89ABCDEF; ECanaMboxes.MBOX2.MDL.all = 0x00000000; ECanaMboxes.MBOX2.MDH.all = 0x89ABCDEF; ECanaMboxes.MBOX3.MDL.all = 0x00000000; ECanaMboxes.MBOX3.MDH.all = 0x89ABCDEF; ECanaMboxes.MBOX4.MDL.all = 0x00000000; ECanaMboxes.MBOX4.MDH.all = 0x89ABCDEF; ECanaMboxes.MBOX5.MDL.all = 0x00000000; ECanaMboxes.MBOX5.MDH.all = 0x89ABCDEF; ECanaMboxes.MBOX6.MDL.all = 0x00000000; ECanaMboxes.MBOX6.MDH.all = 0x89ABCDEF; ECanaMboxes.MBOX7.MDL.all = 0x00000000; ECanaMboxes.MBOX7.MDH.all = 0x89ABCDEF; ECanaMboxes.MBOX8.MDL.all = 0x00000000; ECanaMboxes.MBOX8.MDH.all = 0x89ABCDEF; ECanaMboxes.MBOX9.MDL.all = 0x9555AAA9; ECanaMboxes.MBOX9.MDH.all = 0x89ABCDEF; ECanaMboxes.MBOX10.MDL.all = 0x9555AAAA; ECanaMboxes.MBOX10.MDH.all = 0x89ABCDEF; ECanaMboxes.MBOX11.MDL.all = 0x9555AAAB; ECanaMboxes.MBOX11.MDH.all = 0x89ABCDEF; ECanaMboxes.MBOX12.MDL.all = 0x9555AAAC; ECanaMboxes.MBOX12.MDH.all = 0x89ABCDEF; ECanaMboxes.MBOX13.MDL.all = 0x9555AAAD; ECanaMboxes.MBOX13.MDH.all = 0x89ABCDEF; ECanaMboxes.MBOX14.MDL.all = 0x9555AAAE; ECanaMboxes.MBOX14.MDH.all = 0x89ABCDEF; ECanaMboxes.MBOX15.MDL.all = 0x9555AAAF; ECanaMboxes.MBOX15.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 = 0x0000FFFF; ECanbRegs.CANMIM.all = 0xFFFF0000; EDIS; // 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;*/ Canb_config(); // Begin transmitting for(;;) { if(switch1==1){ all_parameter_1=(Speed<<24)+(Rpm_1<<16)+(Rpm_2<<8); all_parameter_2=(WaterTemp<<24)+(Temp_Sign_Value<<16)+(Room_Temp<<8)+(Fuel); all_parameter_3=(Mileage_1<<24)+(Mileage_2<<16)+(Mileage_3<<8)+(MaxSpeed); //all_parameter_4=() //all_parameter_5= //all_parameter_6=; ECanaMboxes.MBOX1.MDL.all = all_parameter_1; ECanaMboxes.MBOX2.MDL.all = all_parameter_2; ECanaMboxes.MBOX2.MDH.all = (Battery<<24); ECanaMboxes.MBOX3.MDL.all = all_parameter_3; ECanaMboxes.MBOX3.MDH.all = (AveSpeed<<24); //ECanaMboxes.MBOX4.MDL.all = all_parameter_4; //ECanaMboxes.MBOX5.MDL.all = all_parameter_5; 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++; //Read from Receive mailboxes and begin checking for data */ for(j=16; j<32; j++) // Read & check 16 mailboxes { mailbox_read(j); // This func reads the indicated mailbox data mailbox_check(TestMbox1,TestMbox2,TestMbox3); // Checks the received data } }switch1=0; } __asm(" ESTOP0"); // Stop here } // This function reads out the contents of the indicated // by the Mailbox number (MBXnbr). void mailbox_read(int16 MBXnbr) { volatile struct MBOX *Mailbox; Mailbox = &ECanaMboxes.MBOX0 + MBXnbr; TestMbox1 = Mailbox->MDL.all; // = 0x9555AAAn (n is the MBX number) TestMbox2 = Mailbox->MDH.all; // = 0x89ABCDEF (a constant) TestMbox3 = Mailbox->MSGID.all;// = 0x9555AAAn (n is the MBX number) } // MSGID of a rcv MBX is transmitted as the MDL data. void mailbox_check(int32 T1, int32 T2, int32 T3) { if((T1 != T3) || ( T2 != 0x89ABCDEF)) { ErrorCount++; } else { PassCount++; } } void Canb_config(void){ struct ECAN_REGS ECanbShadow; // Write to the MSGID field of RECEIVE mailboxes MBOX16 - 31 ECanbMboxes.MBOX16.MSGID.all = 0x00000000; ECanbMboxes.MBOX17.MSGID.all = 0x00080001; ECanbMboxes.MBOX18.MSGID.all = 0x000F0002; ECanbMboxes.MBOX19.MSGID.all = 0x00100003; ECanbMboxes.MBOX20.MSGID.all = 0x00140004; ECanbMboxes.MBOX21.MSGID.all = 0x00180005; ECanbMboxes.MBOX22.MSGID.all = 0x001F0006; ECanbMboxes.MBOX23.MSGID.all = 0x00000007; ECanbMboxes.MBOX24.MSGID.all = 0x00000008; ECanbMboxes.MBOX25.MSGID.all = 0x00000009; ECanbMboxes.MBOX26.MSGID.all = 0x0000000A; ECanbMboxes.MBOX27.MSGID.all = 0x0000000B; ECanbMboxes.MBOX28.MSGID.all = 0x0000000C; ECanbMboxes.MBOX29.MSGID.all = 0x0000000D; ECanbMboxes.MBOX30.MSGID.all = 0x0000000E; ECanbMboxes.MBOX31.MSGID.all = 0x0000000F; ECanbRegs.CANME.all = 0xFFFF0000; ECanbRegs.CANMD.all = 0xFFFF0000;// 0-15tx 16-31rx ECanbMboxes.MBOX16.MSGCTRL.bit.DLC = 8; ECanbMboxes.MBOX17.MSGCTRL.bit.DLC = 8; ECanbMboxes.MBOX18.MSGCTRL.bit.DLC = 8; ECanbMboxes.MBOX19.MSGCTRL.bit.DLC = 8; ECanbMboxes.MBOX20.MSGCTRL.bit.DLC = 8; ECanbMboxes.MBOX21.MSGCTRL.bit.DLC = 8; ECanbMboxes.MBOX22.MSGCTRL.bit.DLC = 8; ECanbMboxes.MBOX23.MSGCTRL.bit.DLC = 8; ECanbMboxes.MBOX24.MSGCTRL.bit.DLC = 8; ECanbMboxes.MBOX25.MSGCTRL.bit.DLC = 8; ECanbMboxes.MBOX26.MSGCTRL.bit.DLC = 8; ECanbMboxes.MBOX27.MSGCTRL.bit.DLC = 8; ECanbMboxes.MBOX28.MSGCTRL.bit.DLC = 8; ECanbMboxes.MBOX29.MSGCTRL.bit.DLC = 8; ECanbMboxes.MBOX30.MSGCTRL.bit.DLC = 8; ECanbMboxes.MBOX31.MSGCTRL.bit.DLC = 8; } //=========================================================================== // No more. //===========================================================================
Please download my Application report http://www.ti.com/lit/spra876 . It has many tested examples. I also urge you to look at the Debug tips provided.
THANK YOU
I FIND ANOTHER ARTICLE LIKE THIS http://e2e.ti.com/support/microcontrollers/c2000/f/171/t/812546?TMS320F28335-Example-Code-of-interrupt-based-CAN-reception