我的发送邮箱初始化程序如下,目的是初始化MB1为发送邮箱(自动应答),当接收到远程帧时自动发送具有相同标识符的数据帧到Can总线。
查了很多资料,貌似只要 MD=0,RTR=0,AAM=1,就可以将邮箱设置为自动应答模式,但是调试了几天没成功,发帖请教,请论坛里的朋友们多多指教,在此感激不尽!
void
InitECan(void)
{
struct ECAN_REGS ECanaShadow;
//配置GPIO引脚工作在eCAN功能
EALLOW;
GpioMuxRegs.GPFMUX.bit.CANRXA_GPIOF7=1;
GpioMuxRegs.GPFMUX.bit.CANTXA_GPIOF6=1;
//配置eCAN的RX和TX分别为eCAN的接收和发送引脚
ECanaShadow.CANTIOC.all = ECanaRegs.CANTIOC.all;
ECanaShadow.CANTIOC.bit.TXFUNC = 1;
ECanaRegs.CANTIOC.all = ECanaShadow.CANTIOC.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;
//工作在ecan模式
ECanaShadow.CANMC.bit.SCB = 1;
ECanaShadow.CANMC.bit.DBO = 1;
ECanaShadow.CANMC.bit.ABO = 1;
ECanaRegs.CANMC.all = ECanaShadow.CANMC.all;
EDIS;
ECanaMboxes.MBOX0.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX1.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX2.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX3.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX4.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX5.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX6.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX7.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX8.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX9.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX10.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX11.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX12.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX13.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX14.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX15.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX16.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX17.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX18.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX19.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX20.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX21.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX22.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX23.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX24.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX25.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX26.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX27.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX28.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX29.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX30.MSGCTRL.all = 0x00000000;
ECanaMboxes.MBOX31.MSGCTRL.all = 0x00000000;
//清除所有的TA位
ECanaRegs.CANTA.all = 0xFFFFFFFF;
//清除所有的RMP位
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);
EALLOW;
ECanaRegs.CANBTC.bit.SAM = 0;
ECanaRegs.CANBTC.bit.BRPREG = 19; //500K 90M
ECanaRegs.CANBTC.bit.TSEG2REG = 2;
ECanaRegs.CANBTC.bit.TSEG1REG = 4;
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);
}
void
ECan_Send_MB_Init(void)
{
ECanaShadow.CANME.all = ECanaRegs.CANME.all;
ECanaShadow.CANME.bit.ME1 = 0;
ECanaRegs.CANME.all = ECanaShadow.CANME.all;
ECanaShadow.CANMD.all = ECanaRegs.CANMD.all;
ECanaShadow.CANMD.bit.MD1 = 0;
ECanaRegs.CANMD.all = ECanaShadow.CANMD.all;
ECanaMboxes.MBOX1.MSGID.bit.AME = 0;
ECanaMboxes.MBOX1.MSGID.bit.AAM = 1;
ECanaMboxes.MBOX1.MSGID.bit.IDE = 0;
ECanaMboxes.MBOX1.MSGID.bit.STDMSGID = 0x191;
ECanaMboxes.MBOX1.MSGID.bit.EXTMSGID_L = 0;
ECanaMboxes.MBOX1.MSGID.bit.EXTMSGID_H = 0;
ECanaMboxes.MBOX1.MSGCTRL.bit.RTR = 0;
ECanaMboxes.MBOX1.MSGCTRL.bit.DLC = 8;
EALLOW;
ECanaShadow.CANMC.all = ECanaRegs.CANMC.all;
ECanaRegs.CANMC.bit.CDR = 1;
ECanaRegs.CANMC.all = ECanaShadow.CANMC.all;
EDIS;
ECanaMboxes.MBOX1.MDL.byte.BYTE1 = 1;
ECanaMboxes.MBOX1.MDL.byte.BYTE2 = 2;
ECanaMboxes.MBOX1.MDL.byte.BYTE3 = 3;
ECanaMboxes.MBOX1.MDL.byte.BYTE4 = 4;
ECanaMboxes.MBOX1.MDH.byte.BYTE5 = 5;
ECanaMboxes.MBOX1.MDH.byte.BYTE6 = 6;
ECanaMboxes.MBOX1.MDH.byte.BYTE7 = 7;
ECanaMboxes.MBOX1.MDH.byte.BYTE8 = 8;
EALLOW;
ECanaShadow.CANMC.all = ECanaRegs.CANMC.all;
ECanaRegs.CANMC.bit.CDR = 0;
ECanaRegs.CANMC.all = ECanaShadow.CANMC.all;
EDIS;
ECanaShadow.CANME.all = ECanaRegs.CANME.all;
ECanaShadow.CANME.bit.ME1 = 1;
ECanaRegs.CANME.all = ECanaShadow.CANME.all;
}
|