TI中文支持网
TI专业的中文技术问题搜集分享网站

我的DSP F28034 CAN能发送数据,但是收不到数据

Other Parts Discussed in Thread:ISO1050

void InitECan(void)
{
struct ECAN_REGS ECanaShadow;
EALLOW;
GpioCtrlRegs.GPAMUX2.bit.GPIO30 = 1; // 0=GPIO, 1=CANRX-A, 2=Resv, 3=Resv
GpioCtrlRegs.GPAMUX2.bit.GPIO31 = 1; // 0=GPIO, 1=CANTX-A, 2=Resv, 3=Resv
GpioCtrlRegs.GPAPUD.bit.GPIO30 = 0; // Enable pull-up for GPIO30 (CANRXA)
GpioCtrlRegs.GPAPUD.bit.GPIO31 = 0; // Enable pull-up for GPIO31 (CANTXA)
GpioCtrlRegs.GPAQSEL2.bit.GPIO30 = 3; // Asynch qual for GPIO30 (CANRXA)

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;//设置通信(接收)引脚

ECanaShadow.CANMC.all = ECanaRegs.CANMC.all;
ECanaShadow.CANMC.bit.SCB = 1;
ECanaRegs.CANMC.all = ECanaShadow.CANMC.all;

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;

ECanaRegs.CANTA.all = 0xFFFFFFFF; //写1清零,准备判别下一次发送与否
ECanaRegs.CANRMP.all = 0xFFFFFFFF; //当接收消息成功时,接收待决位RMP0置位为1

ECanaRegs.CANGIF0.all = 0xFFFFFFFF;
ECanaRegs.CANGIF1.all = 0xFFFFFFFF;
ECanaShadow.CANMC.all = ECanaRegs.CANMC.all;
ECanaShadow.CANMC.bit.CCR = 1 ; // Set CCR = 1
ECanaRegs.CANMC.all = ECanaShadow.CANMC.all;
do
{
ECanaShadow.CANES.all = ECanaRegs.CANES.all;
} while(ECanaShadow.CANES.bit.CCE != 1 ); // Wait for CCE bit to be set..

ECanaShadow.CANBTC.all = 0;
ECanaShadow.CANBTC.bit.BRPREG = 3; // 1000 Kbps @ 30 MHz SYSCLKOUT
ECanaShadow.CANBTC.bit.TSEG1REG = 3;
ECanaShadow.CANBTC.bit.TSEG2REG = 2;
ECanaRegs.CANBTC.all = ECanaShadow.CANBTC.all;

ECanaShadow.CANMC.all = ECanaRegs.CANMC.all;
ECanaShadow.CANMC.bit.CCR = 0 ; // Set CCR = 0
ECanaShadow.CANMC.bit.SUSP= 1 ; //FREE MODEL
ECanaShadow.CANMC.bit.ABO = 1 ; //AUTO BUS ON
ECanaShadow.CANMC.bit.DBO= 0 ;
ECanaRegs.CANMC.all = ECanaShadow.CANMC.all;

do
{
ECanaShadow.CANES.all = ECanaRegs.CANES.all;
} while(ECanaShadow.CANES.bit.CCE != 0 ); // Wait for CCE bit to be cleared..

ECanaRegs.CANOPC.all = 0x00000002;

ECanaShadow.CANGAM.all = ECanaRegs.CANGAM.all;
ECanaShadow.CANGAM.all= 0x9FFFFFFF; //可以接受标准帧和扩展帧
ECanaRegs.CANGAM.all = ECanaShadow.CANGAM.all;

ECanaRegs.CANME.all = 0; // Required before writing the MSGIDs
ECanaMboxes.MBOX0.MSGID.all = 0x1E800000;
ECanaMboxes.MBOX1.MSGID.all = 0x95555555;
ECanaMboxes.MBOX2.MSGID.all = 0x1E880000;
ECanaMboxes.MBOX3.MSGID.all = 0x1E8C0000;
ECanaMboxes.MBOX4.MSGID.all = 0x1E900000;
ECanaMboxes.MBOX5.MSGID.all = 0x1E940000;
ECanaMboxes.MBOX6.MSGID.all = 0x1E980000;
ECanaMboxes.MBOX7.MSGID.all = 0x1E9C0000;
ECanaMboxes.MBOX8.MSGID.all = 0x1EA00000;
ECanaMboxes.MBOX9.MSGID.all = 0x1EA40000;
ECanaMboxes.MBOX10.MSGID.all = 0x1EA80000;
ECanaMboxes.MBOX11.MSGID.all = 0x1EAC0000;
ECanaMboxes.MBOX12.MSGID.all = 0x1EB00000;
ECanaMboxes.MBOX13.MSGID.all = 0x1EB40000;
ECanaMboxes.MBOX14.MSGID.all = 0x1EB80000;
ECanaMboxes.MBOX15.MSGID.all = 0x1EBC0000;

ECanaMboxes.MBOX16.MSGID.all = 0x1EC00000;
ECanaMboxes.MBOX17.MSGID.all = 0x1EC40000;
ECanaMboxes.MBOX18.MSGID.all = 0x1EC80000;
ECanaMboxes.MBOX19.MSGID.all = 0x1ECC0000;
ECanaMboxes.MBOX20.MSGID.all = 0x1ED00000;
ECanaMboxes.MBOX21.MSGID.all = 0x1ED40000;
ECanaMboxes.MBOX22.MSGID.all = 0x1ED80000;
ECanaMboxes.MBOX23.MSGID.all = 0x1EDC0000;
ECanaMboxes.MBOX24.MSGID.all = 0x1EE00000;
ECanaMboxes.MBOX25.MSGID.all = 0x1EE40000;
ECanaMboxes.MBOX26.MSGID.all = 0x1EE80000;
ECanaMboxes.MBOX27.MSGID.all = 0x1EEC0000;
ECanaMboxes.MBOX28.MSGID.all = 0x1EF00000;
ECanaMboxes.MBOX29.MSGID.all = 0x1EF40000;
ECanaMboxes.MBOX30.MSGID.all = 0x1EF80000;
ECanaMboxes.MBOX31.MSGID.all = 0x1EFC0000;
//设置0号邮箱为发送邮箱,其他31个邮箱为接收邮箱
ECanaRegs.CANMD.all = 0xFFFFFFFE;
//启用所有邮箱
ECanaRegs.CANME.all = 0xFFFFFFFF;
ECanaMboxes.MBOX0.MSGCTRL.bit.DLC = 8;
//启用1号邮箱的屏蔽位为0xfffffff,表示匹配所有
ECanaMboxes.MBOX1.MSGID.bit.AME = 1;
ECanaLAMRegs.LAM1.all = 0xFFFFFFFF;
// 5. 中断配置
ECanaShadow.CANMIM.all = ECanaRegs.CANMIM.all;
ECanaShadow.CANMIM.bit.MIM1=1; //启用1号邮箱的中断掩码,屏蔽其他邮箱的中断
ECanaRegs.CANMIM.all = ECanaShadow.CANMIM.all;

//邮箱中断设置在0号中断线
ECanaShadow.CANMIL.all = ECanaRegs.CANMIL.all;
ECanaShadow.CANMIL.all = 0x00000000; // 1-32号邮箱中断在中断线0上产生
ECanaRegs.CANMIL.all = ECanaShadow.CANMIL.all;

//如果邮箱收到1条消息,则指定邮箱的RMP为1,0邮箱不包含消息
ECanaRegs.CANRMP.all = 0xFFFFFFFF;

ECanaShadow.CANGIM.all = ECanaRegs.CANGIM.all;
ECanaShadow.CANGIM.bit.I0EN = 1 ; //中断线0使能
ECanaRegs.CANGIM.all = ECanaShadow.CANGIM.all;
//有CANMIL位决定使用9.5还是9.6号中断
PieCtrlRegs.PIEIER9.bit.INTx5 = 1;
IER |= M_INT9;
PieCtrlRegs.PIECTRL.bit.ENPIE=1;
PieCtrlRegs.PIEACK.all = PIEACK_GROUP9;// Enable TINT0 in the PIE: Group 1 interrupt 7// Enable CPU INT1 which is connected to CPU-Timer 0:PieCtrlRegs.PIEIER1.bit.INTx7 = 1; IER |= M_INT1;// Enable global Interrupts and higher priority real-time debug events:EINT;

ECanaShadow.CANMC.all = ECanaRegs.CANMC.all;
ECanaShadow.CANMC.bit.STM = 0; // Configure CAN for common mode
ECanaRegs.CANMC.all = ECanaShadow.CANMC.all;

//使能所有邮箱
ECanaRegs.CANME.all = 0xFFFFFFFF;

EDIS;
}

下面是MAIN中的部分代码

InitECan();

EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.ECAN0INTA = &Ecan0ISR;//R-CAN1 接收后中断函数
ECanaRegs.CANTA.all = 1;
EDIS;

EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM

for(;;)
{
LoopCount++;

CAN_sendBuf[0]=AdcResult.ADCRESULT0%256;
CAN_sendBuf[1]=AdcResult.ADCRESULT0/256;
CAN_sendBuf[2]=AdcResult.ADCRESULT1%256;
CAN_sendBuf[3]=AdcResult.ADCRESULT1/256;
CAN_sendBuf[4]=AdcResult.ADCRESULT2%256;
CAN_sendBuf[5]=AdcResult.ADCRESULT2/256;
CAN_sendBuf[6]=PWM%256;
CAN_sendBuf[7]=PWM/256;

CAN_SendExt(8);
if((ECanaRegs.CANRMP.all ) !=0)
{
//如果邮箱有数据
cmd.cmdfuc=1;
}

}
}

__interrupt void Ecan0ISR(void)
{
cmd.cmdtype=ECanaMboxes.MBOX1.MDL.byte.BYTE0;
cmd.cmdfuc=ECanaMboxes.MBOX1.MDL.byte.BYTE1;
cmd.data1=ECanaMboxes.MBOX1.MDL.byte.BYTE2;
cmd.data2=ECanaMboxes.MBOX1.MDL.byte.BYTE3;
cmd.data3=ECanaMboxes.MBOX1.MDH.byte.BYTE4;
cmd.data4=ECanaMboxes.MBOX1.MDH.byte.BYTE5;

struct ECAN_REGS ECanaShadow;
//clear CANRMP flags
ECanaShadow.CANRMP.all = ECanaRegs.CANRMP.all;
ECanaRegs.CANRMP.all = ECanaShadow.CANRMP.all;
ProcessData();

}

Susan Yang:

请问您现在使用的硬件设备是什么?两块F28034+2个 CAN收发器?请详细说明一下

另外请使用右下角“使用高级编辑器编辑文本”中的代码上传工具来上传代码或者以附件形式上传工程以方便查看,谢谢

,

sulin su:

我现在下位机是F28034+1个CAN口,上位机用的USBCAN接收数据,上位机能收到数据,但上位机下发数据,DSP进不了中断也查不到接收标记。

,

sulin su:

,

Susan Yang:

图片上传失败,请您以附件i形式上传,谢谢

“F28034+1个CAN口”是指F28034外加CAN收发器吗?

“上位机能收到数据,但上位机下发数据,DSP进不了中断也查不到接收标记。”

请您先确定上位机确实发送了数据。

,

sulin su:

是F28034加CAN收发器+ISO1050收发器

,

Susan Yang:

请您先尝试不使用“接受掩码过滤”的方法。也就是说,发送的MSGID和接收MBX的MSGID完全相同,并且不使用任何掩码位。看是否可以成功

,

sulin su:

//启用1号邮箱的屏蔽位为0xfffffff,表示匹配所有// ECanaMboxes.MBOX1.MSGID.bit.AME = 1;// ECanaLAMRegs.LAM1.all = 0xFFFFFFFF;

我把这两句代码屏蔽了,再次测试,还是收不到。

,

Susan Yang:

能发送给上位机接收,说明硬件上问题应该不大。单从软件,代码配置的话,并没有发现什么问题。所以考虑是否是上位机有一些特殊配置?因为一般测试的话,是两个板子分别加CAN收发器来测试的

赞(0)
未经允许不得转载:TI中文支持网 » 我的DSP F28034 CAN能发送数据,但是收不到数据
分享到: 更多 (0)