附上程序,邮箱的MDL和MDH死活为零。可是CANRMP有被置为1
#include "DSP2833x_Device.h"
#include "DSP2833x_Examples.h"
struct ECAN_REGS ECanbShadow;
interrupt void ECanbR_ISR(void);
void InitECanR(void);
Uint16 MSGL0 = 0;
Uint16 MSGL1 = 0;
Uint16 MSGL2 = 0;
Uint16 MSGL3 = 0;
Uint16 MSGH0 = 0;
Uint16 MSGH1 = 0;
Uint16 MSGH2 = 0;
Uint16 MSGH3 = 0;
int Counts = 0;
void main()
{
InitSysCtrl(); //系统初始化
InitXintf16Gpio(); //初始化16路Gpio
InitECanGpio();
InitECanbGpio(); //初始化ECanb
InitECanaGpio();
InitECana();
InitECanb();
DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
EALLOW;
PieVectTable.ECAN1INTB = &ECanbR_ISR;
EDIS;
InitECanR();
IER =M_INT9;
//PieCtrlRegs.PIEIER1.bit.INTx7 = 1;
PieCtrlRegs.PIEIER9.bit.INTx8 = 1; //使能第9组中断第8个小中断,即ECAN1INTB
//PieCtrlRegs.PIEACK.bit.ACK9 = 1; //PIEACK置1
EINT;
ERTM;
for(;;)
{
}
}
interrupt void ECanbR_ISR(void)
{
if(ECanbRegs.CANGIF1.bit.GMIF1 == 1)
{
if(ECanbRegs.CANRMP.all == 0x00010000)
{
ECanbRegs.CANRMP.all = 0x00010000;
MSGL0 = ECanbMboxes.MBOX16.MDL.byte.BYTE0;
MSGL1 = ECanbMboxes.MBOX16.MDL.byte.BYTE1;
MSGL2 = ECanbMboxes.MBOX16.MDL.byte.BYTE2;
MSGL3 = ECanbMboxes.MBOX16.MDL.byte.BYTE3;
MSGH0 = ECanbMboxes.MBOX16.MDH.byte.BYTE4;
MSGH1 = ECanbMboxes.MBOX16.MDH.byte.BYTE5;
MSGH2 = ECanbMboxes.MBOX16.MDH.byte.BYTE6;
MSGH3 = ECanbMboxes.MBOX16.MDH.byte.BYTE7;
}
}
PieCtrlRegs.PIEACK.bit.ACK9 = 1;
//ECanbRegs.CANOPC.all = 0x00000000;
}
void InitECanR(void)
{
EALLOW;
ECanbShadow.CANTIOC.all = ECanbRegs.CANTIOC.all;
ECanbShadow.CANTIOC.bit.TXFUNC = 1;
ECanbRegs.CANTIOC.all = ECanbShadow.CANTIOC.all;
ECanbShadow.CANRIOC.all = ECanbRegs.CANRIOC.all;
ECanbShadow.CANRIOC.bit.RXFUNC = 1;
ECanbRegs.CANRIOC.all = ECanbShadow.CANRIOC.all;
ECanbShadow.CANMC.all = ECanbRegs.CANMC.all;
ECanbShadow.CANMC.bit.CCR = 1;
ECanbRegs.CANMC.all = ECanbShadow.CANMC.all;
EDIS;
ECanbShadow.CANES.all = ECanbRegs.CANES.all;
do
{
ECanbShadow.CANES.all = ECanbRegs.CANES.all;
}while(ECanbShadow.CANES.bit.CCE != 1);
ECanbRegs.CANBTC.all = 0;
EALLOW;
ECanbShadow.CANBTC.all = ECanbRegs.CANBTC.all;
ECanbShadow.CANBTC.bit.BRPREG = 9;
ECanbShadow.CANBTC.bit.TSEG2REG = 2;
ECanbShadow.CANBTC.bit.TSEG1REG = 10;
ECanbShadow.CANBTC.bit.SAM = 1; //采样三次取多次
ECanbRegs.CANBTC.all = ECanbShadow.CANBTC.all;
ECanbShadow.CANMC.all = ECanbRegs.CANMC.all;
ECanbShadow.CANMC.bit.CCR = 0;
ECanbShadow.CANMC.bit.PDR = 0;
ECanbShadow.CANMC.bit.DBO = 0;
ECanbShadow.CANMC.bit.WUBA = 0;
ECanbShadow.CANMC.bit.CDR = 0;
ECanbShadow.CANMC.bit.ABO = 0;
ECanbShadow.CANMC.bit.STM = 0;
ECanbShadow.CANMC.bit.SRES = 0;
ECanbShadow.CANMC.bit.MBNR = 0;
ECanbRegs.CANMC.all = ECanbShadow.CANMC.all;
EDIS;
ECanbMboxes.MBOX0.MSGCTRL.all = 0;
ECanbMboxes.MBOX1.MSGCTRL.all = 0;
ECanbMboxes.MBOX2.MSGCTRL.all = 0;
ECanbMboxes.MBOX3.MSGCTRL.all = 0;
ECanbMboxes.MBOX4.MSGCTRL.all = 0;
ECanbMboxes.MBOX5.MSGCTRL.all = 0;
ECanbMboxes.MBOX6.MSGCTRL.all = 0;
ECanbMboxes.MBOX7.MSGCTRL.all = 0;
ECanbMboxes.MBOX8.MSGCTRL.all = 0;
ECanbMboxes.MBOX9.MSGCTRL.all = 0;
ECanbMboxes.MBOX10.MSGCTRL.all = 0;
ECanbMboxes.MBOX11.MSGCTRL.all = 0;
ECanbMboxes.MBOX12.MSGCTRL.all = 0;
ECanbMboxes.MBOX13.MSGCTRL.all = 0;
ECanbMboxes.MBOX14.MSGCTRL.all = 0;
ECanbMboxes.MBOX15.MSGCTRL.all = 0;
ECanbMboxes.MBOX16.MSGCTRL.all = 0;
ECanbMboxes.MBOX17.MSGCTRL.all = 0;
ECanbMboxes.MBOX18.MSGCTRL.all = 0;
ECanbMboxes.MBOX19.MSGCTRL.all = 0;
ECanbMboxes.MBOX20.MSGCTRL.all = 0;
ECanbMboxes.MBOX21.MSGCTRL.all = 0;
ECanbMboxes.MBOX22.MSGCTRL.all = 0;
ECanbMboxes.MBOX23.MSGCTRL.all = 0;
ECanbMboxes.MBOX24.MSGCTRL.all = 0;
ECanbMboxes.MBOX25.MSGCTRL.all = 0;
ECanbMboxes.MBOX26.MSGCTRL.all = 0;
ECanbMboxes.MBOX27.MSGCTRL.all = 0;
ECanbMboxes.MBOX28.MSGCTRL.all = 0;
ECanbMboxes.MBOX29.MSGCTRL.all = 0;
ECanbMboxes.MBOX30.MSGCTRL.all = 0;
ECanbMboxes.MBOX31.MSGCTRL.all = 0;
ECanbShadow.CANES.all = ECanbRegs.CANES.all;
do
{
ECanbShadow.CANES.all = ECanbRegs.CANES.all;
}while(ECanbShadow.CANES.bit.CCE != 0);
ECanbRegs.CANGIM.all = 0x00000000;
ECanbRegs.CANMIM.all = 0x00000000;
ECanbRegs.CANMIL.all = 0xFFFFFFFF;
ECanbRegs.CANME.all = 0x00000000;
ECanbMboxes.MBOX16.MSGID.bit.IDE = 0;
ECanbMboxes.MBOX16.MSGID.bit.STDMSGID = 0x0314;
ECanbMboxes.MBOX16.MSGID.bit.AAM = 0;
ECanbMboxes.MBOX16.MSGID.bit.AME = 0;
ECanbRegs.CANMD.all = 0xFFFF0000;
//ECanbShadow.CANGAM.all = ECanbRegs.CANGAM.all;
//ECanbShadow.CANGAM.bit.AMI = 1; //标准帧和扩展帧都接受
//ECanbShadow.CANGAM.bit.GAM2816 |= 0x1fff; //LAM(0)用于邮箱0~2 ,LAM(3)用于邮箱3~5,对于邮箱6~15,用全局接收屏蔽
//ECanbRegs.CANGAM.all = ECanbShadow.CANGAM.all;
/*ECanbShadow.CANOPC.all = ECanbRegs.CANOPC.all;
ECanbShadow.CANOPC.bit.OPC16 = 0; //设置为没有写覆盖保护
ECanbRegs.CANOPC.all = ECanbShadow.CANOPC.all;
*/
ECanbMboxes.MBOX16.MSGCTRL.bit.DLC = 8;
ECanbMboxes.MBOX16.MSGCTRL.bit.RTR = 0;
EALLOW;
ECanbShadow.CANMC.all = ECanbRegs.CANMC.all;
ECanbShadow.CANMC.bit.STM = 0; // Configure CAN for self-test mode
ECanbShadow.CANMC.bit.SCB = 1; // eCAN mode (reqd to access 32 mailboxes)
ECanbRegs.CANMC.all = ECanbShadow.CANMC.all;
EDIS;
ECanbShadow.CANME.all = ECanbRegs.CANME.all;
ECanbShadow.CANME.bit.ME16 = 1;
ECanbRegs.CANME.all = ECanbShadow.CANME.all;
ECanbRegs.CANMIL.all = 0xFFFF0000;
ECanbRegs.CANMIM.all = 0xFFFFFFFF;
EALLOW;
ECanbShadow.CANGIM.all = ECanbRegs.CANGIM.all;
ECanbShadow.CANGIM.bit.AAIM = 1;
ECanbShadow.CANGIM.bit.WDIM = 1;
ECanbShadow.CANGIM.bit.WUIM = 1;
ECanbShadow.CANGIM.bit.BOIM = 1;
ECanbShadow.CANGIM.bit.EPIM = 1;
ECanbShadow.CANGIM.bit.WLIM = 1;
ECanbShadow.CANGIM.bit.I0EN = 1;
ECanbShadow.CANGIM.bit.I1EN = 1;
ECanbShadow.CANGIM.bit.GIL =1;
ECanbRegs.CANGIM.all = ECanbShadow.CANGIM.all;
ECanbRegs.CANRMP.all = 0xFFFFFFFF;
ECanbRegs.CANTA.all = 0xFFFFFFFF;
ECanbRegs.CANGIF0.all = 0xFFFFFFFF;
ECanbRegs.CANGIF1.all = 0xFFFFFFFF;
} |