用2812做can总线通信,250k波特率,30M时钟,150M主频,之前一直没注意,因为和USBCAN盒通讯都正常。最近连一个外部设备,2812发送,USBCAN盒能正常接收,但是该设备接收不了,最后,用示波器看波形,发现我的2812输出电平显性电平是4us,但隐形电平只有3.7us,不知道大家遇到过这种问题吗
我的can初始化程序如下:
void InitECan(void)
{
struct ECAN_REGS ECanaShadow;
EALLOW;
//配置GPIO引脚工作在eCAN功能
SysCtrlRegs.PCLKCR.bit.ECANENCLK = 1; // LSPCLK to SCIA enabled
/* Configure eCAN pins for CAN operation using GPIO regs*/
GpioMuxRegs.GPFMUX.bit.CANTXA_GPIOF6 = 1;
GpioMuxRegs.GPFMUX.bit.CANRXA_GPIOF7 = 1;
//配置GPIO引脚工作在eCAN功能
//配置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.CCR = 1;
ECanaRegs.CANMC.all = ECanaShadow.CANMC.all;
EDIS;
//CPU请求向CANBTC和CANGAM写配置信息,该位置1后必须等到CANED.CCE为1,才能
//对CANBTC进行操作。
do
{
ECanaShadow.CANES.all = ECanaRegs.CANES.all;
}
while(ECanaShadow.CANES.bit.CCE != 1);
EALLOW;
//(BRPREG+1)=10 ,CAN时钟为15MHz
ECanaShadow.CANBTC.bit.BRP = 39;
//CAN通信的波特率为250kHz
ECanaShadow.CANBTC.bit.TSEG2 = 2;
ECanaShadow.CANBTC.bit.TSEG1 = 10;
ECanaRegs.CANBTC.all = ECanaShadow.CANBTC.all;
EDIS;
EALLOW;
ECanaShadow.CANMC.all = ECanaRegs.CANMC.all;
//工作在非测试模式
ECanaShadow.CANMC.bit.STM = 0;
//工作在ecan模式
ECanaShadow.CANMC.bit.SCM = 1;
ECanaShadow.CANMC.bit.DBO = 1;
ECanaShadow.CANMC.bit.CCR = 0;
ECanaShadow.CANMC.bit.PDR = 0;
ECanaShadow.CANMC.bit.WUBA = 1;
ECanaShadow.CANMC.bit.CDR = 0;
ECanaShadow.CANMC.bit.ABO = 1;
ECanaShadow.CANMC.bit.SRES = 0;
ECanaShadow.CANMC.bit.MBNR = 0;
ECanaRegs.CANMC.all = ECanaShadow.CANMC.all;
EDIS;
//初始化所有主设备控制区域为0,控制区域所有的位都初始化为0
ECanaMboxes.MBOX0.MCF.all = 0x00000000;
ECanaMboxes.MBOX1.MCF.all = 0x00000000;
ECanaMboxes.MBOX2.MCF.all = 0x00000000;
ECanaMboxes.MBOX3.MCF.all = 0x00000000;
ECanaMboxes.MBOX4.MCF.all = 0x00000000;
ECanaMboxes.MBOX5.MCF.all = 0x00000000;
ECanaMboxes.MBOX6.MCF.all = 0x00000000;
ECanaMboxes.MBOX7.MCF.all = 0x00000000;
ECanaMboxes.MBOX8.MCF.all = 0x00000000;
ECanaMboxes.MBOX9.MCF.all = 0x00000000;
ECanaMboxes.MBOX10.MCF.all = 0x00000000;
ECanaMboxes.MBOX11.MCF.all = 0x00000000;
ECanaMboxes.MBOX12.MCF.all = 0x00000000;
ECanaMboxes.MBOX13.MCF.all = 0x00000000;
ECanaMboxes.MBOX14.MCF.all = 0x00000000;
ECanaMboxes.MBOX15.MCF.all = 0x00000000;
ECanaMboxes.MBOX16.MCF.all = 0x00000000;
ECanaMboxes.MBOX17.MCF.all = 0x00000000;
ECanaMboxes.MBOX18.MCF.all = 0x00000000;
ECanaMboxes.MBOX19.MCF.all = 0x00000000;
ECanaMboxes.MBOX20.MCF.all = 0x00000000;
ECanaMboxes.MBOX21.MCF.all = 0x00000000;
ECanaMboxes.MBOX22.MCF.all = 0x00000000;
ECanaMboxes.MBOX23.MCF.all = 0x00000000;
ECanaMboxes.MBOX24.MCF.all = 0x00000000;
ECanaMboxes.MBOX25.MCF.all = 0x00000000;
ECanaMboxes.MBOX26.MCF.all = 0x00000000;
ECanaMboxes.MBOX27.MCF.all = 0x00000000;
ECanaMboxes.MBOX28.MCF.all = 0x00000000;
ECanaMboxes.MBOX29.MCF.all = 0x00000000;
ECanaMboxes.MBOX30.MCF.all = 0x00000000;
ECanaMboxes.MBOX31.MCF.all = 0x00000000;
do
{
ECanaShadow.CANES.all = ECanaRegs.CANES.all;
}
while(ECanaShadow.CANES.bit.CCE != 0);
//清除所有的TA位
EALLOW;
ECanaRegs.CANTRR.all = 0xFFFFFFFF;
ECanaRegs.CANTA.all = 0xFFFFFFFF;
//清除所有的RMP位
ECanaRegs.CANRMP.all = 0xFFFFFFFF;
//清除所有的中断标志位
ECanaRegs.CANGIF0.all = 0xFFFFFFFF;
ECanaRegs.CANGIF1.all = 0xFFFFFFFF;
EDIS;
//屏蔽所有邮箱,在写MSGID之前要完成该操作
ECanaRegs.CANME.all = 0;
//设置发送邮箱的ID号,
ECanaMboxes.MBOX16.MID.bit.IDE = 0;//标准标识符
ECanaMboxes.MBOX16.MID.bit.AAM = 0;//正常发送模式
ECanaMboxes.MBOX16.MID.bit.AME = 0;//不使用接收屏蔽,所有的标识符位必须匹配
ECanaMboxes.MBOX16.MID.bit.MSGID_H = (UINT)(((POS_TR << 7) | uCANID)<<2);
//设置接收邮箱的ID,
ECanaMboxes.MBOX0.MID.all = 0x40000000; // standard frame, Acceptance mask enable,ID=0
ECanaMboxes.MBOX1.MID.all = 0x40000000; // standard frame, Acceptance mask enable,ID=0
ECanaMboxes.MBOX2.MID.all = 0x40000000; // standard frame, Acceptance mask enable,ID=0
ECanaMboxes.MBOX3.MID.all = 0x40000000; // standard frame, Acceptance mask enable,ID=0
ECanaMboxes.MBOX4.MID.all = 0x40000000; // standard frame, Acceptance mask enable,ID=0
ECanaMboxes.MBOX5.MID.all = 0x40000000; // standard frame, Acceptance mask enable,ID=0
ECanaMboxes.MBOX6.MID.all = 0x40000000; // standard frame, Acceptance mask enable,ID=0
ECanaMboxes.MBOX7.MID.all = 0x40000000; // standard frame, Acceptance mask enable,ID=0
ECanaMboxes.MBOX8.MID.all = 0x40000000; // standard frame, Acceptance mask enable,ID=0
ECanaMboxes.MBOX9.MID.all = 0x40000000; // standard frame, Acceptance mask enable,ID=0
ECanaMboxes.MBOX10.MID.all = 0x40000000; // standard frame, Acceptance mask enable,ID=0
ECanaMboxes.MBOX11.MID.all = 0x40000000; // standard frame, Acceptance mask enable,ID=0
ECanaMboxes.MBOX12.MID.all = 0x40000000; // standard frame, Acceptance mask enable,ID=0
ECanaMboxes.MBOX13.MID.all = 0x40000000; // standard frame, Acceptance mask enable,ID=0
ECanaMboxes.MBOX14.MID.all = 0x40000000; // standard frame, Acceptance mask enable,ID=0
ECanaMboxes.MBOX15.MID.all = 0x40000000; // standard frame, Acceptance mask enable,ID=0
EALLOW;
ECanaLAMRegs.LAM0.all = 0x1FFFFFFF; // standard frame, every bit Acceptance mask enable
ECanaLAMRegs.LAM1.all = 0x1FFFFFFF; // standard frame, every bit Acceptance mask enable
ECanaLAMRegs.LAM2.all = 0x1FFFFFFF; // standard frame, every bit Acceptance mask enable
ECanaLAMRegs.LAM3.all = 0x1FFFFFFF; // standard frame, every bit Acceptance mask enable
ECanaLAMRegs.LAM4.all = 0x1FFFFFFF; // standard frame, every bit Acceptance mask enable
ECanaLAMRegs.LAM5.all = 0x1FFFFFFF; // standard frame, every bit Acceptance mask enable
ECanaLAMRegs.LAM6.all = 0x1FFFFFFF; // standard frame, every bit Acceptance mask enable
ECanaLAMRegs.LAM7.all = 0x1FFFFFFF; // standard frame, every bit Acceptance mask enable
ECanaLAMRegs.LAM8.all = 0x1FFFFFFF; // standard frame, every bit Acceptance mask enable
ECanaLAMRegs.LAM9.all = 0x1FFFFFFF; // standard frame, every bit Acceptance mask enable
ECanaLAMRegs.LAM10.all = 0x1FFFFFFF; // standard frame, every bit Acceptance mask enable
ECanaLAMRegs.LAM11.all = 0x1FFFFFFF; // standard frame, every bit Acceptance mask enable
ECanaLAMRegs.LAM12.all = 0x1FFFFFFF; // standard frame, every bit Acceptance mask enable
ECanaLAMRegs.LAM13.all = 0x1FFFFFFF; // standard frame, every bit Acceptance mask enable
ECanaLAMRegs.LAM14.all = 0x1FFFFFFF; // standard frame, every bit Acceptance mask enable
ECanaLAMRegs.LAM15.all = 0x1FFFFFFF; // standard frame, every bit Acceptance mask enable
EDIS;
// ECanaMboxes.MBOX3.MID.bit.MSGID_H = (UINT)(uCANID<<2);
//设置邮箱3为接收邮箱
ECanaShadow.CANMD.all = ECanaRegs.CANMD.all;
ECanaShadow.CANMD.all =0x0000ffff;
ECanaRegs.CANMD.all = ECanaShadow.CANMD.all;
//数据长度 8个BYTE
ECanaMboxes.MBOX16.MCF.bit.DLC = 8;
ECanaMboxes.MBOX0.MCF.bit.DLC = 8;
ECanaMboxes.MBOX1.MCF.bit.DLC = 8;
ECanaMboxes.MBOX2.MCF.bit.DLC = 8;
ECanaMboxes.MBOX3.MCF.bit.DLC = 8;
ECanaMboxes.MBOX4.MCF.bit.DLC = 8;
ECanaMboxes.MBOX5.MCF.bit.DLC = 8;
ECanaMboxes.MBOX6.MCF.bit.DLC = 8;
ECanaMboxes.MBOX7.MCF.bit.DLC = 8;
ECanaMboxes.MBOX8.MCF.bit.DLC = 8;
ECanaMboxes.MBOX9.MCF.bit.DLC = 8;
ECanaMboxes.MBOX10.MCF.bit.DLC = 8;
ECanaMboxes.MBOX11.MCF.bit.DLC = 8;
ECanaMboxes.MBOX12.MCF.bit.DLC = 8;
ECanaMboxes.MBOX13.MCF.bit.DLC = 8;
ECanaMboxes.MBOX14.MCF.bit.DLC = 8;
ECanaMboxes.MBOX15.MCF.bit.DLC = 8;
//设置发送优先级
ECanaMboxes.MBOX16.MCF.bit.TPL = 2;
//没有远方应答帧被请求*/
ECanaMboxes.MBOX16.MCF.bit.RTR = 0;
ECanaMboxes.MBOX3.MCF.bit.RTR = 0;
//向邮箱RAM区写数据
ECanaMboxes.MBOX16.MDRL.all = 0x00000000;
ECanaMboxes.MBOX16.MDRH.all = 0x00000000;
//邮箱中断使能
EALLOW;
//邮箱使能
//邮箱中断将产生在ECAN0INT
ECanaRegs.CANMIL.all = 0x00000000;
ECanaRegs.CANGIF0.all = 0xFFFFFFFF;
ECanaRegs.CANGIF1.all = 0xFFFFFFFF;
//ECAN0INT中断请求线被使能
ECanaRegs.CANGIM.all = 0x00000001;
EDIS;
} |
|