找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2824|回复: 2
打印 上一主题 下一主题
收起左侧

STM32实现 Ethercat 从站源码

[复制链接]
跳转到指定楼层
楼主
ID:647576 发表于 2022-3-29 18:37 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
该源码是当前流行的机器人控制系统倍福所采用的构架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, 下载次数: 84)
UC16-R1.rar (4.54 KB, 下载次数: 44)

评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏3 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:145349 发表于 2023-2-16 16:23 | 只看该作者
EtherCAT从站开发板及源程序:
简化XML生成,简化编程,10分钟快速入门,详细见:
http://www.openedv.com/forum.php?mod=viewthread&tid=340287
回复

使用道具 举报

板凳
ID:1068936 发表于 2023-3-31 08:50 | 只看该作者
楼主,你好!STM32实现EtherCat从站源码,看不出从那体现出来。能否详细解说一下,谢谢!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表