1、开启三个接受邮箱的配置
{
Uint32 i,*addr;
unsigned long ulECanCntTmp;
struct ECAN_REGS ECanaShadow;
EALLOW;
ECanaRegs.CANME.all=0x00000000;//屏蔽所有邮箱
// CANTX 引脚作为CAN 模块的发送引脚
ECanaShadow.CANTIOC.all=ECanaRegs.CANTIOC.all;
ECanaShadow.CANTIOC.bit.TXFUNC=1;
ECanaRegs.CANTIOC.all=ECanaShadow.CANTIOC.all;
// CANRX 引脚作为CAN 模块的接收引脚
ECanaShadow.CANRIOC.all=ECanaRegs.CANRIOC.all;
ECanaShadow.CANRIOC.bit.RXFUNC=1;
ECanaRegs.CANRIOC.all=ECanaShadow.CANRIOC.all;
/* Configure eCAN for HECC mode – (reqd to access mailboxes 16 thru 31) */
//HECC mode also enables time-stamping feature
ECanaShadow.CANMC.all=ECanaRegs.CANMC.all;
ECanaShadow.CANMC.bit.SUSP=1;// 1:如断点,单行执行模式下,外设正常运行 0:当前消息发送完毕后,外设关闭
ECanaShadow.CANMC.bit.SCB=1; // 1:选择eCAN 模式,0:eCAN 工作在SCC 模式,只有邮箱0~15可用
ECanaShadow.CANMC.bit.ABO=1; // 1:在总线脱离状态下,检测到128×11 隐性位后,模块将自动恢复总线的连接状态,0:总线脱离状态只有在检测到128×11 连续的隐性位并且已经清除CCR 位后才跳出
ECanaRegs.CANMC.all=ECanaShadow.CANMC.all;
/* Initialize all bits of 'Master Control Field' to zero */
//Some bits of MSGCTRL comeup in an unknown state.all bits (including reserved bits) of MSGCTRL must be initialized to zero
//ECanaMboxes.MBOX0.MSGCTRL.all =0x00000000;
//…
for(i=0x6100;i<0x6200;i++) //清理邮箱,6100-61ffh是eCan的RAM空间,对应MailBox0-31
{
addr=(unsigned long *)i;
*addr=0;
}
ECanaMboxes.MBOX0.MSGCTRL.bit.DLC = 8; //决定收发的字节数,8 Bytes. Valid value range is from 0-8.
ECanaMboxes.MBOX1.MSGCTRL.bit.DLC = 8;
ECanaMboxes.MBOX2.MSGCTRL.bit.DLC = 8;
ECanaMboxes.MBOX3.MSGCTRL.bit.DLC = 8;
ECanaMboxes.MBOX4.MSGCTRL.bit.DLC = 8;
ECanaMboxes.MBOX5.MSGCTRL.bit.DLC = 8;
ECanaMboxes.MBOX6.MSGCTRL.bit.DLC = 8;
ECanaMboxes.MBOX3.MSGCTRL.bit.DLC = 8;
// 接收邮箱
ECanaMboxes.MBOX0.MSGID.all=0xD8ffF300;
ECanaMboxes.MBOX1.MSGID.all=0x07220000 << 2 |0x40000000; ECanaMboxes.MBOX2.MSGID.all=0xD8ff0000|(CanLoadPositionAddr<<8)|CanLoadSourceAddr; //F1 111 1000 1011 在线升级 2号邮箱拓展帧 接收
// 发送邮箱
ECanaMboxes.MBOX3.MSGID.all=0xC50F8003; //100ms 客户 定时 发送
ECanaMboxes.MBOX4.MSGID.all=0xC60F8003;
ECanaMboxes.MBOX5.MSGID.all=0x07EA0000 << 2 | 0x40000000;
ECanaMboxes.MBOX6.MSGID.all=0xD8ff0000|CanLoadPositionAddr; //在线升级 6号邮箱拓展帧 发送
//TAn, RMPn, GIFn bits are all zero upon reset and are cleared again as a matter of precaution.
ECanaRegs.CANTA.all=0xFFFFFFFF; //Clear all TAn bits
ECanaRegs.CANRMP.all=0xFFFFFFFF; //Clear all RMPn bits
ECanaRegs.CANGIF0.all=0xFFFFFFFF; //Clear all interrupt flag bits
ECanaRegs.CANGIF1.all=0xFFFFFFFF;
/* Configure bit timing parameters for eCANA*/
ECanaShadow.CANMC.all=ECanaRegs.CANMC.all;
ECanaShadow.CANMC.bit.CCR=1; //=1 必须在CCE flag of CANES=1后才能写CANBTC,CANGAM(屏蔽寄存器)
ECanaRegs.CANMC.all=ECanaShadow.CANMC.all;
ECanaShadow.CANES.all=ECanaRegs.CANES.all;//错误和状态寄存器复位
ulECanCntTmp=0;
while(ECanaShadow.CANES.bit.CCE != 1) //while last 1.1msMax //Wait for CCE bit to be set..
{
//KickDog();//不起
ECanaShadow.CANES.all=ECanaRegs.CANES.all;
ulECanCntTmp++;
if(ulECanCntTmp>20000)//10.4ms {
break;
}
}
ECanaShadow.CANBTC.all=0;
ECanaShadow.CANBTC.bit.BRPREG=7;//19; // 30000000/{(19+1)*[(2+1)+(1+1)+1}=250KB
ECanaShadow.CANBTC.bit.TSEG2REG=2;//1; // 30000000/{(9+1)*[(2+1)+(1+1)+1}=500KB
ECanaShadow.CANBTC.bit.TSEG1REG=10;//2; //6
ECanaShadow.CANBTC.bit.SAM=0; //0:只采样1次 1:3次采样,多数的值作为最终的结果
ECanaShadow.CANBTC.bit.SJWREG=2; //0; 当CAN 通信节点重新同步时,SJW 表示定义了一个通信位可以延长或缩短的TQ 值的数量。SJW 可以在1~4 之间进行调整。
ECanaRegs.CANBTC.all=ECanaShadow.CANBTC.all;
ECanaShadow.CANMC.all=ECanaRegs.CANMC.all;
ECanaShadow.CANMC.bit.CCR=0;
ECanaRegs.CANMC.all=ECanaShadow.CANMC.all;
ECanaShadow.CANES.all=ECanaRegs.CANES.all;
ulECanCntTmp=0;
while(ECanaShadow.CANES.bit.CCE!=0)//14.4us //Wait for CCE bit to be cleared..
{
ECanaShadow.CANES.all=ECanaRegs.CANES.all;
ulECanCntTmp++;
if(ulECanCntTmp>20000)//10.4ms {
break;
}
}
/* Enable Mailboxe 0.1.4.5 */// 使能012,456邮箱
ui32CanMePara=0x0000007F; // 0x0000007F
ECanaRegs.CANME.all=ui32CanMePara; //Required before writing the MSGIDs,使能0123,456邮箱
ECanaRegs.CANMD.all=0x00000007; //Mail direction,0:transmit,1:receive 3,4,5,6发送,0,1,2接收
EDIS;
/* even curr, receive data from other module */
ECanaLAMRegs.LAM0.all=0x87FFFFFF; //只判断0x18 //800FFFFC;//31:接收标准和扩展帧,
ECanaLAMRegs.LAM1.all=0xFFFFFFFF; //0:必须匹配 1:Don't care 29-2全部接收 0-1,19-28必须匹配 就是PROTNO和PTP必须满足条件
ECanaLAMRegs.LAM2.all=0x87FF0000;;
// ECanaLAMRegs.LAM4.all=0x87FFFFFF;//800FFFFC;//1000..1111.1111.1111.1111.1100
// ECanaLAMRegs.LAM5.all=0x800FFFFC;// 0x800FFFFC
// ECanaLAMRegs.LAM6.all=0x800FFFFC; // 1: 0xc6080783
}
2、开启两个邮箱的配置
与三个邮箱不同之处如下:
(1)、
ui32CanMePara=0x0000007F; // 0x0000007F
ECanaRegs.CANME.all=ui32CanMePara; //Required before writing the MSGIDs,使能0123,456邮箱
(2)、
ui32CanMePara=0x0000007D; // 0x0000007F
ECanaRegs.CANME.all=ui32CanMePara; //Required before writing the MSGIDs,使能0123,456邮箱
jianqi sun:(1)、这种情况开启三个接受邮箱
ui32CanMePara=0x0000007F; ECanaRegs.CANME.all=ui32CanMePara;
(2)、这种情况开启两个接受邮箱
ui32CanMePara=0x0000007D;ECanaRegs.CANME.all=ui32CanMePara;
1、开启三个接受邮箱的配置
{
Uint32 i,*addr;
unsigned long ulECanCntTmp;
struct ECAN_REGS ECanaShadow;
EALLOW;
ECanaRegs.CANME.all=0x00000000;//屏蔽所有邮箱
// CANTX 引脚作为CAN 模块的发送引脚
ECanaShadow.CANTIOC.all=ECanaRegs.CANTIOC.all;
ECanaShadow.CANTIOC.bit.TXFUNC=1;
ECanaRegs.CANTIOC.all=ECanaShadow.CANTIOC.all;
// CANRX 引脚作为CAN 模块的接收引脚
ECanaShadow.CANRIOC.all=ECanaRegs.CANRIOC.all;
ECanaShadow.CANRIOC.bit.RXFUNC=1;
ECanaRegs.CANRIOC.all=ECanaShadow.CANRIOC.all;
/* Configure eCAN for HECC mode – (reqd to access mailboxes 16 thru 31) */
//HECC mode also enables time-stamping feature
ECanaShadow.CANMC.all=ECanaRegs.CANMC.all;
ECanaShadow.CANMC.bit.SUSP=1;// 1:如断点,单行执行模式下,外设正常运行 0:当前消息发送完毕后,外设关闭
ECanaShadow.CANMC.bit.SCB=1; // 1:选择eCAN 模式,0:eCAN 工作在SCC 模式,只有邮箱0~15可用
ECanaShadow.CANMC.bit.ABO=1; // 1:在总线脱离状态下,检测到128×11 隐性位后,模块将自动恢复总线的连接状态,0:总线脱离状态只有在检测到128×11 连续的隐性位并且已经清除CCR 位后才跳出
ECanaRegs.CANMC.all=ECanaShadow.CANMC.all;
/* Initialize all bits of 'Master Control Field' to zero */
//Some bits of MSGCTRL comeup in an unknown state.all bits (including reserved bits) of MSGCTRL must be initialized to zero
//ECanaMboxes.MBOX0.MSGCTRL.all =0x00000000;
//…
for(i=0x6100;i<0x6200;i++) //清理邮箱,6100-61ffh是eCan的RAM空间,对应MailBox0-31
{
addr=(unsigned long *)i;
*addr=0;
}
ECanaMboxes.MBOX0.MSGCTRL.bit.DLC = 8; //决定收发的字节数,8 Bytes. Valid value range is from 0-8.
ECanaMboxes.MBOX1.MSGCTRL.bit.DLC = 8;
ECanaMboxes.MBOX2.MSGCTRL.bit.DLC = 8;
ECanaMboxes.MBOX3.MSGCTRL.bit.DLC = 8;
ECanaMboxes.MBOX4.MSGCTRL.bit.DLC = 8;
ECanaMboxes.MBOX5.MSGCTRL.bit.DLC = 8;
ECanaMboxes.MBOX6.MSGCTRL.bit.DLC = 8;
ECanaMboxes.MBOX3.MSGCTRL.bit.DLC = 8;
// 接收邮箱
ECanaMboxes.MBOX0.MSGID.all=0xD8ffF300;
ECanaMboxes.MBOX1.MSGID.all=0x07220000 << 2 |0x40000000; ECanaMboxes.MBOX2.MSGID.all=0xD8ff0000|(CanLoadPositionAddr<<8)|CanLoadSourceAddr; //F1 111 1000 1011 在线升级 2号邮箱拓展帧 接收
// 发送邮箱
ECanaMboxes.MBOX3.MSGID.all=0xC50F8003; //100ms 客户 定时 发送
ECanaMboxes.MBOX4.MSGID.all=0xC60F8003;
ECanaMboxes.MBOX5.MSGID.all=0x07EA0000 << 2 | 0x40000000;
ECanaMboxes.MBOX6.MSGID.all=0xD8ff0000|CanLoadPositionAddr; //在线升级 6号邮箱拓展帧 发送
//TAn, RMPn, GIFn bits are all zero upon reset and are cleared again as a matter of precaution.
ECanaRegs.CANTA.all=0xFFFFFFFF; //Clear all TAn bits
ECanaRegs.CANRMP.all=0xFFFFFFFF; //Clear all RMPn bits
ECanaRegs.CANGIF0.all=0xFFFFFFFF; //Clear all interrupt flag bits
ECanaRegs.CANGIF1.all=0xFFFFFFFF;
/* Configure bit timing parameters for eCANA*/
ECanaShadow.CANMC.all=ECanaRegs.CANMC.all;
ECanaShadow.CANMC.bit.CCR=1; //=1 必须在CCE flag of CANES=1后才能写CANBTC,CANGAM(屏蔽寄存器)
ECanaRegs.CANMC.all=ECanaShadow.CANMC.all;
ECanaShadow.CANES.all=ECanaRegs.CANES.all;//错误和状态寄存器复位
ulECanCntTmp=0;
while(ECanaShadow.CANES.bit.CCE != 1) //while last 1.1msMax //Wait for CCE bit to be set..
{
//KickDog();//不起
ECanaShadow.CANES.all=ECanaRegs.CANES.all;
ulECanCntTmp++;
if(ulECanCntTmp>20000)//10.4ms {
break;
}
}
ECanaShadow.CANBTC.all=0;
ECanaShadow.CANBTC.bit.BRPREG=7;//19; // 30000000/{(19+1)*[(2+1)+(1+1)+1}=250KB
ECanaShadow.CANBTC.bit.TSEG2REG=2;//1; // 30000000/{(9+1)*[(2+1)+(1+1)+1}=500KB
ECanaShadow.CANBTC.bit.TSEG1REG=10;//2; //6
ECanaShadow.CANBTC.bit.SAM=0; //0:只采样1次 1:3次采样,多数的值作为最终的结果
ECanaShadow.CANBTC.bit.SJWREG=2; //0; 当CAN 通信节点重新同步时,SJW 表示定义了一个通信位可以延长或缩短的TQ 值的数量。SJW 可以在1~4 之间进行调整。
ECanaRegs.CANBTC.all=ECanaShadow.CANBTC.all;
ECanaShadow.CANMC.all=ECanaRegs.CANMC.all;
ECanaShadow.CANMC.bit.CCR=0;
ECanaRegs.CANMC.all=ECanaShadow.CANMC.all;
ECanaShadow.CANES.all=ECanaRegs.CANES.all;
ulECanCntTmp=0;
while(ECanaShadow.CANES.bit.CCE!=0)//14.4us //Wait for CCE bit to be cleared..
{
ECanaShadow.CANES.all=ECanaRegs.CANES.all;
ulECanCntTmp++;
if(ulECanCntTmp>20000)//10.4ms {
break;
}
}
/* Enable Mailboxe 0.1.4.5 */// 使能012,456邮箱
ui32CanMePara=0x0000007F; // 0x0000007F
ECanaRegs.CANME.all=ui32CanMePara; //Required before writing the MSGIDs,使能0123,456邮箱
ECanaRegs.CANMD.all=0x00000007; //Mail direction,0:transmit,1:receive 3,4,5,6发送,0,1,2接收
EDIS;
/* even curr, receive data from other module */
ECanaLAMRegs.LAM0.all=0x87FFFFFF; //只判断0x18 //800FFFFC;//31:接收标准和扩展帧,
ECanaLAMRegs.LAM1.all=0xFFFFFFFF; //0:必须匹配 1:Don't care 29-2全部接收 0-1,19-28必须匹配 就是PROTNO和PTP必须满足条件
ECanaLAMRegs.LAM2.all=0x87FF0000;;
// ECanaLAMRegs.LAM4.all=0x87FFFFFF;//800FFFFC;//1000..1111.1111.1111.1111.1100
// ECanaLAMRegs.LAM5.all=0x800FFFFC;// 0x800FFFFC
// ECanaLAMRegs.LAM6.all=0x800FFFFC; // 1: 0xc6080783
}
2、开启两个邮箱的配置
与三个邮箱不同之处如下:
(1)、
ui32CanMePara=0x0000007F; // 0x0000007F
ECanaRegs.CANME.all=ui32CanMePara; //Required before writing the MSGIDs,使能0123,456邮箱
(2)、
ui32CanMePara=0x0000007D; // 0x0000007F
ECanaRegs.CANME.all=ui32CanMePara; //Required before writing the MSGIDs,使能0123,456邮箱
Annie Liu:
为更加有效地解决您的问题,我们建议您将问题发布在E2E英文技术论坛上https://e2e.ti.com/support/microcontrollers/c2000/f/171,将由资深的工程师为您提供帮助。我们的E2E英文社区有TI专家进行回复,并得到全球各地工程师的支持,分享他们的知识和经验。