DSP28335 CAN接收不到另外一个CAN节点发送的数据,数据帧格式为:01 C0 11 22 33 44 55 66 77 88。01 C0为帧信息,后面的为数据。两个CAN节点的波特率均为500kbs,我配置的CAN接收为中断接收。我用另外一个CAN模块是可以收到发送CAN节点发送的数据的。不知道是不是我配置的CAN节点配置有误,还是数据被我屏蔽了。#include "DSP2833x_Device.h" // Headerfile Include File
#include "DSP2833x_GlobalPrototypes.h"
#include "DSP2833x_SWPrioritizedIsrLevels.h"
#include "DSP2833x_Project.h"
/*
*
*/
interrupt void canb_receive_isr(void);
Uint16 Send(void);
Uint32 recData_L;
Uint32 recData_H;
void main()
{
struct ECAN_REGS ECanbShadow;
// 1 初始化系统
InitSysCtrl();
// 2 初始化引脚
InitECanGpio();
// 3 清除中断
DINT;
// 初始化PIE中断控制寄存器
InitPieCtrl();
// 关闭CPU中断,清除CPU中断标志
IER = 0x0000;
IFR = 0x0000;
// 初始化PIE中断向量表
InitPieVectTable();
EALLOW;
PieVectTable.ECAN0INTB = &canb_receive_isr;
EDIS;
// 4 初始化设备
InitECanb();
// 5 用户代码
// 写MSGID
ECanbMboxes.MBOX25.MSGID.all = 0x04000000;
ECanbMboxes.MBOX5.MSGID.all = 0x07000000;
// 配置邮箱25为发送邮箱
ECanbShadow.CANMD.all = ECanbRegs.CANMD.all;
ECanbShadow.CANMD.bit.MD25 = 0;
ECanbShadow.CANMD.bit.MD5 = 1;
ECanbRegs.CANMD.all = ECanbShadow.CANMD.all;
// 使能邮箱25
ECanbShadow.CANME.all = ECanbRegs.CANME.all;
ECanbShadow.CANME.bit.ME25 = 1;
ECanbShadow.CANME.bit.ME5 = 1;
ECanbRegs.CANME.all = ECanbShadow.CANME.all;
// 在消息控制器中写DLC区:数据长度为8
ECanbMboxes.MBOX25.MSGCTRL.bit.DLC = 2;//数据长度
ECanbMboxes.MBOX5.MSGCTRL.bit.DLC = 8;
// MBOX25数据为0002
ECanbMboxes.MBOX25.MDL.byte.BYTE0 = 0x00;
ECanbMboxes.MBOX25.MDL.byte.BYTE1 = 0x02;
// 没有远程应答帧请求
ECanbMboxes.MBOX5.MSGCTRL.bit.RTR = 0;
// 邮箱中断使能
EALLOW;
ECanbRegs.CANMIM.all = 0xFFFFFFFF; // 使能所有的邮箱产生中断,没有用到的邮箱不产生中断
// 邮箱中断将产生ECAN0INT中断
ECanbRegs.CANMIL.all = 0; // 在中断线0产生中断
ECanbRegs.CANGIF0.all = 0xFFFFFFFF; // 全局中断标志寄存器
// ECAN0INT中断请求线使能
ECanbRegs.CANGIM.bit.I0EN = 1; // 使能中断线0产生中断
EDIS;
// 使能中断
IER |= M_INT9;
// 使能PIE中断
PieCtrlRegs.PIEIER9.bit.INTx7 = 1;
PieCtrlRegs.PIEACK.bit.ACK9 = 1;
EINT;
ERTM;
Send();
for(;;);
}
Uint16 Send(void)
{
struct ECAN_REGS ECanbShadow;
ECanbShadow.CANTRS.all = 0;
ECanbShadow.CANTRS.bit.TRS25 = 1;
ECanbRegs.CANTRS.all = ECanbShadow.CANTRS.all;
do{
ECanbShadow.CANTA.all = ECanbRegs.CANTA.all;
}while((ECanbShadow.CANTA.bit.TA25 == 0));
ECanbShadow.CANTA.all = 0;
ECanbShadow.CANTA.bit.TA25 = 1;
ECanbRegs.CANTA.all = ECanbShadow.CANTA.all;
return 1;
}
interrupt void canb_receive_isr(void)
{
struct ECAN_REGS ECanbShadow;
ECanbShadow.CANRMP.all = ECanbRegs.CANRMP.all;
while(ECanbShadow.CANRMP.bit.RMP5 != 1);
ECanbRegs.CANRMP.bit.RMP5 = 1; // 复位RMP,同时复位中断标志
ECanbRegs.CANRMP.all = ECanbShadow.CANRMP.all;
recData_L = ECanbMboxes.MBOX5.MDL.all;
recData_H = ECanbMboxes.MBOX5.MDH.all;
PieCtrlRegs.PIEACK.bit.ACK9 = 1;
EINT;
}
|