接受板子的代码
void main()
{
/* Create a shadow register structure for the CAN control registers. This is
needed, since, only 32-bit access is allowed to these registers. 16-bit access
to these registers could potentially corrupt the register contents. This is
especially true while writing to a bit (or group of bits) among bits 16 - 31 */
struct ECAN_REGS ECanaShadow;
struct ECAN_REGS ECanbShadow;
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP2833x_SysCtrl.c file.
InitSysCtrl();
// Step 2. Initalize 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
// Just initalize eCAN pins for this example
// This function is in DSP2833x_ECan.c
InitECanGpio();
InitECanbGpio();
// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
DINT;
// Initialize the 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();
// Interrupts that are used in this example are re-mapped to
// ISR functions found within this file.
// No interrupts used in this example.
// Step 4. Initialize all the Device Peripherals:
// This function is found in DSP2833x_InitPeripherals.c
// InitPeripherals(); // Not required for this example
// In this case just initalize eCAN-A and eCAN-B
// This function is in DSP2833x_ECan.c
// InitECan();
InitECanb();
// Step 5. User specific code:
/* Write to the MSGID field */
ECanbMboxes.MBOX24.MSGID.all = 0x95555555; // Extended Identifier
/* Configure Mailbox under test as a Transmit mailbox */
ECanbShadow.CANMD.all = ECanbRegs.CANMD.all;
ECanbShadow.CANMD.bit.MD24 = 1; /// 1: 接收邮箱 0:发送邮箱
ECanbRegs.CANMD.all = ECanbShadow.CANMD.all;
/* Enable Mailbox under test */
ECanbShadow.CANME.all = ECanbRegs.CANME.all;
ECanbShadow.CANME.bit.ME24 = 1; /// 1:使能 0: 不使能
ECanbRegs.CANME.all = ECanbShadow.CANME.all;
/* Write to DLC field in Master Control reg */
ECanbMboxes.MBOX24.MSGCTRL.bit.DLC = 8;
ECanbMboxes.MBOX24.MSGCTRL.bit.RTR = 0;
EALLOW;
ECanbRegs.CANMIM.all = 0xffffffff;
ECanbRegs.CANMIL.all = 0;
ECanbRegs.CANGIF0.all = 0xffffffff;
ECanbRegs.CANGIM.bit.I0EN = 1;
EDIS;
PieCtrlRegs.PIEIER9.bit.INTx7 = 1;
IER |= M_INT9;
EINT;
ERTM;
for(;;);
}
|