使用Ecantool调试的时候发现只能自动识别1000k的波特率,改成其他波特率都能不能自动识别,一直也找不到问题出在哪,想问问大家有遇到类似的情况吗?怎么解决的。代码如下:
void main(void)
{
// struct ECAN_REGS ECanaShadow;
struct ECAN_REGS ECanbShadow;
InitSysCtrl();
EALLOW;
InitEPwm1Gpio();
InitEPwm2Gpio();
InitEPwm6Gpio();
EDIS;
InitECanGpio();
DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
InitECan();
EALLOW;
ECanbRegs.CANMC.bit.DBO = 1;
EDIS;
ECanbMboxes.MBOX0.MSGID.all = 0x98050001;
ECanbMboxes.MBOX1.MSGID.all = 0x98050003;
ECanbMboxes.MBOX2.MSGID.all = 0x98050004;
ECanbMboxes.MBOX3.MSGID.all = 0x98050005;
ECanbMboxes.MBOX4.MSGID.all = 0x98050006;
ECanbMboxes.MBOX5.MSGID.all = 0x98050007;
ECanbMboxes.MBOX6.MSGID.all = 0x98050008;
ECanbMboxes.MBOX16.MSGID.all = 0x9807000f;
ECanbShadow.CANMD.all = ECanbRegs.CANMD.all;
ECanbShadow.CANMD.all = 0xFFFF0000;
ECanbRegs.CANMD.all = ECanbShadow.CANMD.all;
ECanbShadow.CANME.all = ECanbRegs.CANME.all;
ECanbShadow.CANME.all = 0xFFFFFFFF;
ECanbRegs.CANME.all = ECanbShadow.CANME.all;
ECanbMboxes.MBOX0.MSGCTRL.bit.DLC = 8;
ECanbMboxes.MBOX1.MSGCTRL.bit.DLC = 8;
ECanbMboxes.MBOX2.MSGCTRL.bit.DLC = 8;
ECanbMboxes.MBOX3.MSGCTRL.bit.DLC = 8;
ECanbMboxes.MBOX4.MSGCTRL.bit.DLC = 8;
ECanbMboxes.MBOX5.MSGCTRL.bit.DLC = 8;
ECanbMboxes.MBOX6.MSGCTRL.bit.DLC = 8;
ECanbMboxes.MBOX16.MSGCTRL.bit.DLC = 8;
// MemCopy(&RamfuncsLoadStart, &RamfuncsLoadEnd, &RamfuncsRunStart);
// InitFlash();
AdcRegs.ADCTRL1.bit.rsvd1 = 0x0008;
AdcRegs.ADCTRL1.bit.rsvd1 = 0x000F;
InitAdc();
InitEPwmTimer();
ConfigADC();
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;
EDIS;
Initlimit();
ConfigEPwm1();
ConfigEPwm2();
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;
EDIS;
EALLOW;
PieVectTable.EPWM6_INT=&epwm6_timer_isr;
EDIS;
IER|=M_INT3;
PieCtrlRegs.PIEIER3.bit.INTx6 = PWM6_INT_ENABLE;
EINT;
ERTM;
while(1)
{
}
}
//定义中断服务程序
interrupt void epwm6_timer_isr(void)
{
n++;
if(n >= f_int)
{
PIE++;
n = 0;
CANtr = 1;
}
SettingADC();
/CAN发送/接收-开始******/
if(CANtr == 1)
{
//发送采样数据
ECanbMboxes.MBOX0.MDL.all = 0;
ECanbMboxes.MBOX0.MDH.all = 1; //0号邮箱发送UL,ID18070001
ECanbMboxes.MBOX1.MDL.all = 0;
ECanbMboxes.MBOX1.MDH.all = 1; //1号邮箱发送IL,ID18070003
ECanbMboxes.MBOX2.MDL.all = 0;
ECanbMboxes.MBOX2.MDH.all = 1; //2号邮箱发送UH,ID18070004
ECanbMboxes.MBOX3.MDL.all = 0;
ECanbMboxes.MBOX3.MDH.all = 1; //3号邮箱发送IH,ID18070005
ECanbMboxes.MBOX4.MDL.all = 0;
ECanbMboxes.MBOX4.MDH.all = 1; //4号邮箱发送T1,ID18070006
ECanbMboxes.MBOX5.MDL.all = 0;
ECanbMboxes.MBOX5.MDH.all = 1; //5号邮箱发送T2,ID18070007
ECanbMboxes.MBOX6.MDL.all = 0;
ECanbMboxes.MBOX6.MDH.all = 1; //6号邮箱发送T3,ID18070008
//发送
// ECanbShadow.CANTRS.all = 0;
ECanbShadow.CANTRS.all = 0x0000007F; // 允许0-6邮箱发送,置1时开始发送
ECanbRegs.CANTRS.all = ECanbShadow.CANTRS.all;
// do
// {
// ECanbShadow.CANTA.all = ECanbRegs.CANTA.all;
// } while(ECanbShadow.CANTA.bit.TA0 == 0);//MSGCTRL中的TPL值相同的情况下邮箱号大的先发送,所以TA0置零时说明所有数据均已发送
//
ECanbShadow.CANTA.all = 0;
ECanbShadow.CANTA.all = 0x0000007F;
ECanbRegs.CANTA.all = ECanbShadow.CANTA.all;
ECanbShadow.CANTRS.all = 0;
ECanbShadow.CANTRS.all = 0x00010000;
ECanbRegs.CANTRS.all = ECanbShadow.CANTRS.all;
CANtoDSP = ECanbMboxes.MBOX16.MDH.all;
// //这里不注释掉程序会卡在while判断
// do
// {
// ECanbShadow.CANRMP.all = ECanbRegs.CANRMP.all;
// } while(ECanbShadow.CANRMP.bit.RMP16 == 0);
//
// ECanbShadow.CANRMP.all = 0;
// ECanbShadow.CANRMP.all = 0x00010000; //清除16号邮箱发送成功的置位,等待下一次发送
// ECanbRegs.CANRMP.all = ECanbShadow.CANRMP.all;
CANtr = 0;
}
}