关于CAN通信的一点疑问
时间:10-02
整理:3721RD
点击:
大家好,小弟最近在学习DSP28335,在CAN通信时遇到了点问题,CAN 收发都调试成功了,但是总觉得程序不够完善,想请教下各位。
1、没有错误处理机制,所以我查了一些资料,现在加了个总线关闭时初始化ECan的操作,还没调试,不知道这样处理是否可行。另外想问下,还由其他必要的系统中断和邮箱中断要处理吗? 例如邮箱超时等。
Code:
//系统中断
interrupt void ECAN0INTA_ISR(void) // eCAN-A
{
struct ECAN_REGS ECanaShadow;
do{
ECanaShadow.CANGIF0.all=ECanaRegs.CANGIF0.all;
}while(ECanaShadow.CANGIF0.all & 0x3FF00 == 0x00000000);
//总线关闭
if(ECanaShadow.CANGIF0.bit.BOIF0==1){
InitECan();
Msg0x440.configMbx(&Msg0x440);
Msg0x100.configMbx(&Msg0x100);
Msg0x200.configMbx(&Msg0x200);
}
PieCtrlRegs.PIEACK.all = PIEACK_GROUP9;
EINT;
// Next two lines for debug only to halt the processor here
// Remove after inserting ISR Code
//asm (" ESTOP0");
//for(;;);
}
//邮箱中断
interrupt void ECAN1INTA_ISR(void) // eCAN-A
{
// Insert ISR Code here
//If mailbox n contains a received message, bit RMP[n] of this register is set
struct ECAN_REGS ECanaShadow;
do{
ECanaShadow.CANRMP.all=ECanaRegs.CANRMP.all;
}while(ECanaShadow.CANRMP.all & 0xFFFF0000 == 0x00000000);
if(ECanaShadow.CANRMP.bit.RMP16==1){
ECanaRegs.CANRMP.all=0x00010000;
Msg0x100.BYTE[0]=ECanaMboxes.MBOX16.MDL.byte.BYTE0;
Msg0x100.BYTE[1]=ECanaMboxes.MBOX16.MDL.byte.BYTE1;
Msg0x100.BYTE[2]=ECanaMboxes.MBOX16.MDL.byte.BYTE2;
Msg0x100.BYTE[3]=ECanaMboxes.MBOX16.MDL.byte.BYTE3;
Msg0x100.BYTE[4]=ECanaMboxes.MBOX16.MDH.byte.BYTE4;
Msg0x100.BYTE[5]=ECanaMboxes.MBOX16.MDH.byte.BYTE5;
Msg0x100.BYTE[6]=ECanaMboxes.MBOX16.MDH.byte.BYTE6;
Msg0x100.BYTE[7]=ECanaMboxes.MBOX16.MDH.byte.BYTE7;
}
if(ECanaShadow.CANRMP.bit.RMP17==1){
ECanaRegs.CANRMP.all=0x00020000;
Msg0x200.BYTE[0]=ECanaMboxes.MBOX17.MDL.byte.BYTE0;
Msg0x200.BYTE[1]=ECanaMboxes.MBOX17.MDL.byte.BYTE1;
Msg0x200.BYTE[2]=ECanaMboxes.MBOX17.MDL.byte.BYTE2;
Msg0x200.BYTE[3]=ECanaMboxes.MBOX17.MDL.byte.BYTE3;
Msg0x200.BYTE[4]=ECanaMboxes.MBOX17.MDH.byte.BYTE4;
Msg0x200.BYTE[5]=ECanaMboxes.MBOX17.MDH.byte.BYTE5;
Msg0x200.BYTE[6]=ECanaMboxes.MBOX17.MDH.byte.BYTE6;
Msg0x200.BYTE[7]=ECanaMboxes.MBOX17.MDH.byte.BYTE7;
}
// To receive more interrupts from this PIE group, acknowledge this interrupt
PieCtrlRegs.PIEACK.all = PIEACK_GROUP9;
EINT;
// Next two lines for debug only to halt the processor here
// Remove after inserting ISR Code
//asm (" ESTOP0");
//for(;;);
}
2、CAN的断电模式是否只在器件要进入低功耗模式时用到?
1、没有错误处理机制,所以我查了一些资料,现在加了个总线关闭时初始化ECan的操作,还没调试,不知道这样处理是否可行。另外想问下,还由其他必要的系统中断和邮箱中断要处理吗? 例如邮箱超时等。
Code:
//系统中断
interrupt void ECAN0INTA_ISR(void) // eCAN-A
{
struct ECAN_REGS ECanaShadow;
do{
ECanaShadow.CANGIF0.all=ECanaRegs.CANGIF0.all;
}while(ECanaShadow.CANGIF0.all & 0x3FF00 == 0x00000000);
//总线关闭
if(ECanaShadow.CANGIF0.bit.BOIF0==1){
InitECan();
Msg0x440.configMbx(&Msg0x440);
Msg0x100.configMbx(&Msg0x100);
Msg0x200.configMbx(&Msg0x200);
}
PieCtrlRegs.PIEACK.all = PIEACK_GROUP9;
EINT;
// Next two lines for debug only to halt the processor here
// Remove after inserting ISR Code
//asm (" ESTOP0");
//for(;;);
}
//邮箱中断
interrupt void ECAN1INTA_ISR(void) // eCAN-A
{
// Insert ISR Code here
//If mailbox n contains a received message, bit RMP[n] of this register is set
struct ECAN_REGS ECanaShadow;
do{
ECanaShadow.CANRMP.all=ECanaRegs.CANRMP.all;
}while(ECanaShadow.CANRMP.all & 0xFFFF0000 == 0x00000000);
if(ECanaShadow.CANRMP.bit.RMP16==1){
ECanaRegs.CANRMP.all=0x00010000;
Msg0x100.BYTE[0]=ECanaMboxes.MBOX16.MDL.byte.BYTE0;
Msg0x100.BYTE[1]=ECanaMboxes.MBOX16.MDL.byte.BYTE1;
Msg0x100.BYTE[2]=ECanaMboxes.MBOX16.MDL.byte.BYTE2;
Msg0x100.BYTE[3]=ECanaMboxes.MBOX16.MDL.byte.BYTE3;
Msg0x100.BYTE[4]=ECanaMboxes.MBOX16.MDH.byte.BYTE4;
Msg0x100.BYTE[5]=ECanaMboxes.MBOX16.MDH.byte.BYTE5;
Msg0x100.BYTE[6]=ECanaMboxes.MBOX16.MDH.byte.BYTE6;
Msg0x100.BYTE[7]=ECanaMboxes.MBOX16.MDH.byte.BYTE7;
}
if(ECanaShadow.CANRMP.bit.RMP17==1){
ECanaRegs.CANRMP.all=0x00020000;
Msg0x200.BYTE[0]=ECanaMboxes.MBOX17.MDL.byte.BYTE0;
Msg0x200.BYTE[1]=ECanaMboxes.MBOX17.MDL.byte.BYTE1;
Msg0x200.BYTE[2]=ECanaMboxes.MBOX17.MDL.byte.BYTE2;
Msg0x200.BYTE[3]=ECanaMboxes.MBOX17.MDL.byte.BYTE3;
Msg0x200.BYTE[4]=ECanaMboxes.MBOX17.MDH.byte.BYTE4;
Msg0x200.BYTE[5]=ECanaMboxes.MBOX17.MDH.byte.BYTE5;
Msg0x200.BYTE[6]=ECanaMboxes.MBOX17.MDH.byte.BYTE6;
Msg0x200.BYTE[7]=ECanaMboxes.MBOX17.MDH.byte.BYTE7;
}
// To receive more interrupts from this PIE group, acknowledge this interrupt
PieCtrlRegs.PIEACK.all = PIEACK_GROUP9;
EINT;
// Next two lines for debug only to halt the processor here
// Remove after inserting ISR Code
//asm (" ESTOP0");
//for(;;);
}
2、CAN的断电模式是否只在器件要进入低功耗模式时用到?