使用Ecantool调试的时候发现只能自动识别1000k的波特率,改成其他波特率都能不能自动识别,一直也找不到问题出在哪,想问问大家有遇到类似的情况吗?怎么解决的。代码如下:
void main(void)
{
// struct ECAN_REGS ECanaShadow;
struct ECAN_REGS ECanbShadow;
InitSysCtrl();
//初始化GPIO,将其配置成PWM方式
EALLOW;
InitEPwm1Gpio();//将GPIO0和GPIO1引脚配置为PWM模式,即EPWM1A和EPWM1B
InitEPwm2Gpio();//将GPIO2和GPIO3引脚配置为PWM模式,即EPWM1A和EPWM1B
InitEPwm6Gpio();//将GPIO10和GPIO11引脚配置为PWM模式,即EPWM6A和EPWM6B
EDIS;
InitECanGpio();
//禁用全局中断
DINT;
//初始化PIE控制向量表和控制函数
InitPieCtrl();
//禁止所有CPU中断和清除所有CPU中断标志
IER = 0x0000;
IFR = 0x0000;
//初始化PIE中断向量表
InitPieVectTable();
InitECan();
EALLOW;
ECanbRegs.CANMC.bit.DBO = 1;// 定义数据读取方向,1由低位向高位读,0相反
EDIS;
//配置邮箱0-6发送ID
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;
//配置邮箱16接收ID
ECanbMboxes.MBOX16.MSGID.all = 0x9807000f;
//邮箱0-6作为发送邮箱,邮箱7作为发送邮箱;1表示接收,0表示发送
ECanbShadow.CANMD.all = ECanbRegs.CANMD.all;
ECanbShadow.CANMD.all = 0xFFFF0000;//0-15全作为发送邮箱,16-31全作为接收邮箱
ECanbRegs.CANMD.all = ECanbShadow.CANMD.all;
//使能邮箱
ECanbShadow.CANME.all = ECanbRegs.CANME.all;
ECanbShadow.CANME.all = 0xFFFFFFFF;//使能全部邮箱
ECanbRegs.CANME.all = ECanbShadow.CANME.all;
//发送或接受8位数据
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;
//烧录FLASH
// MemCopy(&RamfuncsLoadStart, &RamfuncsLoadEnd, &RamfuncsRunStart);
// InitFlash();
//使能模拟内核电压,进芯DSP需要
AdcRegs.ADCTRL1.bit.rsvd1 = 0x0008; //1000
//调整模拟内核电压,进芯DSP需要
AdcRegs.ADCTRL1.bit.rsvd1 = 0x000F; //1111
//初始化ADC
InitAdc();
//初始化EPWM时钟及PWM中断工作方式
InitEPwmTimer();
//执行ADC配置函数
ConfigADC();
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;
EDIS;
Initlimit();//自定义初始化限幅
//执行PWM配置函数
ConfigEPwm1();
ConfigEPwm2();
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;
EDIS;
//设置中断的入口地址
EALLOW;
PieVectTable.EPWM6_INT=&epwm6_timer_isr;
EDIS;
//EPWM1_INT位于PIE的第三组第一个
IER|=M_INT3;//这句话意思等价于IER=IER|M_INT3,将IER处的第三组使能
PieCtrlRegs.PIEIER3.bit.INTx6 = PWM6_INT_ENABLE;//将PIEIER3对应的第一位
//使能全局中断
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; //清除0-6号邮箱发送成功的置位,等待下一次发送
ECanbRegs.CANTA.all = ECanbShadow.CANTA.all;
//接收
ECanbShadow.CANTRS.all = 0;
ECanbShadow.CANTRS.all = 0x00010000; // 允许16邮箱接收,置1时开始接收
ECanbRegs.CANTRS.all = ECanbShadow.CANTRS.all;
CANtoDSP = ECanbMboxes.MBOX16.MDH.all;//上位机传送到DSP的数据
// //这里不注释掉程序会卡在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;
}
}
更多回帖