标题: STM32实现 Ethercat 从站源码 [打印本页]

作者: luipingwei    时间: 2022-3-29 18:37
标题: STM32实现 Ethercat 从站源码
该源码是当前流行的机器人控制系统倍福所采用的构架Ethercat  总线
xml文件是设备描述文件,烧写在了EEPROM 里面  从站站 (ET11000)上电后 会从 eeprom 加载配置参数
完成初始化过程

文件中有对应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实现 Ethercat 从站源码.rar (1.19 MB, 下载次数: 98)
UC16-R1.rar (4.54 KB, 下载次数: 53)

作者: zhaomingli    时间: 2023-2-16 16:23
EtherCAT从站开发板及源程序:
简化XML生成,简化编程,10分钟快速入门,详细见:
http://www.openedv.com/forum.php?mod=viewthread&tid=340287

作者: shiman999    时间: 2023-3-31 08:50
楼主,你好!STM32实现EtherCat从站源码,看不出从那体现出来。能否详细解说一下,谢谢!
作者: yahuiwang    时间: 2024-8-7 11:19
受教了,谢谢分享
作者: huaishang    时间: 2025-1-1 19:21
受教了,谢谢分享
作者: suroy    时间: 2025-1-2 00:06
goodjob




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1