標(biāo)題: STM32實(shí)現(xiàn) Ethercat 從站源碼 [打印本頁]

作者: luipingwei    時(shí)間: 2022-3-29 18:37
標(biāo)題: STM32實(shí)現(xiàn) Ethercat 從站源碼
該源碼是當(dāng)前流行的機(jī)器人控制系統(tǒng)倍福所采用的構(gòu)架Ethercat  總線
xml文件是設(shè)備描述文件,燒寫在了EEPROM 里面  從站站 (ET11000)上電后 會(huì)從 eeprom 加載配置參數(shù)
完成初始化過程

文件中有對(duì)應(yīng)IO 及AD 全局變量的定義
extern     uint16_t uhADCxConvertedValue;
#define SWITCH_1         PCin(7)//   PCin(8)                // PORTDbits.RD7 /**< \brief Access to switch 1 input*/
#define SWITCH_2         PCin(8)//   PCin(9)                // PORTDbits.RD6 /**< \brief Access to switch 2 input*/
#define SWITCH_3         PCin(9)//   PAin(11)                // PORTDbits.RD5 /**< \brief Access to switch 3 input*/
#define SWITCH_4         PGin(11)//   PAin(12)                // PORTDbits.RD4 /**< \brief Access to switch 4 input*/
#define SWITCH_5         PGin(12)//   PAin(13)                // PORTDbits.RD3 /**< \brief Access to switch 5 input*/
#define SWITCH_6         PGin(13)//   PAin(14)                // PORTDbits.RD2 /**< \brief Access to switch 6 input*/
#define SWITCH_7         PGin(14)//  PAin(15)                // PORTDbits.RD1 /**< \brief Access to switch 7 input*/
#define SWITCH_8         PGin(15)//   PCin(12)                // PORTDbits.RD0 /**< \brief Access to switch 8 input*/

#define LED_1            PCout(6)    //     PCout(7)                // LATBbits.LATB8 /**< \brief Access to led 1 output*/
#define LED_2            PGout(8)    //     PCout(6)            //3////LATBbits.LATB9 /**< \brief Access to led 2 output*/
#define LED_3            PGout(7)//     PGout(8)                // LATBbits.LATB10 /**< \brief Access to led 3 output*/
#define LED_4            PGout(6)//     PGout(7)                //LATBbits.LATB11 /**< \brief Access to led 4 output*/
#define LED_5            PGout(5)//     PGout(6)                // LATBbits.LATB12 /**< \brief Access to led 5 output*/
#define LED_6            PGout(4)//     PGout(5)                // LATBbits.LATB13 /**< \brief Access to led 6 output*/
#define LED_7            PGout(3)//     PGout(4)                //LATBbits.LATB14 /**< \brief Access to led 7 output*/
#define LED_8            PDout(13)//     PGout(3)   


部分源碼如
/////////////////////////////////////////////////////////////////////////////////////////
/**
\return     0(ALSTATUSCODE_NOERROR), NOERROR_INWORK
\param      pInputSize  pointer to save the input process data length
\param      pOutputSize  pointer to save the output process data length

\brief    This function calculates the process data sizes from the actual SM-PDO-Assign
            and PDO mapping
*////////////////////////////////////////////////////////////////////////////////////////
UINT16 APPL_GenerateMapping(UINT16* pInputSize,UINT16* pOutputSize)
{
#if COE_SUPPORTED
    UINT16 result = ALSTATUSCODE_NOERROR;
    UINT16 PDOAssignEntryCnt = 0;
    OBJCONST TOBJECT OBJMEM * pPDO = NULL;
    UINT16 PDOSubindex0 = 0;
    UINT32 *pPDOEntry = NULL;
    UINT16 PDOEntryCnt = 0;
    UINT16 InputSize = 0;
    UINT16 OutputSize = 0;

    /*Scan object 0x1C12 RXPDO assign*/
    for(PDOAssignEntryCnt = 0; PDOAssignEntryCnt < sRxPDOassign.u16SubIndex0; PDOAssignEntryCnt++)
    {
        pPDO = OBJ_GetObjectHandle(sRxPDOassign.aEntries[PDOAssignEntryCnt]);
        if(pPDO != NULL)
        {
            PDOSubindex0 = *((UINT16 *)pPDO->pVarPtr);
            for(PDOEntryCnt = 0; PDOEntryCnt < PDOSubindex0; PDOEntryCnt++)
            {
                        //                                result = *(UINT8 *)pPDO->pVarPtr;
                        //                                result=(OBJ_GetEntryOffset((PDOEntryCnt+1),pPDO)>>3);
                pPDOEntry = (UINT32 *)((UINT8 *)pPDO->pVarPtr + (OBJ_GetEntryOffset((PDOEntryCnt+1),pPDO)>>3));    //goto PDO entry
                // we increment the expected output size depending on the mapped Entry
                OutputSize += (UINT16) ((*pPDOEntry) & 0xFF);
            }
        }
        else
        {
            /*assigned PDO was not found in object dictionary. return invalid mapping*/
            OutputSize = 0;
            result = ALSTATUSCODE_INVALIDOUTPUTMAPPING;
            break;
        }
    }

    OutputSize = (OutputSize + 7) >> 3;// +7

下載: STM32實(shí)現(xiàn) Ethercat 從站源碼.rar (1.19 MB, 下載次數(shù): 98)
UC16-R1.rar (4.54 KB, 下載次數(shù): 53)

作者: zhaomingli    時(shí)間: 2023-2-16 16:23
EtherCAT從站開發(fā)板及源程序:
簡化XML生成,簡化編程,10分鐘快速入門,詳細(xì)見:
http://www.openedv.com/forum.php?mod=viewthread&tid=340287

作者: shiman999    時(shí)間: 2023-3-31 08:50
樓主,你好!STM32實(shí)現(xiàn)EtherCat從站源碼,看不出從那體現(xiàn)出來。能否詳細(xì)解說一下,謝謝!
作者: yahuiwang    時(shí)間: 2024-8-7 11:19
受教了,謝謝分享
作者: huaishang    時(shí)間: 2025-1-1 19:21
受教了,謝謝分享
作者: suroy    時(shí)間: 2025-1-2 00:06
goodjob




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1