F2812 eCAN模块作从站,与主站进行CANOPEN通讯,使用3个RXPDO,4个TXPDO,调试通讯出现如下问题:
主站只能接收到优先级较高的两个邮箱的数据,即可接收到两个TXPDO的数据,报另两个TXPDO丢失。
主站可与其他从站进行正常通讯,故推断问题可能在从站,但检查配置等未发现问题,请诸位指教。
user4395406:
问题补充:通讯方式若为同步,可正常实现通讯;若为异步方式即会出现上述问题
Green Deng:
回复 user4395406:
你好,方便贴上配置方面的程序吗?
user4395406:
回复 Green Deng:
你好,代码如下,以TXPDO1为例
#define DICTIONARY_PDO1_TX_COMM \{0x1800,0x00,RW,1,(unsigned char *)&uTPDO1Len},\{0x1800,0x01,RW|FUNC,4,(void *)&CO_TPDO1_COBIDAccessEvent},\{0x1800,0x02,RW|FUNC,1,(void *)&CO_TPDO1_TypeAccessEvent}
const DICT_OBJECT_TEMPLATE db_pdo1_tx_comm[] = {DICTIONARY_PDO1_TX_COMM};void CO_CanStackInit(void){ CO_ResetComunParam();CO_CanHardwreInit();CO_NmtOpen();CO_SyncOpen(); CO_Sdo1Open(); CO_NmteProdOpen();// COBID=0x700L+idCO_NmteConsOpen();}
void CO_SyncOpen(void){ Uint16 lSYNC_COBID;lSYNC_COBID=0x80;ECanaShadow.CANME.all = ECanaRegs.CANME.all;ECanaShadow.CANME.bit.ME24 = 0; ECanaRegs.CANME.all = ECanaShadow.CANME.all;ECanaMboxes.MBOX24.MSGID.bit.STDMSGID = lSYNC_COBID;ECanaShadow.CANMD.all = ECanaRegs.CANMD.all;ECanaShadow.CANMD.bit.MD24 = 1; //RX ECanaRegs.CANMD.all = ECanaShadow.CANMD.all;
ECanaShadow.CANME.all = ECanaRegs.CANME.all;ECanaShadow.CANME.bit.ME24 = 1; ECanaRegs.CANME.all = ECanaShadow.CANME.all;unnEnFlg.bit.SYNC_EN=1;}void CO_TPdo1Open(void){Uint16ucTPDO1_COBID;ucTPDO1_COBID = ((((Uint16)uTPDOComm1.Byte2) & 0x0FF)<<8U) + (uTPDOComm1.Byte1 & 0x0FF);ECanaShadow.CANME.all = ECanaRegs.CANME.all;ECanaShadow.CANME.bit.ME12 = 0; ECanaRegs.CANME.all = ECanaShadow.CANME.all;ECanaMboxes.MBOX12.MSGID.bit.STDMSGID = ucTPDO1_COBID;ECanaMboxes.MBOX12.MSGCTRL.bit.TPL=4; ECanaMboxes.MBOX12.MSGCTRL.bit.DLC=8;ECanaShadow.CANMD.all = ECanaRegs.CANMD.all;ECanaShadow.CANMD.bit.MD12 = 0; //TXECanaRegs.CANMD.all = ECanaShadow.CANMD.all;ECanaShadow.CANME.all = ECanaRegs.CANME.all;ECanaShadow.CANME.bit.ME12 = 1; ECanaRegs.CANME.all = ECanaShadow.CANME.all;unnEnFlg.bit.TPDO1_EN=1;}
voidCO_TPDO1_COBIDAccessEvent(void){switch ( mCO_DictGetCmd() ){case DICT_OBJ_INFO:{break;}case DICT_OBJ_READ: {*(struct PDO_COMMUNCATION_PARMTER *)(uDict.obj->pReqBuf)=uTPDOComm1;break;}
case DICT_OBJ_WRITE: {stPdoCOIBTemp = *(struct PDO_COMMUNCATION_PARMTER *)(uDict.obj->pReqBuf);if(stPdoCOIBTemp.Byte4.bit.PDO_DIS){//close TPDO1if((stPdoCOIBTemp.Byte1==uTPDOComm1.Byte1)&&(stPdoCOIBTemp.Byte2==uTPDOComm1.Byte2)&&(stPdoCOIBTemp.Byte3==uTPDOComm1.Byte3)&&(!((stPdoCOIBTemp.Byte4.all^uTPDOComm1.Byte4.all)&0x007F))){if(unnEnFlg.bit.TPDO1_EN)CO_TPdo1Close();uTPDOComm1.Byte4.bit.PDO_DIS=1; }else { mCO_DictSetRet(E_PARAM_RANGE);}}else{//open TPDO1if((stPdoCOIBTemp.Byte1==uTPDOComm1.Byte1)&&(stPdoCOIBTemp.Byte2==uTPDOComm1.Byte2)&&(stPdoCOIBTemp.Byte3==uTPDOComm1.Byte3)&&(!((stPdoCOIBTemp.Byte4.all^uTPDOComm1.Byte4.all)&0x007F))){if(!unnEnFlg.bit.TPDO1_EN)CO_TPdo1Open();uTPDOComm1.Byte4.bit.PDO_DIS=0; }else { mCO_DictSetRet(E_PARAM_RANGE);}}break;}}}
voidCO_TPDO1_TypeAccessEvent(void){Uint16 uitemp;switch (mCO_DictGetCmd()){case DICT_OBJ_INFO:{break;}case DICT_OBJ_READ: {*(uDict.obj->pReqBuf)=ucTPdo1SyncSet;break;}case DICT_OBJ_WRITE: {uitemp =*(uDict.obj->pReqBuf);if( (uitemp==0)||(uitemp >1U)||(uitemp <=240U) ){ucTPdo1Counter=ucTPdo1SyncSet=uitemp;}else if( (uitemp==254)||(uitemp==255) ){ucTPdo1SyncSet=uitemp;}else{ mCO_DictSetRet(E_PARAM_RANGE);}break;}}}
Green Deng:
回复 user4395406:
你好,关于CANopen的问题,我咨询了一下美国的工程师,对方表示
we cannot help you with CANopen issues. For that, you may have to reach out to some other online forum for CANopen.
不过他也提供了一些调试技巧:
What is the MSGID of the two failing TXPDO?Have you ensured that frames with those MSGIDs are actually transmitted on the bus?
If they are indeed transmitted, are there any RX mailboxes correctly configured to receive these messages?
Remove CANopen from the picture and treat it like normal CAN communication. My suspicion is that this likely a mailbox configuration issue.
user4395406:
回复 Green Deng:
非常感谢您的回复!
我会再检查相关配置。
Green Deng:
回复 user4395406:
客气了