• 回复
  • 收藏
  • 点赞
  • 分享
  • 发新帖

TMS320F2812有关CAN通信问题

现做变频电源用此IC
用到CAN总线与远程PC通信
一般情况下通信没问题已在用.
在异常下:有可能是消息冲突,超载等没处理好使CAN模块停止了
在一段时间里有停止通信现象,重上电复位就好.
就像路由器有时不能上网,重上电就好一样.
请高人指点一下!非常感谢!
原CAN初始代码与发送接收代码如下:



void InitCAN(void)
{
Uint32 x1;
EALLOW;
ECanaShadow.CANTIOC.all = ECanaRegs.CANTIOC.all;
ECanaShadow.CANTIOC.bit.TXFUNC = 1;
ECanaRegs.CANTIOC.all = ECanaShadow.CANRIOC.all;

ECanaShadow.CANRIOC.all = ECanaRegs.CANRIOC.all;
ECanaShadow.CANRIOC.bit.RXFUNC = 1;
ECanaRegs.CANRIOC.all = ECanaShadow.CANRIOC.all;
EDIS;
ECanaRegs.CANME.all = 0;
//客流的转换模块的发送ID 0x02 接收0x20
/*发送邮箱的ID号*/
x1=DeviceNumber;
x1=x1*0x40000;
ECanaMboxes.MBOX0.MSGID.all = x1;//+0x40000;//发送
/*接收邮箱的ID号*/
ECanaMboxes.MBOX6.MSGID.all =x1;
ECanaMboxes.MBOX7.MSGID.all =x1;
ECanaMboxes.MBOX8.MSGID.all =x1;        //接收
ECanaMboxes.MBOX9.MSGID.all =0x03480000;//接收
/*0 is TX,8 is RX*/
ECanaRegs.CANMD.all = 0x000003c0;
/*邮箱使能8-1*/
ECanaRegs.CANME.all = 0x000003c1;

ECanaMboxes.MBOX0.MSGCTRL.bit.DLC = 8;
ECanaMboxes.MBOX6.MSGCTRL.bit.DLC = 8;
ECanaMboxes.MBOX7.MSGCTRL.bit.DLC = 8;
ECanaMboxes.MBOX8.MSGCTRL.bit.DLC = 8;
ECanaMboxes.MBOX9.MSGCTRL.bit.DLC = 8;

ECanaMboxes.MBOX0.MSGCTRL.bit.TPL=1;
ECanaMboxes.MBOX6.MSGCTRL.bit.TPL=0;
ECanaMboxes.MBOX7.MSGCTRL.bit.TPL=0;
ECanaMboxes.MBOX8.MSGCTRL.bit.TPL=0;
ECanaMboxes.MBOX9.MSGCTRL.bit.TPL=0;
  
/*没有远方应答帧被请求*/
ECanaMboxes.MBOX0.MSGCTRL.bit.RTR = 0;
ECanaMboxes.MBOX6.MSGCTRL.bit.RTR = 0;
ECanaMboxes.MBOX7.MSGCTRL.bit.RTR = 0;
ECanaMboxes.MBOX8.MSGCTRL.bit.RTR = 0;
ECanaMboxes.MBOX9.MSGCTRL.bit.RTR = 0;

EALLOW;
/*邮箱使能*/
ECanaRegs.CANMIM.all = 0xFFFFFFFF;
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;
/*(BRPREG+1)=100  波特率50K*/
ECanaShadow.CANBTC.bit.BRPREG = 99;
ECanaShadow.CANBTC.bit.TSEG2REG = 5;
ECanaShadow.CANBTC.bit.TSEG1REG = 12;

ECanaRegs.CANBTC.all = ECanaShadow.CANBTC.all;

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);

EALLOW;
ECanaShadow.CANMC.all = ECanaRegs.CANMC.all;
ECanaShadow.CANMC.bit.SUSP= 1;//
ECanaShadow.CANMC.bit.STM = 0;//自测试模式=1
ECanaShadow.CANMC.bit.SCB = 0;//ecan模式=1
ECanaRegs.CANMC.all = ECanaShadow.CANMC.all;
EDIS;
EALLOW;

ECanaRegs.CANMIM.all = 0x000003c1;//Enable Box0(TXD) Box8(RXD)
ECanaRegs.CANMIL.all = 0x00000001;//Box0->CANINT1;Box->CANINT0;
ECanaRegs.CANRMP.all = 0x00000000;
ECanaRegs.CANGIF0.all= 0xffffffff; //Crear All INT Status Flag
ECanaRegs.CANGIF1.all= 0xffffffff;
ECanaRegs.CANGIM.all = 0x30003;//Close All NMI
//ECanaRegs.CANTOC.all =0x00000301;//Enable Timer Over

EDIS;

EALLOW;
PieVectTable.ECAN0INTA=&cpu_ECANRXD_isr;
PieVectTable.ECAN1INTA=&cpu_ECANTXD_isr;
EDIS;
PieCtrlRegs.PIEIER9.bit.INTx6 = 1;
PieCtrlRegs.PIEIER9.bit.INTx5 = 1;  
}



interrupt void cpu_ECANRXD_isr(void)  // eCAN-A
{
if((ECanaRegs.CANRMP.bit.RMP6==1)||(ECanaRegs.CANRMP.bit.RMP7==1)||
    (ECanaRegs.CANRMP.bit.RMP8==1)||(ECanaRegs.CANRMP.bit.RMP9==1)
   )
   {  
    这里是接受数据处理代码;   
   }
PieCtrlRegs.PIEACK.bit.ACK9 = 1;
}

interrupt void cpu_ECANTXD_isr(void)  // eCAN-A
{
  
if(ECanaRegs.CANTA.all == 0x00000001)
    {
     ECanaRegs.CANTA.all = 0x00000001;
    } //清除中断标志
PieCtrlRegs.PIEACK.bit.ACK9 = 1;
}
全部回复(0)
正序查看
倒序查看
现在还没有回复呢,说说你的想法