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

28335的CAN中断接收方式

按照官方配置,配置完can接收,采用中断接收,debug时进不了中断。有没有遇到类似情况的?求解答。

void InitECan(void) // Initialize eCAN-B module
{
struct ECAN_REGS ECanbShadow;
EALLOW; // EALLOW enables access to protected bits
//配置GPIO工作在额eCAN功能
GpioCtrlRegs.GPAPUD.bit.GPIO16 = 1; // Disable pull-up for GPIO16 (CANTXB)
GpioCtrlRegs.GPAPUD.bit.GPIO17 = 0; // Enable pull-up for GPIO17 (CANRXB)
GpioCtrlRegs.GPAQSEL2.bit.GPIO17 = 3; // Asynch qual for GPIO17 (CANRXB)
GpioCtrlRegs.GPAMUX2.bit.GPIO16 = 2; // Configure GPIO16 for CANTXB operation
GpioCtrlRegs.GPAMUX2.bit.GPIO17 = 2; // Configure GPIO17 for CANRXB operation

//配置eCAN的RX和TX分别为eCAN的接收和发射引脚

ECanbShadow.CANTIOC.all = ECanbRegs.CANTIOC.all;

ECanbShadow.CANTIOC.bit.TXFUNC = 1;

ECanbRegs.CANTIOC.all = ECanbShadow.CANTIOC.all;

ECanbShadow.CANRIOC.all = ECanbRegs.CANRIOC.all;
ECanbShadow.CANRIOC.bit.RXFUNC = 1;
ECanbRegs.CANRIOC.all = ECanbShadow.CANRIOC.all;

/* Configure bit timing parameters for eCANB*/
ECanbShadow.CANMC.all = ECanbRegs.CANMC.all;
ECanbShadow.CANMC.bit.CCR = 1 ; // Set CCR = 1
ECanbRegs.CANMC.all = ECanbShadow.CANMC.all;

ECanbShadow.CANES.all = ECanbRegs.CANES.all;
do
{ECanbShadow.CANES.bit.CCE=ECanbRegs.CANES.bit.CCE;}
while(ECanbShadow.CANES.bit.CCE != 1 ) ; // Wait for CCE bit to be set..CCE等于1时跳出循环,则可以对CANBTC设置

//设置通信波特率
ECanbShadow.CANBTC.all = ECanbRegs.CANBTC.all;
ECanbShadow.CANBTC.bit.BRPREG = 9;
/*150/10=15*/
ECanbShadow.CANBTC.bit.TSEG2REG = 2;
ECanbShadow.CANBTC.bit.TSEG1REG = 10;
ECanbRegs.CANBTC.all = ECanbShadow.CANBTC.all;

ECanbShadow.CANMC.all = ECanbRegs.CANMC.all;
ECanbShadow.CANMC.bit.STM = 0; //工作在正常模式
ECanbShadow.CANMC.bit.DBO = 1;
ECanbShadow.CANMC.bit.SCB = 1;
ECanbRegs.CANMC.all = ECanbShadow.CANMC.all;
do
{
// ECanbShadow.CANES.all = ECanbRegs.CANES.all;
ECanbShadow.CANES.bit.CCE = 0;
} while(ECanbShadow.CANES.bit.CCE != 0 ); // Wait for CCE bit to be cleared..

//初始化所有主设备控制区域为0,MCF所有的位都初始化为0
ECanbMboxes.MBOX0.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX1.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX2.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX3.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX4.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX5.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX6.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX7.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX8.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX9.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX10.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX11.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX12.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX13.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX14.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX15.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX16.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX17.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX18.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX19.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX20.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX21.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX22.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX23.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX24.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX25.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX26.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX27.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX28.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX29.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX30.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX31.MSGCTRL.all = 0x00000000;

// TAn, RMPn, GIFn bits are all zero upon reset and are cleared again
// as a matter of precaution.

ECanbShadow.CANTA.all = ECanbRegs.CANTA.all;
ECanbShadow.CANTA.all = 0xFFFFFFFF;
ECanbRegs.CANTA.all = ECanbShadow.CANTA.all;

ECanbShadow.CANRMP.all = ECanbRegs.CANRMP.all;
ECanbShadow.CANRMP.all = 0xFFFFFFFF;
ECanbRegs.CANRMP.all = ECanbShadow.CANRMP.all;

ECanbShadow.CANGIF0.all = ECanbRegs.CANGIF0.all;
ECanbShadow.CANGIF0.all = 0xFFFFFFFF;
ECanbRegs.CANGIF0.all = ECanbShadow.CANGIF0.all;

ECanbShadow.CANGIF1.all = ECanbRegs.CANGIF1.all;
ECanbShadow.CANGIF1.all = 0xFFFFFFFF;
ECanbRegs.CANGIF1.all = ECanbShadow.CANGIF1.all;

EALLOW;
/* Mailbox interrupt is disable*/
ECanbShadow.CANGIM.all = 0x00000000;
ECanbRegs.CANGIM.all = ECanbShadow.CANGIM.all;

ECanbShadow.CANMIM.all = 0x00000000;
ECanbRegs.CANMIM.all = ECanbShadow.CANMIM.all;

ECanbShadow.CANMIL.all = 0xFFFFFFFF;
ECanbRegs.CANMIL.all = ECanbShadow.CANMIL.all;
EDIS;

/* Set ECan mailboxs */
ECanbRegs.CANME.all = 0x00000000;

//The ID of sendmail
ECanbMboxes.MBOX0.MSGID.all = 0xCF00FFFF; //CF00FFFF 1100 1111 0000 0000 1111 1111 1111 1111
//The ID of receivemail
ECanbMboxes.MBOX16.MSGID.all = 0x80C20000;//CF02FFFF 1100 1111 0000 0010 1111 1111 1111 1111

/*数据长度为8byte*/
ECanbMboxes.MBOX0.MSGCTRL.bit.DLC = 8;
ECanbMboxes.MBOX16.MSGCTRL.bit.DLC = 8;

/*The mail0 is TX;The mail16 is RX*/
ECanbShadow.CANMD.all = ECanbRegs.CANMD.all;
ECanbShadow.CANMD.bit.MD0 =0;
ECanbShadow.CANMD.bit.MD16 =1;
ECanbRegs.CANMD.all = ECanbShadow.CANMD.all;

ECanbShadow.CANME.all = ECanbRegs.CANME.all;
ECanbShadow.CANME.all = 0x00010001; // Required before writing the MSGIDs 0000 0000 0000 0001 0000 0000 0000 0001
ECanbRegs.CANME.all = ECanbShadow.CANME.all;

// /*没有远方应答帧被请求*/
ECanbMboxes.MBOX16.MSGCTRL.bit.RTR = 0;

//邮箱屏蔽使能
ECanbRegs.CANMIM.all = 0xFFFFFFFF;
//邮箱中断将产生在ECAN0INT
ECanbRegs.CANMIL.all = 0;
ECanbRegs.CANGIF0.all = 0xFFFFFFFF;
//ECAN0INT中断请求被使能
ECanbRegs.CANGIM.bit.I0EN = 1;
EDIS;
}

jh chen:

信息量太少.不涉密的话可以把代码贴上来.

你使用什么方式制造数据?一共发送了几帧?几个邮箱接收.几个产生中断?

查看一下邮箱,看看是否有数据?核对配置的帧ID.

按照官方配置,配置完can接收,采用中断接收,debug时进不了中断。有没有遇到类似情况的?求解答。

void InitECan(void) // Initialize eCAN-B module
{
struct ECAN_REGS ECanbShadow;
EALLOW; // EALLOW enables access to protected bits
//配置GPIO工作在额eCAN功能
GpioCtrlRegs.GPAPUD.bit.GPIO16 = 1; // Disable pull-up for GPIO16 (CANTXB)
GpioCtrlRegs.GPAPUD.bit.GPIO17 = 0; // Enable pull-up for GPIO17 (CANRXB)
GpioCtrlRegs.GPAQSEL2.bit.GPIO17 = 3; // Asynch qual for GPIO17 (CANRXB)
GpioCtrlRegs.GPAMUX2.bit.GPIO16 = 2; // Configure GPIO16 for CANTXB operation
GpioCtrlRegs.GPAMUX2.bit.GPIO17 = 2; // Configure GPIO17 for CANRXB operation

//配置eCAN的RX和TX分别为eCAN的接收和发射引脚

ECanbShadow.CANTIOC.all = ECanbRegs.CANTIOC.all;

ECanbShadow.CANTIOC.bit.TXFUNC = 1;

ECanbRegs.CANTIOC.all = ECanbShadow.CANTIOC.all;

ECanbShadow.CANRIOC.all = ECanbRegs.CANRIOC.all;
ECanbShadow.CANRIOC.bit.RXFUNC = 1;
ECanbRegs.CANRIOC.all = ECanbShadow.CANRIOC.all;

/* Configure bit timing parameters for eCANB*/
ECanbShadow.CANMC.all = ECanbRegs.CANMC.all;
ECanbShadow.CANMC.bit.CCR = 1 ; // Set CCR = 1
ECanbRegs.CANMC.all = ECanbShadow.CANMC.all;

ECanbShadow.CANES.all = ECanbRegs.CANES.all;
do
{ECanbShadow.CANES.bit.CCE=ECanbRegs.CANES.bit.CCE;}
while(ECanbShadow.CANES.bit.CCE != 1 ) ; // Wait for CCE bit to be set..CCE等于1时跳出循环,则可以对CANBTC设置

//设置通信波特率
ECanbShadow.CANBTC.all = ECanbRegs.CANBTC.all;
ECanbShadow.CANBTC.bit.BRPREG = 9;
/*150/10=15*/
ECanbShadow.CANBTC.bit.TSEG2REG = 2;
ECanbShadow.CANBTC.bit.TSEG1REG = 10;
ECanbRegs.CANBTC.all = ECanbShadow.CANBTC.all;

ECanbShadow.CANMC.all = ECanbRegs.CANMC.all;
ECanbShadow.CANMC.bit.STM = 0; //工作在正常模式
ECanbShadow.CANMC.bit.DBO = 1;
ECanbShadow.CANMC.bit.SCB = 1;
ECanbRegs.CANMC.all = ECanbShadow.CANMC.all;
do
{
// ECanbShadow.CANES.all = ECanbRegs.CANES.all;
ECanbShadow.CANES.bit.CCE = 0;
} while(ECanbShadow.CANES.bit.CCE != 0 ); // Wait for CCE bit to be cleared..

//初始化所有主设备控制区域为0,MCF所有的位都初始化为0
ECanbMboxes.MBOX0.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX1.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX2.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX3.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX4.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX5.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX6.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX7.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX8.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX9.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX10.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX11.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX12.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX13.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX14.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX15.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX16.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX17.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX18.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX19.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX20.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX21.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX22.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX23.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX24.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX25.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX26.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX27.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX28.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX29.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX30.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX31.MSGCTRL.all = 0x00000000;

// TAn, RMPn, GIFn bits are all zero upon reset and are cleared again
// as a matter of precaution.

ECanbShadow.CANTA.all = ECanbRegs.CANTA.all;
ECanbShadow.CANTA.all = 0xFFFFFFFF;
ECanbRegs.CANTA.all = ECanbShadow.CANTA.all;

ECanbShadow.CANRMP.all = ECanbRegs.CANRMP.all;
ECanbShadow.CANRMP.all = 0xFFFFFFFF;
ECanbRegs.CANRMP.all = ECanbShadow.CANRMP.all;

ECanbShadow.CANGIF0.all = ECanbRegs.CANGIF0.all;
ECanbShadow.CANGIF0.all = 0xFFFFFFFF;
ECanbRegs.CANGIF0.all = ECanbShadow.CANGIF0.all;

ECanbShadow.CANGIF1.all = ECanbRegs.CANGIF1.all;
ECanbShadow.CANGIF1.all = 0xFFFFFFFF;
ECanbRegs.CANGIF1.all = ECanbShadow.CANGIF1.all;

EALLOW;
/* Mailbox interrupt is disable*/
ECanbShadow.CANGIM.all = 0x00000000;
ECanbRegs.CANGIM.all = ECanbShadow.CANGIM.all;

ECanbShadow.CANMIM.all = 0x00000000;
ECanbRegs.CANMIM.all = ECanbShadow.CANMIM.all;

ECanbShadow.CANMIL.all = 0xFFFFFFFF;
ECanbRegs.CANMIL.all = ECanbShadow.CANMIL.all;
EDIS;

/* Set ECan mailboxs */
ECanbRegs.CANME.all = 0x00000000;

//The ID of sendmail
ECanbMboxes.MBOX0.MSGID.all = 0xCF00FFFF; //CF00FFFF 1100 1111 0000 0000 1111 1111 1111 1111
//The ID of receivemail
ECanbMboxes.MBOX16.MSGID.all = 0x80C20000;//CF02FFFF 1100 1111 0000 0010 1111 1111 1111 1111

/*数据长度为8byte*/
ECanbMboxes.MBOX0.MSGCTRL.bit.DLC = 8;
ECanbMboxes.MBOX16.MSGCTRL.bit.DLC = 8;

/*The mail0 is TX;The mail16 is RX*/
ECanbShadow.CANMD.all = ECanbRegs.CANMD.all;
ECanbShadow.CANMD.bit.MD0 =0;
ECanbShadow.CANMD.bit.MD16 =1;
ECanbRegs.CANMD.all = ECanbShadow.CANMD.all;

ECanbShadow.CANME.all = ECanbRegs.CANME.all;
ECanbShadow.CANME.all = 0x00010001; // Required before writing the MSGIDs 0000 0000 0000 0001 0000 0000 0000 0001
ECanbRegs.CANME.all = ECanbShadow.CANME.all;

// /*没有远方应答帧被请求*/
ECanbMboxes.MBOX16.MSGCTRL.bit.RTR = 0;

//邮箱屏蔽使能
ECanbRegs.CANMIM.all = 0xFFFFFFFF;
//邮箱中断将产生在ECAN0INT
ECanbRegs.CANMIL.all = 0;
ECanbRegs.CANGIF0.all = 0xFFFFFFFF;
//ECAN0INT中断请求被使能
ECanbRegs.CANGIM.bit.I0EN = 1;
EDIS;
}

JT Niu:

回复 jh chen:

你好,我已经附上了我的配置代码,能帮忙看下吗?一个接收中断,采用can调试器发送或者控制器发送数据,一个邮箱接收Mbox16

按照官方配置,配置完can接收,采用中断接收,debug时进不了中断。有没有遇到类似情况的?求解答。

void InitECan(void) // Initialize eCAN-B module
{
struct ECAN_REGS ECanbShadow;
EALLOW; // EALLOW enables access to protected bits
//配置GPIO工作在额eCAN功能
GpioCtrlRegs.GPAPUD.bit.GPIO16 = 1; // Disable pull-up for GPIO16 (CANTXB)
GpioCtrlRegs.GPAPUD.bit.GPIO17 = 0; // Enable pull-up for GPIO17 (CANRXB)
GpioCtrlRegs.GPAQSEL2.bit.GPIO17 = 3; // Asynch qual for GPIO17 (CANRXB)
GpioCtrlRegs.GPAMUX2.bit.GPIO16 = 2; // Configure GPIO16 for CANTXB operation
GpioCtrlRegs.GPAMUX2.bit.GPIO17 = 2; // Configure GPIO17 for CANRXB operation

//配置eCAN的RX和TX分别为eCAN的接收和发射引脚

ECanbShadow.CANTIOC.all = ECanbRegs.CANTIOC.all;

ECanbShadow.CANTIOC.bit.TXFUNC = 1;

ECanbRegs.CANTIOC.all = ECanbShadow.CANTIOC.all;

ECanbShadow.CANRIOC.all = ECanbRegs.CANRIOC.all;
ECanbShadow.CANRIOC.bit.RXFUNC = 1;
ECanbRegs.CANRIOC.all = ECanbShadow.CANRIOC.all;

/* Configure bit timing parameters for eCANB*/
ECanbShadow.CANMC.all = ECanbRegs.CANMC.all;
ECanbShadow.CANMC.bit.CCR = 1 ; // Set CCR = 1
ECanbRegs.CANMC.all = ECanbShadow.CANMC.all;

ECanbShadow.CANES.all = ECanbRegs.CANES.all;
do
{ECanbShadow.CANES.bit.CCE=ECanbRegs.CANES.bit.CCE;}
while(ECanbShadow.CANES.bit.CCE != 1 ) ; // Wait for CCE bit to be set..CCE等于1时跳出循环,则可以对CANBTC设置

//设置通信波特率
ECanbShadow.CANBTC.all = ECanbRegs.CANBTC.all;
ECanbShadow.CANBTC.bit.BRPREG = 9;
/*150/10=15*/
ECanbShadow.CANBTC.bit.TSEG2REG = 2;
ECanbShadow.CANBTC.bit.TSEG1REG = 10;
ECanbRegs.CANBTC.all = ECanbShadow.CANBTC.all;

ECanbShadow.CANMC.all = ECanbRegs.CANMC.all;
ECanbShadow.CANMC.bit.STM = 0; //工作在正常模式
ECanbShadow.CANMC.bit.DBO = 1;
ECanbShadow.CANMC.bit.SCB = 1;
ECanbRegs.CANMC.all = ECanbShadow.CANMC.all;
do
{
// ECanbShadow.CANES.all = ECanbRegs.CANES.all;
ECanbShadow.CANES.bit.CCE = 0;
} while(ECanbShadow.CANES.bit.CCE != 0 ); // Wait for CCE bit to be cleared..

//初始化所有主设备控制区域为0,MCF所有的位都初始化为0
ECanbMboxes.MBOX0.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX1.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX2.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX3.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX4.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX5.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX6.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX7.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX8.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX9.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX10.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX11.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX12.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX13.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX14.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX15.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX16.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX17.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX18.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX19.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX20.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX21.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX22.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX23.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX24.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX25.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX26.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX27.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX28.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX29.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX30.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX31.MSGCTRL.all = 0x00000000;

// TAn, RMPn, GIFn bits are all zero upon reset and are cleared again
// as a matter of precaution.

ECanbShadow.CANTA.all = ECanbRegs.CANTA.all;
ECanbShadow.CANTA.all = 0xFFFFFFFF;
ECanbRegs.CANTA.all = ECanbShadow.CANTA.all;

ECanbShadow.CANRMP.all = ECanbRegs.CANRMP.all;
ECanbShadow.CANRMP.all = 0xFFFFFFFF;
ECanbRegs.CANRMP.all = ECanbShadow.CANRMP.all;

ECanbShadow.CANGIF0.all = ECanbRegs.CANGIF0.all;
ECanbShadow.CANGIF0.all = 0xFFFFFFFF;
ECanbRegs.CANGIF0.all = ECanbShadow.CANGIF0.all;

ECanbShadow.CANGIF1.all = ECanbRegs.CANGIF1.all;
ECanbShadow.CANGIF1.all = 0xFFFFFFFF;
ECanbRegs.CANGIF1.all = ECanbShadow.CANGIF1.all;

EALLOW;
/* Mailbox interrupt is disable*/
ECanbShadow.CANGIM.all = 0x00000000;
ECanbRegs.CANGIM.all = ECanbShadow.CANGIM.all;

ECanbShadow.CANMIM.all = 0x00000000;
ECanbRegs.CANMIM.all = ECanbShadow.CANMIM.all;

ECanbShadow.CANMIL.all = 0xFFFFFFFF;
ECanbRegs.CANMIL.all = ECanbShadow.CANMIL.all;
EDIS;

/* Set ECan mailboxs */
ECanbRegs.CANME.all = 0x00000000;

//The ID of sendmail
ECanbMboxes.MBOX0.MSGID.all = 0xCF00FFFF; //CF00FFFF 1100 1111 0000 0000 1111 1111 1111 1111
//The ID of receivemail
ECanbMboxes.MBOX16.MSGID.all = 0x80C20000;//CF02FFFF 1100 1111 0000 0010 1111 1111 1111 1111

/*数据长度为8byte*/
ECanbMboxes.MBOX0.MSGCTRL.bit.DLC = 8;
ECanbMboxes.MBOX16.MSGCTRL.bit.DLC = 8;

/*The mail0 is TX;The mail16 is RX*/
ECanbShadow.CANMD.all = ECanbRegs.CANMD.all;
ECanbShadow.CANMD.bit.MD0 =0;
ECanbShadow.CANMD.bit.MD16 =1;
ECanbRegs.CANMD.all = ECanbShadow.CANMD.all;

ECanbShadow.CANME.all = ECanbRegs.CANME.all;
ECanbShadow.CANME.all = 0x00010001; // Required before writing the MSGIDs 0000 0000 0000 0001 0000 0000 0000 0001
ECanbRegs.CANME.all = ECanbShadow.CANME.all;

// /*没有远方应答帧被请求*/
ECanbMboxes.MBOX16.MSGCTRL.bit.RTR = 0;

//邮箱屏蔽使能
ECanbRegs.CANMIM.all = 0xFFFFFFFF;
//邮箱中断将产生在ECAN0INT
ECanbRegs.CANMIL.all = 0;
ECanbRegs.CANGIF0.all = 0xFFFFFFFF;
//ECAN0INT中断请求被使能
ECanbRegs.CANGIM.bit.I0EN = 1;
EDIS;
}

jh chen:

回复 JT Niu:

EALLOW; // EALLOW enables access to protected bits//配置GPIO工作在额eCAN功能GpioCtrlRegs.GPAPUD.bit.GPIO16 = 1; // Disable pull-up for GPIO16 (CANTXB)GpioCtrlRegs.GPAPUD.bit.GPIO17 = 0; // Enable pull-up for GPIO17 (CANRXB)GpioCtrlRegs.GPAQSEL2.bit.GPIO17 = 3; // Asynch qual for GPIO17 (CANRXB)GpioCtrlRegs.GPAMUX2.bit.GPIO16 = 2; // Configure GPIO16 for CANTXB operationGpioCtrlRegs.GPAMUX2.bit.GPIO17 = 2; // Configure GPIO17 for CANRXB operation

EDIS;//这里请加上一个EDIS

中断函数是如何编写的呢?

按照官方配置,配置完can接收,采用中断接收,debug时进不了中断。有没有遇到类似情况的?求解答。

void InitECan(void) // Initialize eCAN-B module
{
struct ECAN_REGS ECanbShadow;
EALLOW; // EALLOW enables access to protected bits
//配置GPIO工作在额eCAN功能
GpioCtrlRegs.GPAPUD.bit.GPIO16 = 1; // Disable pull-up for GPIO16 (CANTXB)
GpioCtrlRegs.GPAPUD.bit.GPIO17 = 0; // Enable pull-up for GPIO17 (CANRXB)
GpioCtrlRegs.GPAQSEL2.bit.GPIO17 = 3; // Asynch qual for GPIO17 (CANRXB)
GpioCtrlRegs.GPAMUX2.bit.GPIO16 = 2; // Configure GPIO16 for CANTXB operation
GpioCtrlRegs.GPAMUX2.bit.GPIO17 = 2; // Configure GPIO17 for CANRXB operation

//配置eCAN的RX和TX分别为eCAN的接收和发射引脚

ECanbShadow.CANTIOC.all = ECanbRegs.CANTIOC.all;

ECanbShadow.CANTIOC.bit.TXFUNC = 1;

ECanbRegs.CANTIOC.all = ECanbShadow.CANTIOC.all;

ECanbShadow.CANRIOC.all = ECanbRegs.CANRIOC.all;
ECanbShadow.CANRIOC.bit.RXFUNC = 1;
ECanbRegs.CANRIOC.all = ECanbShadow.CANRIOC.all;

/* Configure bit timing parameters for eCANB*/
ECanbShadow.CANMC.all = ECanbRegs.CANMC.all;
ECanbShadow.CANMC.bit.CCR = 1 ; // Set CCR = 1
ECanbRegs.CANMC.all = ECanbShadow.CANMC.all;

ECanbShadow.CANES.all = ECanbRegs.CANES.all;
do
{ECanbShadow.CANES.bit.CCE=ECanbRegs.CANES.bit.CCE;}
while(ECanbShadow.CANES.bit.CCE != 1 ) ; // Wait for CCE bit to be set..CCE等于1时跳出循环,则可以对CANBTC设置

//设置通信波特率
ECanbShadow.CANBTC.all = ECanbRegs.CANBTC.all;
ECanbShadow.CANBTC.bit.BRPREG = 9;
/*150/10=15*/
ECanbShadow.CANBTC.bit.TSEG2REG = 2;
ECanbShadow.CANBTC.bit.TSEG1REG = 10;
ECanbRegs.CANBTC.all = ECanbShadow.CANBTC.all;

ECanbShadow.CANMC.all = ECanbRegs.CANMC.all;
ECanbShadow.CANMC.bit.STM = 0; //工作在正常模式
ECanbShadow.CANMC.bit.DBO = 1;
ECanbShadow.CANMC.bit.SCB = 1;
ECanbRegs.CANMC.all = ECanbShadow.CANMC.all;
do
{
// ECanbShadow.CANES.all = ECanbRegs.CANES.all;
ECanbShadow.CANES.bit.CCE = 0;
} while(ECanbShadow.CANES.bit.CCE != 0 ); // Wait for CCE bit to be cleared..

//初始化所有主设备控制区域为0,MCF所有的位都初始化为0
ECanbMboxes.MBOX0.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX1.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX2.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX3.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX4.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX5.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX6.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX7.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX8.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX9.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX10.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX11.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX12.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX13.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX14.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX15.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX16.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX17.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX18.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX19.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX20.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX21.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX22.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX23.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX24.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX25.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX26.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX27.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX28.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX29.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX30.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX31.MSGCTRL.all = 0x00000000;

// TAn, RMPn, GIFn bits are all zero upon reset and are cleared again
// as a matter of precaution.

ECanbShadow.CANTA.all = ECanbRegs.CANTA.all;
ECanbShadow.CANTA.all = 0xFFFFFFFF;
ECanbRegs.CANTA.all = ECanbShadow.CANTA.all;

ECanbShadow.CANRMP.all = ECanbRegs.CANRMP.all;
ECanbShadow.CANRMP.all = 0xFFFFFFFF;
ECanbRegs.CANRMP.all = ECanbShadow.CANRMP.all;

ECanbShadow.CANGIF0.all = ECanbRegs.CANGIF0.all;
ECanbShadow.CANGIF0.all = 0xFFFFFFFF;
ECanbRegs.CANGIF0.all = ECanbShadow.CANGIF0.all;

ECanbShadow.CANGIF1.all = ECanbRegs.CANGIF1.all;
ECanbShadow.CANGIF1.all = 0xFFFFFFFF;
ECanbRegs.CANGIF1.all = ECanbShadow.CANGIF1.all;

EALLOW;
/* Mailbox interrupt is disable*/
ECanbShadow.CANGIM.all = 0x00000000;
ECanbRegs.CANGIM.all = ECanbShadow.CANGIM.all;

ECanbShadow.CANMIM.all = 0x00000000;
ECanbRegs.CANMIM.all = ECanbShadow.CANMIM.all;

ECanbShadow.CANMIL.all = 0xFFFFFFFF;
ECanbRegs.CANMIL.all = ECanbShadow.CANMIL.all;
EDIS;

/* Set ECan mailboxs */
ECanbRegs.CANME.all = 0x00000000;

//The ID of sendmail
ECanbMboxes.MBOX0.MSGID.all = 0xCF00FFFF; //CF00FFFF 1100 1111 0000 0000 1111 1111 1111 1111
//The ID of receivemail
ECanbMboxes.MBOX16.MSGID.all = 0x80C20000;//CF02FFFF 1100 1111 0000 0010 1111 1111 1111 1111

/*数据长度为8byte*/
ECanbMboxes.MBOX0.MSGCTRL.bit.DLC = 8;
ECanbMboxes.MBOX16.MSGCTRL.bit.DLC = 8;

/*The mail0 is TX;The mail16 is RX*/
ECanbShadow.CANMD.all = ECanbRegs.CANMD.all;
ECanbShadow.CANMD.bit.MD0 =0;
ECanbShadow.CANMD.bit.MD16 =1;
ECanbRegs.CANMD.all = ECanbShadow.CANMD.all;

ECanbShadow.CANME.all = ECanbRegs.CANME.all;
ECanbShadow.CANME.all = 0x00010001; // Required before writing the MSGIDs 0000 0000 0000 0001 0000 0000 0000 0001
ECanbRegs.CANME.all = ECanbShadow.CANME.all;

// /*没有远方应答帧被请求*/
ECanbMboxes.MBOX16.MSGCTRL.bit.RTR = 0;

//邮箱屏蔽使能
ECanbRegs.CANMIM.all = 0xFFFFFFFF;
//邮箱中断将产生在ECAN0INT
ECanbRegs.CANMIL.all = 0;
ECanbRegs.CANGIF0.all = 0xFFFFFFFF;
//ECAN0INT中断请求被使能
ECanbRegs.CANGIM.bit.I0EN = 1;
EDIS;
}

JT Niu:

回复 jh chen:

//这是中断函数 INT9.7interrupt void ECAN0INTB_ISR(void) // eCAN-B{ // Insert ISR Code here while (ECanbRegs.CANRMP.all != 0x00010000); ECanbRegs.CANRMP.all = 0x00010000;//复位RMP标志,同时也复位中断标志

if(ECanbRegs.CANRMP.all != 0x00010000) { ECanbRegs.CANRMP.all = 0x00010000; //复位RMP标志,同时也复位中断标志 } Rec_l = ECanbMboxes.MBOX16.MDL.all; //收到的数据在接收邮箱Mbox16 Rec_h = ECanbMboxes.MBOX16.MDH.all; PieCtrlRegs.PIEACK.bit.ACK9 = 1; EINT;

}

//这是main函数

int main(void){

InitSysCtrl(); //初始化系统和时钟基本模块,PLL, WatchDog, enable Peripheral Clocks asm(" RPT #8 || NOP"); //表示延迟8+1个系统时钟周期,汇编指令

DINT;

InitGpio();

InitPieCtrl(); IER = 0x0000; IFR = 0x0000; InitPieVectTable(); InitECan();

asm(" RPT #8 || NOP");

// //使能PIE中断 PieCtrlRegs.PIECTRL.bit.ENPIE = 1; // Enable the PIE PieCtrlRegs.PIEIER9.bit.INTx7 = 1;

EALLOW; PieVectTable.ECAN0INTB = & ECAN0INTB_ISR;

EDIS; //使能CPU中断

IER |= M_INT9;

EINT; //开全局中断 ERTM; //开实时中断

while(1) {}

}

按照官方配置,配置完can接收,采用中断接收,debug时进不了中断。有没有遇到类似情况的?求解答。

void InitECan(void) // Initialize eCAN-B module
{
struct ECAN_REGS ECanbShadow;
EALLOW; // EALLOW enables access to protected bits
//配置GPIO工作在额eCAN功能
GpioCtrlRegs.GPAPUD.bit.GPIO16 = 1; // Disable pull-up for GPIO16 (CANTXB)
GpioCtrlRegs.GPAPUD.bit.GPIO17 = 0; // Enable pull-up for GPIO17 (CANRXB)
GpioCtrlRegs.GPAQSEL2.bit.GPIO17 = 3; // Asynch qual for GPIO17 (CANRXB)
GpioCtrlRegs.GPAMUX2.bit.GPIO16 = 2; // Configure GPIO16 for CANTXB operation
GpioCtrlRegs.GPAMUX2.bit.GPIO17 = 2; // Configure GPIO17 for CANRXB operation

//配置eCAN的RX和TX分别为eCAN的接收和发射引脚

ECanbShadow.CANTIOC.all = ECanbRegs.CANTIOC.all;

ECanbShadow.CANTIOC.bit.TXFUNC = 1;

ECanbRegs.CANTIOC.all = ECanbShadow.CANTIOC.all;

ECanbShadow.CANRIOC.all = ECanbRegs.CANRIOC.all;
ECanbShadow.CANRIOC.bit.RXFUNC = 1;
ECanbRegs.CANRIOC.all = ECanbShadow.CANRIOC.all;

/* Configure bit timing parameters for eCANB*/
ECanbShadow.CANMC.all = ECanbRegs.CANMC.all;
ECanbShadow.CANMC.bit.CCR = 1 ; // Set CCR = 1
ECanbRegs.CANMC.all = ECanbShadow.CANMC.all;

ECanbShadow.CANES.all = ECanbRegs.CANES.all;
do
{ECanbShadow.CANES.bit.CCE=ECanbRegs.CANES.bit.CCE;}
while(ECanbShadow.CANES.bit.CCE != 1 ) ; // Wait for CCE bit to be set..CCE等于1时跳出循环,则可以对CANBTC设置

//设置通信波特率
ECanbShadow.CANBTC.all = ECanbRegs.CANBTC.all;
ECanbShadow.CANBTC.bit.BRPREG = 9;
/*150/10=15*/
ECanbShadow.CANBTC.bit.TSEG2REG = 2;
ECanbShadow.CANBTC.bit.TSEG1REG = 10;
ECanbRegs.CANBTC.all = ECanbShadow.CANBTC.all;

ECanbShadow.CANMC.all = ECanbRegs.CANMC.all;
ECanbShadow.CANMC.bit.STM = 0; //工作在正常模式
ECanbShadow.CANMC.bit.DBO = 1;
ECanbShadow.CANMC.bit.SCB = 1;
ECanbRegs.CANMC.all = ECanbShadow.CANMC.all;
do
{
// ECanbShadow.CANES.all = ECanbRegs.CANES.all;
ECanbShadow.CANES.bit.CCE = 0;
} while(ECanbShadow.CANES.bit.CCE != 0 ); // Wait for CCE bit to be cleared..

//初始化所有主设备控制区域为0,MCF所有的位都初始化为0
ECanbMboxes.MBOX0.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX1.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX2.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX3.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX4.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX5.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX6.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX7.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX8.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX9.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX10.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX11.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX12.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX13.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX14.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX15.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX16.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX17.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX18.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX19.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX20.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX21.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX22.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX23.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX24.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX25.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX26.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX27.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX28.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX29.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX30.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX31.MSGCTRL.all = 0x00000000;

// TAn, RMPn, GIFn bits are all zero upon reset and are cleared again
// as a matter of precaution.

ECanbShadow.CANTA.all = ECanbRegs.CANTA.all;
ECanbShadow.CANTA.all = 0xFFFFFFFF;
ECanbRegs.CANTA.all = ECanbShadow.CANTA.all;

ECanbShadow.CANRMP.all = ECanbRegs.CANRMP.all;
ECanbShadow.CANRMP.all = 0xFFFFFFFF;
ECanbRegs.CANRMP.all = ECanbShadow.CANRMP.all;

ECanbShadow.CANGIF0.all = ECanbRegs.CANGIF0.all;
ECanbShadow.CANGIF0.all = 0xFFFFFFFF;
ECanbRegs.CANGIF0.all = ECanbShadow.CANGIF0.all;

ECanbShadow.CANGIF1.all = ECanbRegs.CANGIF1.all;
ECanbShadow.CANGIF1.all = 0xFFFFFFFF;
ECanbRegs.CANGIF1.all = ECanbShadow.CANGIF1.all;

EALLOW;
/* Mailbox interrupt is disable*/
ECanbShadow.CANGIM.all = 0x00000000;
ECanbRegs.CANGIM.all = ECanbShadow.CANGIM.all;

ECanbShadow.CANMIM.all = 0x00000000;
ECanbRegs.CANMIM.all = ECanbShadow.CANMIM.all;

ECanbShadow.CANMIL.all = 0xFFFFFFFF;
ECanbRegs.CANMIL.all = ECanbShadow.CANMIL.all;
EDIS;

/* Set ECan mailboxs */
ECanbRegs.CANME.all = 0x00000000;

//The ID of sendmail
ECanbMboxes.MBOX0.MSGID.all = 0xCF00FFFF; //CF00FFFF 1100 1111 0000 0000 1111 1111 1111 1111
//The ID of receivemail
ECanbMboxes.MBOX16.MSGID.all = 0x80C20000;//CF02FFFF 1100 1111 0000 0010 1111 1111 1111 1111

/*数据长度为8byte*/
ECanbMboxes.MBOX0.MSGCTRL.bit.DLC = 8;
ECanbMboxes.MBOX16.MSGCTRL.bit.DLC = 8;

/*The mail0 is TX;The mail16 is RX*/
ECanbShadow.CANMD.all = ECanbRegs.CANMD.all;
ECanbShadow.CANMD.bit.MD0 =0;
ECanbShadow.CANMD.bit.MD16 =1;
ECanbRegs.CANMD.all = ECanbShadow.CANMD.all;

ECanbShadow.CANME.all = ECanbRegs.CANME.all;
ECanbShadow.CANME.all = 0x00010001; // Required before writing the MSGIDs 0000 0000 0000 0001 0000 0000 0000 0001
ECanbRegs.CANME.all = ECanbShadow.CANME.all;

// /*没有远方应答帧被请求*/
ECanbMboxes.MBOX16.MSGCTRL.bit.RTR = 0;

//邮箱屏蔽使能
ECanbRegs.CANMIM.all = 0xFFFFFFFF;
//邮箱中断将产生在ECAN0INT
ECanbRegs.CANMIL.all = 0;
ECanbRegs.CANGIF0.all = 0xFFFFFFFF;
//ECAN0INT中断请求被使能
ECanbRegs.CANGIM.bit.I0EN = 1;
EDIS;
}

Gaofeng li:

回复 JT Niu:

检查下DSP2833x_SysCtrl.c文件中,中断时能时钟有没有使能?

按照官方配置,配置完can接收,采用中断接收,debug时进不了中断。有没有遇到类似情况的?求解答。

void InitECan(void) // Initialize eCAN-B module
{
struct ECAN_REGS ECanbShadow;
EALLOW; // EALLOW enables access to protected bits
//配置GPIO工作在额eCAN功能
GpioCtrlRegs.GPAPUD.bit.GPIO16 = 1; // Disable pull-up for GPIO16 (CANTXB)
GpioCtrlRegs.GPAPUD.bit.GPIO17 = 0; // Enable pull-up for GPIO17 (CANRXB)
GpioCtrlRegs.GPAQSEL2.bit.GPIO17 = 3; // Asynch qual for GPIO17 (CANRXB)
GpioCtrlRegs.GPAMUX2.bit.GPIO16 = 2; // Configure GPIO16 for CANTXB operation
GpioCtrlRegs.GPAMUX2.bit.GPIO17 = 2; // Configure GPIO17 for CANRXB operation

//配置eCAN的RX和TX分别为eCAN的接收和发射引脚

ECanbShadow.CANTIOC.all = ECanbRegs.CANTIOC.all;

ECanbShadow.CANTIOC.bit.TXFUNC = 1;

ECanbRegs.CANTIOC.all = ECanbShadow.CANTIOC.all;

ECanbShadow.CANRIOC.all = ECanbRegs.CANRIOC.all;
ECanbShadow.CANRIOC.bit.RXFUNC = 1;
ECanbRegs.CANRIOC.all = ECanbShadow.CANRIOC.all;

/* Configure bit timing parameters for eCANB*/
ECanbShadow.CANMC.all = ECanbRegs.CANMC.all;
ECanbShadow.CANMC.bit.CCR = 1 ; // Set CCR = 1
ECanbRegs.CANMC.all = ECanbShadow.CANMC.all;

ECanbShadow.CANES.all = ECanbRegs.CANES.all;
do
{ECanbShadow.CANES.bit.CCE=ECanbRegs.CANES.bit.CCE;}
while(ECanbShadow.CANES.bit.CCE != 1 ) ; // Wait for CCE bit to be set..CCE等于1时跳出循环,则可以对CANBTC设置

//设置通信波特率
ECanbShadow.CANBTC.all = ECanbRegs.CANBTC.all;
ECanbShadow.CANBTC.bit.BRPREG = 9;
/*150/10=15*/
ECanbShadow.CANBTC.bit.TSEG2REG = 2;
ECanbShadow.CANBTC.bit.TSEG1REG = 10;
ECanbRegs.CANBTC.all = ECanbShadow.CANBTC.all;

ECanbShadow.CANMC.all = ECanbRegs.CANMC.all;
ECanbShadow.CANMC.bit.STM = 0; //工作在正常模式
ECanbShadow.CANMC.bit.DBO = 1;
ECanbShadow.CANMC.bit.SCB = 1;
ECanbRegs.CANMC.all = ECanbShadow.CANMC.all;
do
{
// ECanbShadow.CANES.all = ECanbRegs.CANES.all;
ECanbShadow.CANES.bit.CCE = 0;
} while(ECanbShadow.CANES.bit.CCE != 0 ); // Wait for CCE bit to be cleared..

//初始化所有主设备控制区域为0,MCF所有的位都初始化为0
ECanbMboxes.MBOX0.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX1.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX2.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX3.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX4.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX5.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX6.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX7.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX8.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX9.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX10.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX11.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX12.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX13.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX14.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX15.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX16.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX17.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX18.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX19.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX20.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX21.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX22.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX23.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX24.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX25.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX26.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX27.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX28.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX29.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX30.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX31.MSGCTRL.all = 0x00000000;

// TAn, RMPn, GIFn bits are all zero upon reset and are cleared again
// as a matter of precaution.

ECanbShadow.CANTA.all = ECanbRegs.CANTA.all;
ECanbShadow.CANTA.all = 0xFFFFFFFF;
ECanbRegs.CANTA.all = ECanbShadow.CANTA.all;

ECanbShadow.CANRMP.all = ECanbRegs.CANRMP.all;
ECanbShadow.CANRMP.all = 0xFFFFFFFF;
ECanbRegs.CANRMP.all = ECanbShadow.CANRMP.all;

ECanbShadow.CANGIF0.all = ECanbRegs.CANGIF0.all;
ECanbShadow.CANGIF0.all = 0xFFFFFFFF;
ECanbRegs.CANGIF0.all = ECanbShadow.CANGIF0.all;

ECanbShadow.CANGIF1.all = ECanbRegs.CANGIF1.all;
ECanbShadow.CANGIF1.all = 0xFFFFFFFF;
ECanbRegs.CANGIF1.all = ECanbShadow.CANGIF1.all;

EALLOW;
/* Mailbox interrupt is disable*/
ECanbShadow.CANGIM.all = 0x00000000;
ECanbRegs.CANGIM.all = ECanbShadow.CANGIM.all;

ECanbShadow.CANMIM.all = 0x00000000;
ECanbRegs.CANMIM.all = ECanbShadow.CANMIM.all;

ECanbShadow.CANMIL.all = 0xFFFFFFFF;
ECanbRegs.CANMIL.all = ECanbShadow.CANMIL.all;
EDIS;

/* Set ECan mailboxs */
ECanbRegs.CANME.all = 0x00000000;

//The ID of sendmail
ECanbMboxes.MBOX0.MSGID.all = 0xCF00FFFF; //CF00FFFF 1100 1111 0000 0000 1111 1111 1111 1111
//The ID of receivemail
ECanbMboxes.MBOX16.MSGID.all = 0x80C20000;//CF02FFFF 1100 1111 0000 0010 1111 1111 1111 1111

/*数据长度为8byte*/
ECanbMboxes.MBOX0.MSGCTRL.bit.DLC = 8;
ECanbMboxes.MBOX16.MSGCTRL.bit.DLC = 8;

/*The mail0 is TX;The mail16 is RX*/
ECanbShadow.CANMD.all = ECanbRegs.CANMD.all;
ECanbShadow.CANMD.bit.MD0 =0;
ECanbShadow.CANMD.bit.MD16 =1;
ECanbRegs.CANMD.all = ECanbShadow.CANMD.all;

ECanbShadow.CANME.all = ECanbRegs.CANME.all;
ECanbShadow.CANME.all = 0x00010001; // Required before writing the MSGIDs 0000 0000 0000 0001 0000 0000 0000 0001
ECanbRegs.CANME.all = ECanbShadow.CANME.all;

// /*没有远方应答帧被请求*/
ECanbMboxes.MBOX16.MSGCTRL.bit.RTR = 0;

//邮箱屏蔽使能
ECanbRegs.CANMIM.all = 0xFFFFFFFF;
//邮箱中断将产生在ECAN0INT
ECanbRegs.CANMIL.all = 0;
ECanbRegs.CANGIF0.all = 0xFFFFFFFF;
//ECAN0INT中断请求被使能
ECanbRegs.CANGIM.bit.I0EN = 1;
EDIS;
}

JT Niu:

回复 Gaofeng li:

恩,检查过了,使能了。

按照官方配置,配置完can接收,采用中断接收,debug时进不了中断。有没有遇到类似情况的?求解答。

void InitECan(void) // Initialize eCAN-B module
{
struct ECAN_REGS ECanbShadow;
EALLOW; // EALLOW enables access to protected bits
//配置GPIO工作在额eCAN功能
GpioCtrlRegs.GPAPUD.bit.GPIO16 = 1; // Disable pull-up for GPIO16 (CANTXB)
GpioCtrlRegs.GPAPUD.bit.GPIO17 = 0; // Enable pull-up for GPIO17 (CANRXB)
GpioCtrlRegs.GPAQSEL2.bit.GPIO17 = 3; // Asynch qual for GPIO17 (CANRXB)
GpioCtrlRegs.GPAMUX2.bit.GPIO16 = 2; // Configure GPIO16 for CANTXB operation
GpioCtrlRegs.GPAMUX2.bit.GPIO17 = 2; // Configure GPIO17 for CANRXB operation

//配置eCAN的RX和TX分别为eCAN的接收和发射引脚

ECanbShadow.CANTIOC.all = ECanbRegs.CANTIOC.all;

ECanbShadow.CANTIOC.bit.TXFUNC = 1;

ECanbRegs.CANTIOC.all = ECanbShadow.CANTIOC.all;

ECanbShadow.CANRIOC.all = ECanbRegs.CANRIOC.all;
ECanbShadow.CANRIOC.bit.RXFUNC = 1;
ECanbRegs.CANRIOC.all = ECanbShadow.CANRIOC.all;

/* Configure bit timing parameters for eCANB*/
ECanbShadow.CANMC.all = ECanbRegs.CANMC.all;
ECanbShadow.CANMC.bit.CCR = 1 ; // Set CCR = 1
ECanbRegs.CANMC.all = ECanbShadow.CANMC.all;

ECanbShadow.CANES.all = ECanbRegs.CANES.all;
do
{ECanbShadow.CANES.bit.CCE=ECanbRegs.CANES.bit.CCE;}
while(ECanbShadow.CANES.bit.CCE != 1 ) ; // Wait for CCE bit to be set..CCE等于1时跳出循环,则可以对CANBTC设置

//设置通信波特率
ECanbShadow.CANBTC.all = ECanbRegs.CANBTC.all;
ECanbShadow.CANBTC.bit.BRPREG = 9;
/*150/10=15*/
ECanbShadow.CANBTC.bit.TSEG2REG = 2;
ECanbShadow.CANBTC.bit.TSEG1REG = 10;
ECanbRegs.CANBTC.all = ECanbShadow.CANBTC.all;

ECanbShadow.CANMC.all = ECanbRegs.CANMC.all;
ECanbShadow.CANMC.bit.STM = 0; //工作在正常模式
ECanbShadow.CANMC.bit.DBO = 1;
ECanbShadow.CANMC.bit.SCB = 1;
ECanbRegs.CANMC.all = ECanbShadow.CANMC.all;
do
{
// ECanbShadow.CANES.all = ECanbRegs.CANES.all;
ECanbShadow.CANES.bit.CCE = 0;
} while(ECanbShadow.CANES.bit.CCE != 0 ); // Wait for CCE bit to be cleared..

//初始化所有主设备控制区域为0,MCF所有的位都初始化为0
ECanbMboxes.MBOX0.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX1.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX2.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX3.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX4.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX5.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX6.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX7.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX8.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX9.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX10.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX11.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX12.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX13.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX14.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX15.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX16.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX17.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX18.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX19.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX20.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX21.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX22.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX23.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX24.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX25.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX26.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX27.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX28.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX29.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX30.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX31.MSGCTRL.all = 0x00000000;

// TAn, RMPn, GIFn bits are all zero upon reset and are cleared again
// as a matter of precaution.

ECanbShadow.CANTA.all = ECanbRegs.CANTA.all;
ECanbShadow.CANTA.all = 0xFFFFFFFF;
ECanbRegs.CANTA.all = ECanbShadow.CANTA.all;

ECanbShadow.CANRMP.all = ECanbRegs.CANRMP.all;
ECanbShadow.CANRMP.all = 0xFFFFFFFF;
ECanbRegs.CANRMP.all = ECanbShadow.CANRMP.all;

ECanbShadow.CANGIF0.all = ECanbRegs.CANGIF0.all;
ECanbShadow.CANGIF0.all = 0xFFFFFFFF;
ECanbRegs.CANGIF0.all = ECanbShadow.CANGIF0.all;

ECanbShadow.CANGIF1.all = ECanbRegs.CANGIF1.all;
ECanbShadow.CANGIF1.all = 0xFFFFFFFF;
ECanbRegs.CANGIF1.all = ECanbShadow.CANGIF1.all;

EALLOW;
/* Mailbox interrupt is disable*/
ECanbShadow.CANGIM.all = 0x00000000;
ECanbRegs.CANGIM.all = ECanbShadow.CANGIM.all;

ECanbShadow.CANMIM.all = 0x00000000;
ECanbRegs.CANMIM.all = ECanbShadow.CANMIM.all;

ECanbShadow.CANMIL.all = 0xFFFFFFFF;
ECanbRegs.CANMIL.all = ECanbShadow.CANMIL.all;
EDIS;

/* Set ECan mailboxs */
ECanbRegs.CANME.all = 0x00000000;

//The ID of sendmail
ECanbMboxes.MBOX0.MSGID.all = 0xCF00FFFF; //CF00FFFF 1100 1111 0000 0000 1111 1111 1111 1111
//The ID of receivemail
ECanbMboxes.MBOX16.MSGID.all = 0x80C20000;//CF02FFFF 1100 1111 0000 0010 1111 1111 1111 1111

/*数据长度为8byte*/
ECanbMboxes.MBOX0.MSGCTRL.bit.DLC = 8;
ECanbMboxes.MBOX16.MSGCTRL.bit.DLC = 8;

/*The mail0 is TX;The mail16 is RX*/
ECanbShadow.CANMD.all = ECanbRegs.CANMD.all;
ECanbShadow.CANMD.bit.MD0 =0;
ECanbShadow.CANMD.bit.MD16 =1;
ECanbRegs.CANMD.all = ECanbShadow.CANMD.all;

ECanbShadow.CANME.all = ECanbRegs.CANME.all;
ECanbShadow.CANME.all = 0x00010001; // Required before writing the MSGIDs 0000 0000 0000 0001 0000 0000 0000 0001
ECanbRegs.CANME.all = ECanbShadow.CANME.all;

// /*没有远方应答帧被请求*/
ECanbMboxes.MBOX16.MSGCTRL.bit.RTR = 0;

//邮箱屏蔽使能
ECanbRegs.CANMIM.all = 0xFFFFFFFF;
//邮箱中断将产生在ECAN0INT
ECanbRegs.CANMIL.all = 0;
ECanbRegs.CANGIF0.all = 0xFFFFFFFF;
//ECAN0INT中断请求被使能
ECanbRegs.CANGIM.bit.I0EN = 1;
EDIS;
}

JT Niu:

再问下论坛大神,can模块接收时,如何通过观察寄存器,判断接收邮箱确实接收到了数据啊?

按照官方配置,配置完can接收,采用中断接收,debug时进不了中断。有没有遇到类似情况的?求解答。

void InitECan(void) // Initialize eCAN-B module
{
struct ECAN_REGS ECanbShadow;
EALLOW; // EALLOW enables access to protected bits
//配置GPIO工作在额eCAN功能
GpioCtrlRegs.GPAPUD.bit.GPIO16 = 1; // Disable pull-up for GPIO16 (CANTXB)
GpioCtrlRegs.GPAPUD.bit.GPIO17 = 0; // Enable pull-up for GPIO17 (CANRXB)
GpioCtrlRegs.GPAQSEL2.bit.GPIO17 = 3; // Asynch qual for GPIO17 (CANRXB)
GpioCtrlRegs.GPAMUX2.bit.GPIO16 = 2; // Configure GPIO16 for CANTXB operation
GpioCtrlRegs.GPAMUX2.bit.GPIO17 = 2; // Configure GPIO17 for CANRXB operation

//配置eCAN的RX和TX分别为eCAN的接收和发射引脚

ECanbShadow.CANTIOC.all = ECanbRegs.CANTIOC.all;

ECanbShadow.CANTIOC.bit.TXFUNC = 1;

ECanbRegs.CANTIOC.all = ECanbShadow.CANTIOC.all;

ECanbShadow.CANRIOC.all = ECanbRegs.CANRIOC.all;
ECanbShadow.CANRIOC.bit.RXFUNC = 1;
ECanbRegs.CANRIOC.all = ECanbShadow.CANRIOC.all;

/* Configure bit timing parameters for eCANB*/
ECanbShadow.CANMC.all = ECanbRegs.CANMC.all;
ECanbShadow.CANMC.bit.CCR = 1 ; // Set CCR = 1
ECanbRegs.CANMC.all = ECanbShadow.CANMC.all;

ECanbShadow.CANES.all = ECanbRegs.CANES.all;
do
{ECanbShadow.CANES.bit.CCE=ECanbRegs.CANES.bit.CCE;}
while(ECanbShadow.CANES.bit.CCE != 1 ) ; // Wait for CCE bit to be set..CCE等于1时跳出循环,则可以对CANBTC设置

//设置通信波特率
ECanbShadow.CANBTC.all = ECanbRegs.CANBTC.all;
ECanbShadow.CANBTC.bit.BRPREG = 9;
/*150/10=15*/
ECanbShadow.CANBTC.bit.TSEG2REG = 2;
ECanbShadow.CANBTC.bit.TSEG1REG = 10;
ECanbRegs.CANBTC.all = ECanbShadow.CANBTC.all;

ECanbShadow.CANMC.all = ECanbRegs.CANMC.all;
ECanbShadow.CANMC.bit.STM = 0; //工作在正常模式
ECanbShadow.CANMC.bit.DBO = 1;
ECanbShadow.CANMC.bit.SCB = 1;
ECanbRegs.CANMC.all = ECanbShadow.CANMC.all;
do
{
// ECanbShadow.CANES.all = ECanbRegs.CANES.all;
ECanbShadow.CANES.bit.CCE = 0;
} while(ECanbShadow.CANES.bit.CCE != 0 ); // Wait for CCE bit to be cleared..

//初始化所有主设备控制区域为0,MCF所有的位都初始化为0
ECanbMboxes.MBOX0.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX1.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX2.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX3.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX4.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX5.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX6.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX7.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX8.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX9.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX10.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX11.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX12.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX13.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX14.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX15.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX16.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX17.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX18.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX19.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX20.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX21.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX22.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX23.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX24.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX25.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX26.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX27.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX28.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX29.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX30.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX31.MSGCTRL.all = 0x00000000;

// TAn, RMPn, GIFn bits are all zero upon reset and are cleared again
// as a matter of precaution.

ECanbShadow.CANTA.all = ECanbRegs.CANTA.all;
ECanbShadow.CANTA.all = 0xFFFFFFFF;
ECanbRegs.CANTA.all = ECanbShadow.CANTA.all;

ECanbShadow.CANRMP.all = ECanbRegs.CANRMP.all;
ECanbShadow.CANRMP.all = 0xFFFFFFFF;
ECanbRegs.CANRMP.all = ECanbShadow.CANRMP.all;

ECanbShadow.CANGIF0.all = ECanbRegs.CANGIF0.all;
ECanbShadow.CANGIF0.all = 0xFFFFFFFF;
ECanbRegs.CANGIF0.all = ECanbShadow.CANGIF0.all;

ECanbShadow.CANGIF1.all = ECanbRegs.CANGIF1.all;
ECanbShadow.CANGIF1.all = 0xFFFFFFFF;
ECanbRegs.CANGIF1.all = ECanbShadow.CANGIF1.all;

EALLOW;
/* Mailbox interrupt is disable*/
ECanbShadow.CANGIM.all = 0x00000000;
ECanbRegs.CANGIM.all = ECanbShadow.CANGIM.all;

ECanbShadow.CANMIM.all = 0x00000000;
ECanbRegs.CANMIM.all = ECanbShadow.CANMIM.all;

ECanbShadow.CANMIL.all = 0xFFFFFFFF;
ECanbRegs.CANMIL.all = ECanbShadow.CANMIL.all;
EDIS;

/* Set ECan mailboxs */
ECanbRegs.CANME.all = 0x00000000;

//The ID of sendmail
ECanbMboxes.MBOX0.MSGID.all = 0xCF00FFFF; //CF00FFFF 1100 1111 0000 0000 1111 1111 1111 1111
//The ID of receivemail
ECanbMboxes.MBOX16.MSGID.all = 0x80C20000;//CF02FFFF 1100 1111 0000 0010 1111 1111 1111 1111

/*数据长度为8byte*/
ECanbMboxes.MBOX0.MSGCTRL.bit.DLC = 8;
ECanbMboxes.MBOX16.MSGCTRL.bit.DLC = 8;

/*The mail0 is TX;The mail16 is RX*/
ECanbShadow.CANMD.all = ECanbRegs.CANMD.all;
ECanbShadow.CANMD.bit.MD0 =0;
ECanbShadow.CANMD.bit.MD16 =1;
ECanbRegs.CANMD.all = ECanbShadow.CANMD.all;

ECanbShadow.CANME.all = ECanbRegs.CANME.all;
ECanbShadow.CANME.all = 0x00010001; // Required before writing the MSGIDs 0000 0000 0000 0001 0000 0000 0000 0001
ECanbRegs.CANME.all = ECanbShadow.CANME.all;

// /*没有远方应答帧被请求*/
ECanbMboxes.MBOX16.MSGCTRL.bit.RTR = 0;

//邮箱屏蔽使能
ECanbRegs.CANMIM.all = 0xFFFFFFFF;
//邮箱中断将产生在ECAN0INT
ECanbRegs.CANMIL.all = 0;
ECanbRegs.CANGIF0.all = 0xFFFFFFFF;
//ECAN0INT中断请求被使能
ECanbRegs.CANGIM.bit.I0EN = 1;
EDIS;
}

beidoubushixing:

回复 JT Niu:

1.看RMP位是否会置位。
2.可以在接收数据函数里面,将数据读出到变量,再去观察。

按照官方配置,配置完can接收,采用中断接收,debug时进不了中断。有没有遇到类似情况的?求解答。

void InitECan(void) // Initialize eCAN-B module
{
struct ECAN_REGS ECanbShadow;
EALLOW; // EALLOW enables access to protected bits
//配置GPIO工作在额eCAN功能
GpioCtrlRegs.GPAPUD.bit.GPIO16 = 1; // Disable pull-up for GPIO16 (CANTXB)
GpioCtrlRegs.GPAPUD.bit.GPIO17 = 0; // Enable pull-up for GPIO17 (CANRXB)
GpioCtrlRegs.GPAQSEL2.bit.GPIO17 = 3; // Asynch qual for GPIO17 (CANRXB)
GpioCtrlRegs.GPAMUX2.bit.GPIO16 = 2; // Configure GPIO16 for CANTXB operation
GpioCtrlRegs.GPAMUX2.bit.GPIO17 = 2; // Configure GPIO17 for CANRXB operation

//配置eCAN的RX和TX分别为eCAN的接收和发射引脚

ECanbShadow.CANTIOC.all = ECanbRegs.CANTIOC.all;

ECanbShadow.CANTIOC.bit.TXFUNC = 1;

ECanbRegs.CANTIOC.all = ECanbShadow.CANTIOC.all;

ECanbShadow.CANRIOC.all = ECanbRegs.CANRIOC.all;
ECanbShadow.CANRIOC.bit.RXFUNC = 1;
ECanbRegs.CANRIOC.all = ECanbShadow.CANRIOC.all;

/* Configure bit timing parameters for eCANB*/
ECanbShadow.CANMC.all = ECanbRegs.CANMC.all;
ECanbShadow.CANMC.bit.CCR = 1 ; // Set CCR = 1
ECanbRegs.CANMC.all = ECanbShadow.CANMC.all;

ECanbShadow.CANES.all = ECanbRegs.CANES.all;
do
{ECanbShadow.CANES.bit.CCE=ECanbRegs.CANES.bit.CCE;}
while(ECanbShadow.CANES.bit.CCE != 1 ) ; // Wait for CCE bit to be set..CCE等于1时跳出循环,则可以对CANBTC设置

//设置通信波特率
ECanbShadow.CANBTC.all = ECanbRegs.CANBTC.all;
ECanbShadow.CANBTC.bit.BRPREG = 9;
/*150/10=15*/
ECanbShadow.CANBTC.bit.TSEG2REG = 2;
ECanbShadow.CANBTC.bit.TSEG1REG = 10;
ECanbRegs.CANBTC.all = ECanbShadow.CANBTC.all;

ECanbShadow.CANMC.all = ECanbRegs.CANMC.all;
ECanbShadow.CANMC.bit.STM = 0; //工作在正常模式
ECanbShadow.CANMC.bit.DBO = 1;
ECanbShadow.CANMC.bit.SCB = 1;
ECanbRegs.CANMC.all = ECanbShadow.CANMC.all;
do
{
// ECanbShadow.CANES.all = ECanbRegs.CANES.all;
ECanbShadow.CANES.bit.CCE = 0;
} while(ECanbShadow.CANES.bit.CCE != 0 ); // Wait for CCE bit to be cleared..

//初始化所有主设备控制区域为0,MCF所有的位都初始化为0
ECanbMboxes.MBOX0.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX1.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX2.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX3.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX4.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX5.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX6.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX7.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX8.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX9.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX10.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX11.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX12.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX13.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX14.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX15.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX16.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX17.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX18.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX19.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX20.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX21.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX22.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX23.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX24.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX25.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX26.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX27.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX28.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX29.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX30.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX31.MSGCTRL.all = 0x00000000;

// TAn, RMPn, GIFn bits are all zero upon reset and are cleared again
// as a matter of precaution.

ECanbShadow.CANTA.all = ECanbRegs.CANTA.all;
ECanbShadow.CANTA.all = 0xFFFFFFFF;
ECanbRegs.CANTA.all = ECanbShadow.CANTA.all;

ECanbShadow.CANRMP.all = ECanbRegs.CANRMP.all;
ECanbShadow.CANRMP.all = 0xFFFFFFFF;
ECanbRegs.CANRMP.all = ECanbShadow.CANRMP.all;

ECanbShadow.CANGIF0.all = ECanbRegs.CANGIF0.all;
ECanbShadow.CANGIF0.all = 0xFFFFFFFF;
ECanbRegs.CANGIF0.all = ECanbShadow.CANGIF0.all;

ECanbShadow.CANGIF1.all = ECanbRegs.CANGIF1.all;
ECanbShadow.CANGIF1.all = 0xFFFFFFFF;
ECanbRegs.CANGIF1.all = ECanbShadow.CANGIF1.all;

EALLOW;
/* Mailbox interrupt is disable*/
ECanbShadow.CANGIM.all = 0x00000000;
ECanbRegs.CANGIM.all = ECanbShadow.CANGIM.all;

ECanbShadow.CANMIM.all = 0x00000000;
ECanbRegs.CANMIM.all = ECanbShadow.CANMIM.all;

ECanbShadow.CANMIL.all = 0xFFFFFFFF;
ECanbRegs.CANMIL.all = ECanbShadow.CANMIL.all;
EDIS;

/* Set ECan mailboxs */
ECanbRegs.CANME.all = 0x00000000;

//The ID of sendmail
ECanbMboxes.MBOX0.MSGID.all = 0xCF00FFFF; //CF00FFFF 1100 1111 0000 0000 1111 1111 1111 1111
//The ID of receivemail
ECanbMboxes.MBOX16.MSGID.all = 0x80C20000;//CF02FFFF 1100 1111 0000 0010 1111 1111 1111 1111

/*数据长度为8byte*/
ECanbMboxes.MBOX0.MSGCTRL.bit.DLC = 8;
ECanbMboxes.MBOX16.MSGCTRL.bit.DLC = 8;

/*The mail0 is TX;The mail16 is RX*/
ECanbShadow.CANMD.all = ECanbRegs.CANMD.all;
ECanbShadow.CANMD.bit.MD0 =0;
ECanbShadow.CANMD.bit.MD16 =1;
ECanbRegs.CANMD.all = ECanbShadow.CANMD.all;

ECanbShadow.CANME.all = ECanbRegs.CANME.all;
ECanbShadow.CANME.all = 0x00010001; // Required before writing the MSGIDs 0000 0000 0000 0001 0000 0000 0000 0001
ECanbRegs.CANME.all = ECanbShadow.CANME.all;

// /*没有远方应答帧被请求*/
ECanbMboxes.MBOX16.MSGCTRL.bit.RTR = 0;

//邮箱屏蔽使能
ECanbRegs.CANMIM.all = 0xFFFFFFFF;
//邮箱中断将产生在ECAN0INT
ECanbRegs.CANMIL.all = 0;
ECanbRegs.CANGIF0.all = 0xFFFFFFFF;
//ECAN0INT中断请求被使能
ECanbRegs.CANGIM.bit.I0EN = 1;
EDIS;
}

cuiling qi:

回复 JT Niu:

请问您这个程序调通了吗?之前我也在看CAN通信,就一直有一个问题就是当RLC设置成8的时候是MDL和MDH分别是8BYTE,还是加起来是8BYTE?

按照官方配置,配置完can接收,采用中断接收,debug时进不了中断。有没有遇到类似情况的?求解答。

void InitECan(void) // Initialize eCAN-B module
{
struct ECAN_REGS ECanbShadow;
EALLOW; // EALLOW enables access to protected bits
//配置GPIO工作在额eCAN功能
GpioCtrlRegs.GPAPUD.bit.GPIO16 = 1; // Disable pull-up for GPIO16 (CANTXB)
GpioCtrlRegs.GPAPUD.bit.GPIO17 = 0; // Enable pull-up for GPIO17 (CANRXB)
GpioCtrlRegs.GPAQSEL2.bit.GPIO17 = 3; // Asynch qual for GPIO17 (CANRXB)
GpioCtrlRegs.GPAMUX2.bit.GPIO16 = 2; // Configure GPIO16 for CANTXB operation
GpioCtrlRegs.GPAMUX2.bit.GPIO17 = 2; // Configure GPIO17 for CANRXB operation

//配置eCAN的RX和TX分别为eCAN的接收和发射引脚

ECanbShadow.CANTIOC.all = ECanbRegs.CANTIOC.all;

ECanbShadow.CANTIOC.bit.TXFUNC = 1;

ECanbRegs.CANTIOC.all = ECanbShadow.CANTIOC.all;

ECanbShadow.CANRIOC.all = ECanbRegs.CANRIOC.all;
ECanbShadow.CANRIOC.bit.RXFUNC = 1;
ECanbRegs.CANRIOC.all = ECanbShadow.CANRIOC.all;

/* Configure bit timing parameters for eCANB*/
ECanbShadow.CANMC.all = ECanbRegs.CANMC.all;
ECanbShadow.CANMC.bit.CCR = 1 ; // Set CCR = 1
ECanbRegs.CANMC.all = ECanbShadow.CANMC.all;

ECanbShadow.CANES.all = ECanbRegs.CANES.all;
do
{ECanbShadow.CANES.bit.CCE=ECanbRegs.CANES.bit.CCE;}
while(ECanbShadow.CANES.bit.CCE != 1 ) ; // Wait for CCE bit to be set..CCE等于1时跳出循环,则可以对CANBTC设置

//设置通信波特率
ECanbShadow.CANBTC.all = ECanbRegs.CANBTC.all;
ECanbShadow.CANBTC.bit.BRPREG = 9;
/*150/10=15*/
ECanbShadow.CANBTC.bit.TSEG2REG = 2;
ECanbShadow.CANBTC.bit.TSEG1REG = 10;
ECanbRegs.CANBTC.all = ECanbShadow.CANBTC.all;

ECanbShadow.CANMC.all = ECanbRegs.CANMC.all;
ECanbShadow.CANMC.bit.STM = 0; //工作在正常模式
ECanbShadow.CANMC.bit.DBO = 1;
ECanbShadow.CANMC.bit.SCB = 1;
ECanbRegs.CANMC.all = ECanbShadow.CANMC.all;
do
{
// ECanbShadow.CANES.all = ECanbRegs.CANES.all;
ECanbShadow.CANES.bit.CCE = 0;
} while(ECanbShadow.CANES.bit.CCE != 0 ); // Wait for CCE bit to be cleared..

//初始化所有主设备控制区域为0,MCF所有的位都初始化为0
ECanbMboxes.MBOX0.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX1.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX2.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX3.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX4.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX5.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX6.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX7.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX8.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX9.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX10.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX11.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX12.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX13.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX14.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX15.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX16.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX17.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX18.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX19.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX20.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX21.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX22.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX23.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX24.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX25.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX26.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX27.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX28.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX29.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX30.MSGCTRL.all = 0x00000000;
ECanbMboxes.MBOX31.MSGCTRL.all = 0x00000000;

// TAn, RMPn, GIFn bits are all zero upon reset and are cleared again
// as a matter of precaution.

ECanbShadow.CANTA.all = ECanbRegs.CANTA.all;
ECanbShadow.CANTA.all = 0xFFFFFFFF;
ECanbRegs.CANTA.all = ECanbShadow.CANTA.all;

ECanbShadow.CANRMP.all = ECanbRegs.CANRMP.all;
ECanbShadow.CANRMP.all = 0xFFFFFFFF;
ECanbRegs.CANRMP.all = ECanbShadow.CANRMP.all;

ECanbShadow.CANGIF0.all = ECanbRegs.CANGIF0.all;
ECanbShadow.CANGIF0.all = 0xFFFFFFFF;
ECanbRegs.CANGIF0.all = ECanbShadow.CANGIF0.all;

ECanbShadow.CANGIF1.all = ECanbRegs.CANGIF1.all;
ECanbShadow.CANGIF1.all = 0xFFFFFFFF;
ECanbRegs.CANGIF1.all = ECanbShadow.CANGIF1.all;

EALLOW;
/* Mailbox interrupt is disable*/
ECanbShadow.CANGIM.all = 0x00000000;
ECanbRegs.CANGIM.all = ECanbShadow.CANGIM.all;

ECanbShadow.CANMIM.all = 0x00000000;
ECanbRegs.CANMIM.all = ECanbShadow.CANMIM.all;

ECanbShadow.CANMIL.all = 0xFFFFFFFF;
ECanbRegs.CANMIL.all = ECanbShadow.CANMIL.all;
EDIS;

/* Set ECan mailboxs */
ECanbRegs.CANME.all = 0x00000000;

//The ID of sendmail
ECanbMboxes.MBOX0.MSGID.all = 0xCF00FFFF; //CF00FFFF 1100 1111 0000 0000 1111 1111 1111 1111
//The ID of receivemail
ECanbMboxes.MBOX16.MSGID.all = 0x80C20000;//CF02FFFF 1100 1111 0000 0010 1111 1111 1111 1111

/*数据长度为8byte*/
ECanbMboxes.MBOX0.MSGCTRL.bit.DLC = 8;
ECanbMboxes.MBOX16.MSGCTRL.bit.DLC = 8;

/*The mail0 is TX;The mail16 is RX*/
ECanbShadow.CANMD.all = ECanbRegs.CANMD.all;
ECanbShadow.CANMD.bit.MD0 =0;
ECanbShadow.CANMD.bit.MD16 =1;
ECanbRegs.CANMD.all = ECanbShadow.CANMD.all;

ECanbShadow.CANME.all = ECanbRegs.CANME.all;
ECanbShadow.CANME.all = 0x00010001; // Required before writing the MSGIDs 0000 0000 0000 0001 0000 0000 0000 0001
ECanbRegs.CANME.all = ECanbShadow.CANME.all;

// /*没有远方应答帧被请求*/
ECanbMboxes.MBOX16.MSGCTRL.bit.RTR = 0;

//邮箱屏蔽使能
ECanbRegs.CANMIM.all = 0xFFFFFFFF;
//邮箱中断将产生在ECAN0INT
ECanbRegs.CANMIL.all = 0;
ECanbRegs.CANGIF0.all = 0xFFFFFFFF;
//ECAN0INT中断请求被使能
ECanbRegs.CANGIM.bit.I0EN = 1;
EDIS;
}

cuiling qi:

您好,请问您这个问题解决了吗?我的例程也是进不了中断

赞(0)
未经允许不得转载:TI中文支持网 » 28335的CAN中断接收方式
分享到: 更多 (0)