本帖最后由 yjw16 于 2014-4-30 22:13 编辑
ECAN作为发送邮箱时,电脑上可以成功收到数据。但作为接受邮箱时,老是不能进入中断,请问是什么原因?程序如下
void main(void)
{
InitSysCtrl();
DINT;
IER = 0x0000;
IFR = 0x0000;
InitPieCtrl();
InitPieVectTable();
InitECan();
EALLOW;
PieVectTable.ECAN0INTA = &User_ECAN0_INTA;
//PieVectTable.ECAN1INTA = &User_ECAN1_INTA;
EDIS;
PieCtrl.PIEIER1.bit.INTx5=1;
IER |= M_INT9;
EINT;
ERTM;
Rec_l=0;
Rec_h=0;
for(;;)
{}
}
interrupt void User_ECAN0_INTA(void)
{
while(ECanaRegs.CANRMP.all!=0x00010000);
ECanaRegs.CANRMP.all!=0x00010000;
Rec_l=ECanaMboxes.MBOX16.MDRL.all;
Rec_h=ECanaMboxes.MBOX16.MDRH.all;
PieCtrl.PIEACK.bit.ACK9 = 1;
EINT;
}
void InitECan(void)
{
struct ECAN_REGS ECanaShadow;
EALLOW;
GpioMuxRegs.GPFMUX.bit.CANTXA_GPIOF6 = 1;
GpioMuxRegs.GPFMUX.bit.CANRXA_GPIOF7 = 1;
EDIS;
EALLOW;
ECanaShadow.CANTIOC.all = ECanaRegs.CANTIOC.all;
ECanaShadow.CANTIOC.bit.TXFUNC = 1;
ECanaRegs.CANTIOC.all = ECanaShadow.CANRIOC.all;
ECanaShadow.CANRIOC.all = ECanaRegs.CANRIOC.all;
ECanaShadow.CANRIOC.bit.RXFUNC = 1;
ECanaRegs.CANRIOC.all = ECanaShadow.CANRIOC.all;
EDIS;
EALLOW;
ECanaShadow.CANMC.all = ECanaRegs.CANMC.all;
ECanaShadow.CANMC.bit.STM = 0;
ECanaShadow.CANMC.bit.SCM = 1;
ECanaRegs.CANMC.all = ECanaShadow.CANMC.all;
EDIS;
ECanaMboxes.MBOX16.MCF.all=0x00000000;
ECanaRegs.CANTA.all=0xFFFFFFFF;
ECanaRegs.CANRMP.all=0xFFFFFFFF;
ECanaRegs.CANGIF0.all = 0xFFFFFFFF;
ECanaRegs.CANGIF1.all = 0xFFFFFFFF;
EALLOW;
//邮箱屏蔽使能
ECanaShadow.CANMC.all = ECanaRegs.CANMC.all;
ECanaShadow.CANMC.bit.CCR = 1;
ECanaRegs.CANMC.all = ECanaShadow.CANMC.all;
EDIS;
do
{
ECanaShadow.CANES.all = ECanaRegs.CANES.all;
}while(ECanaShadow.CANES.bit.CCE != 1);
// 125kHz CAN clock
EALLOW;
ECanaShadow.CANBTC.bit.BRP = 79; //9
ECanaShadow.CANBTC.bit.TSEG2 = 2; //5
ECanaShadow.CANBTC.bit.TSEG1 = 10; //7
ECanaRegs.CANBTC.all = ECanaShadow.CANBTC.all;
ECanaShadow.CANMC.all = ECanaRegs.CANMC.all;
ECanaShadow.CANMC.bit.CCR = 0;
ECanaRegs.CANMC.all = ECanaShadow.CANMC.all;
EDIS;
do
{
ECanaShadow.CANES.all = ECanaRegs.CANES.all;
}while(ECanaShadow.CANES.bit.CCE != 0);
ECanaRegs.CANME.all=0;
ECanaMboxes.MBOX16.MID.all = 0x80C20000;
ECanaShadow.CANMD.all = ECanaRegs.CANMD.all;
ECanaShadow.CANMD.bit.MD16 = 1;
ECanaRegs.CANMD.all = ECanaShadow.CANMD.all;
ECanaMboxes.MBOX16.MCF.bit.DLC = 8;
ECanaMboxes.MBOX16.MCF.bit.RTR = 0;
ECanaShadow.CANME.all = ECanaRegs.CANME.all;
ECanaShadow.CANME.bit.ME16=1;
ECanaRegs.CANME.all = ECanaShadow.CANME.all;
EALLOW;
ECanaRegs.CANMIM.all = 0xFFFFFFFF;
ECanaRegs.CANMIL.all =0;
ECanaRegs.CANGIF0.all = 0xFFFFFFFF;
ECanaRegs.CANGIM.bit.I0EN = 1;
EDIS;
} |