改造了 官方的Example_2833x_ECanBack2Back例子,将邮箱0作为接收方,同时去掉了 selftest mode,另外一个板子作为发送方
接受方主要代码
ECanaMboxes.MBOX0.MSGID.all = 0x15555555;
ECanaRegs.CANMD.all = 0xFFFFFFFF;
ECanaRegs.CANOPC.all = 0x00000001;
ECanaRegs.CANME.all = 0x00000001;
// Specify that 8 bits will be sent/received
ECanaMboxes.MBOX0.MSGCTRL.bit.DLC = 8;
// Write to the mailbox RAM field of MBOX0
ECanaMboxes.MBOX0.MDL.all = 0x9555AAA0;
ECanaMboxes.MBOX0.MDH.all = 0x89ABCDEF;
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.CANRMP.all = 0x00000000; // Set CANRMP
while(ECanaRegs.CANRMP.all != 0x00000001 ) {} // Wait for all CANRMP bits to be set..
ECanaRegs.CANRMP.all = 0x00000000; // Clear all TAn
ECanaRegs.CANRML.all = 0x00000000;
TestMbox1 = ECanaMboxes.MBOX0.MDL.all;
TestMbox2 = ECanaMboxes.MBOX0.MDH.all;
ECanaMboxes.MBOX0.MDL.all = 0x00000000;
ECanaMboxes.MBOX0.MDH.all = 0x00000000;
MessageReceivedCount++;
}
}
Eason Wang:
Move to C2000 forum