打印

TMS320F28335 eCAN模块自检函数

[复制链接]
2952|6
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
Laspide|  楼主 | 2013-11-22 11:04 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
做个一个TMS320F28335 eCAN模块自检函数
Uint32 ECAN_SelfTest(Uint16 ECAN_mu16_CANModuleSN)
{
Uint16 ECAN_mu16_MBoxesSN; /* the mailbox serial number of ECAN Module */
Uint32 ECAN_mu32_RecFrmID; /* the ID of receive frame */
Uint32 ECAN_mu32_RecFrmLowData; /* the low data of receive frame */
Uint32 ECAN_mu32_RecFrmHighData; /* the high data of receive frame */
Uint16 ECAN_mu16_SelfTestNum; /* the number of self test */
Uint32 ECAN_mu32_SelfTestFlag; /* the flag for self test */
Uint16 ECAN_mu16_TestErrCount; /* test error counter */
ECAN_mu32_SelfTestFlag = 0x00000000;
ECan_ms_Regs_Shadow[ECAN_mu16_CANModuleSN].CANMC.all = ECan_mp_Regs[ECAN_mu16_CANModuleSN]->CANMC.all;
if ( ECan_ms_Regs_Shadow[ECAN_mu16_CANModuleSN].CANMC.bit.STM == TRUE )
{
ECan_mp_Regs[ECAN_mu16_CANModuleSN]->CANME.all = 0x00000000;
/* the lower 16 Mailbox will set to be transmit mailbox. */
for ( ECAN_mu16_MBoxesSN = 0; ECAN_mu16_MBoxesSN < 16; ECAN_mu16_MBoxesSN++ )
{
ECan_mp_MBoxes[ECAN_mu16_CANModuleSN]->MBOX[ECAN_mu16_MBoxesSN].MSGID.all = ECAN_MBOX_DEF_ID - ( 1 << ECAN_mu16_MBoxesSN );
ECan_mp_MBoxes[ECAN_mu16_CANModuleSN]->MBOX[ECAN_mu16_MBoxesSN].MSGCTRL.bit.RTR = BIT_CLEAR;
ECan_mp_MBoxes[ECAN_mu16_CANModuleSN]->MBOX[ECAN_mu16_MBoxesSN].MSGCTRL.bit.DLC = 8;
}
/* the higher 16 Mailbox will set to be Receive mailbox. */
for ( ECAN_mu16_MBoxesSN = 16; ECAN_mu16_MBoxesSN < ECAN_MBOX_NUM; ECAN_mu16_MBoxesSN++ )
{
ECan_mp_MBoxes[ECAN_mu16_CANModuleSN]->MBOX[ECAN_mu16_MBoxesSN].MSGID.all = ECAN_MBOX_DEF_ID - ( 1 << ECAN_mu16_MBoxesSN );
}
/* Mailbox configuration */
ECan_mp_Regs[ECAN_mu16_CANModuleSN]->CANMD.all = 0xFFFF0000;
ECan_mp_Regs[ECAN_mu16_CANModuleSN]->CANME.all = 0xFFFFFFFF;
for ( ECAN_mu16_MBoxesSN = 0; ECAN_mu16_MBoxesSN < 16; ECAN_mu16_MBoxesSN++ )
{
ECan_mp_MBoxes[ECAN_mu16_CANModuleSN]->MBOX[ECAN_mu16_MBoxesSN].MDH.all = ECAN_DEF_SEND_DATA_HIGH;
ECan_mp_MBoxes[ECAN_mu16_CANModuleSN]->MBOX[ECAN_mu16_MBoxesSN].MDL.all = ECAN_DEF_SEND_DATA_LOW - ( 1 << ECAN_mu16_MBoxesSN );
}
/* Self-Test Start */
for ( ECAN_mu16_SelfTestNum = 0; ECAN_mu16_SelfTestNum < ECAN_SELF_TEST_MAX_NUM; ECAN_mu16_SelfTestNum++ )
{
/* send messages from the lower 16 mailboxes */
ECan_mp_Regs[ECAN_mu16_CANModuleSN]->CANTRS.all = 0x0000FFFF; /* Set TRS for all transmit mailboxes */
while( ECan_mp_Regs[ECAN_mu16_CANModuleSN]->CANTA.all != 0x0000FFFF ); /* Wait for all TAn bits to be set.. */
ECan_mp_Regs[ECAN_mu16_CANModuleSN]->CANTA.all = 0x0000FFFF; /* Clear all TAn */
/* Read from Receive mailboxes and check data */
for ( ECAN_mu16_MBoxesSN = 16; ECAN_mu16_MBoxesSN < ECAN_MBOX_NUM; ECAN_mu16_MBoxesSN++ )
{
ECAN_mu32_RecFrmID = ECan_mp_MBoxes[ECAN_mu16_CANModuleSN]->MBOX[ECAN_mu16_MBoxesSN].MSGID.all;
ECAN_mu32_RecFrmLowData = ECan_mp_MBoxes[ECAN_mu16_CANModuleSN]->MBOX[ECAN_mu16_MBoxesSN].MDL.all;
ECAN_mu32_RecFrmHighData = ECan_mp_MBoxes[ECAN_mu16_CANModuleSN]->MBOX[ECAN_mu16_MBoxesSN].MDH.all;
if(( ECAN_mu32_RecFrmID != ECAN_mu32_RecFrmLowData) || ( ECAN_mu32_RecFrmHighData != ECAN_DEF_SEND_DATA_HIGH ))
{
ECAN_mu16_TestErrCount++;
ECAN_mu32_SelfTestFlag &= ~(( 1 << ECAN_mu16_MBoxesSN ) | (1 << ( ECAN_mu16_MBoxesSN - 16 )));
}
else
{
ECAN_mu32_SelfTestFlag |= (( 1 << ECAN_mu16_MBoxesSN ) | (1 << ( ECAN_mu16_MBoxesSN - 16 )));
}
}
}
}
else
{
}
return( ECAN_mu32_SelfTestFlag );
}
调用
ECAN_InitModule(); /* This function is in DSP2833x_ECan.c */
if( ECAN_SelfTest(ECAN_ECANA_SN) == 0xFFFFFFFF )
{
ECAN_EnterNormalMode(ECAN_ECANA_SN);
ECAN_ConfigRecMsgBox( ECAN_ECANA_SN, CAN_REC_TST_MAILBOX_SN, CAN_REC_TST_MSG_ID, CAN_REC_MAILBOX_MASK, CAN_FRM_DATA_LENGTH);
ECAN_ConfigSendMsgBox(ECAN_ECANA_SN, CAN_SND_TST_MAILBOX_SN, CAN_SND_TST_MSG_ID, CAN_SND_TST_MAILBOX_SN, CAN_FRM_DATA_LENGTH);
ECAN_ConfigSendMsgBox(ECAN_ECANA_SN, CAN_SND_SYS_MAILBOX_SN, CAN_SND_SYS_MSG_ID, CAN_SND_SYS_MAILBOX_SN, CAN_FRM_DATA_LENGTH);
}
else
{
/* Fault Management */
//ECAN_SendMsg( ECAN_ECANA_SN, 24, 0xAA55AA55, 0x55AA55AA );
}
初始化函数STM位是自检状态,只要改为工作模式,就可以CAN进行通讯。
ECAN_EnterNormalMode(ECAN_ECANA_SN);进入工作模式可以正常通讯。
CAN的接收中断函数
interrupt void ECAN0INTA_ISR(void) // eCAN-A
{
// Insert ISR Code here
// To receive more interrupts from this PIE group, acknowledge this interrupt
// PieCtrlRegs.PIEACK.all = PIEACK_GROUP9;
// Next two lines for debug only to halt the processor here
// Remove after inserting ISR Code
PieCtrlRegs.PIEACK.bit.ACK9 = 1;
if( (ECAN_RecMsg(CAN_ms_RecCANMsgB,ECAN_ECANA_SN,CAN_REC_TST_MAILBOX_SN)) == CAN_REC_TST_MAILBOX_SN )
{
标志寄存器_mu16_Work_Status = 2; /* Test Mode */
}
if( (ECAN_RecMsg(CAN_ms_RecCANMsgA,ECAN_ECANA_SN,CAN_REC_SYS_MAILBOX_SN)) == CAN_REC_SYS_MAILBOX_SN )
{
标志寄存器_mu16_Work_Status = 1; /* Test Mode */
}
EINT;
}
接收中断中置两个接收标志,主循环中分别判断标志,作出相应响应
问题是debug中,一旦连续运行,程序就会进入此中断一次,置一个标志,主循环的逻辑就错误响应了,而且两个标志中,只进前面一个标志判断中。
单步运行却不会进入此中断。
自检时,全局中断是关闭的,所有初始化都完成后才开中断。
想不出程序到底有什么问题,最后的办法是在自检完成后,重新初始化eCAN,程序就OK了,不会在进入CAN接收中断函数了。


ECAN_InitModule(); /* This function is in DSP2833x_ECan.c */
if( ECAN_SelfTest(ECAN_ECANA_SN) == 0xFFFFFFFF )
{
ECAN_InitModule();

ECAN_EnterNormalMode(ECAN_ECANA_SN);
ECAN_ConfigRecMsgBox( ECAN_ECANA_SN, CAN_REC_TST_MAILBOX_SN, CAN_REC_TST_MSG_ID, CAN_REC_MAILBOX_MASK, CAN_FRM_DATA_LENGTH);
ECAN_ConfigSendMsgBox(ECAN_ECANA_SN, CAN_SND_TST_MAILBOX_SN, CAN_SND_TST_MSG_ID, CAN_SND_TST_MAILBOX_SN, CAN_FRM_DATA_LENGTH);
ECAN_ConfigSendMsgBox(ECAN_ECANA_SN, CAN_SND_SYS_MAILBOX_SN, CAN_SND_SYS_MSG_ID, CAN_SND_SYS_MAILBOX_SN, CAN_FRM_DATA_LENGTH);
}
else
{
/* Fault Management */
//ECAN_SendMsg( ECAN_ECANA_SN, 24, 0xAA55AA55, 0x55AA55AA );
}


有没有朋友做过类似的功能,希望知道问题的真实所在。

相关帖子

沙发
dirtwillfly| | 2013-11-22 11:35 | 只看该作者
没玩过,帮顶

使用特权

评论回复
板凳
specialfrin| | 2013-11-22 22:50 | 只看该作者
= = 坐等高手解答

使用特权

评论回复
地板
dirtwillfly| | 2013-11-23 12:21 | 只看该作者
帮你叫个高手来。请 @zhangmangui 版主帮忙回答

使用特权

评论回复
5
justbybing| | 2013-11-23 22:52 | 只看该作者
求大神现身

使用特权

评论回复
6
i1mcu| | 2013-11-24 19:59 | 只看该作者
回环测试 么?

使用特权

评论回复
7
i1mcu| | 2013-11-24 20:00 | 只看该作者
你可以参考一下2812产品的。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

106

主题

241

帖子

0

粉丝