ImageVerifierCode 换一换
格式:DOCX , 页数:12 ,大小:19.94KB ,
资源ID:5975674      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/5975674.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(实验5485总线及Modbus通讯协议实验.docx)为本站会员(b****5)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

实验5485总线及Modbus通讯协议实验.docx

1、实验5485总线及Modbus通讯协议实验课程名称:嵌入式软件技术开课机房:11号机房 2012年4月24日星期二8:1011:35 专业班级通信09(2 )班 学号Xb07680215姓名夏陆豪实验项目名称实验5485总线及Modbus通讯协议实验指导教师陈玮一、实验任务与实验目的 实验目的1. 了解Modbus协议及其应用2. 了解freeModbus库及其移植方法3. 掌握Modbus协议中常用命令的应用实验任务1. 将开源Modbus协议库freeModbus移植到EASY ARM8962开发板上二、报告内容 Freemodbus是modbus协议在嵌入式处理器上的实现。包括AVR,P

2、IC,WIN32等等平台。它是开放性源代码,可用于商业目的。它实现了Modbus RTU/ASCII、TCP三种传输方式,当前版本是1.5,支持以下功能: 读输入寄存器 (0x04) 读保持寄存器 (0x03) 写单个寄存器 (0x06) 写多个寄存器 (0x10) 读/写多个寄存器 (0x17) 读取线圈状态 (0x01) 写单个线圈 (0x05) 写多个线圈 (0x0F) 读输入状态 (0x02) 报告从机标识 (0x11)本实现基于最新的标准并且与标准完全兼容。接收和传输Modbus RTU/ASCII数据帧是通过一个由硬件提取层的调用来驱动状态机实现的。这就使得协议非常容易移植到其他的

3、平台之上。当接收一个完整的数据帧后,该数据帧被传入Modbus应用层,数据帧的内容在该层内得到解析。为方便地增加新的Modbus功能,Freemodbus在应用层提供了钩子函数Hooks。如果用到了Modbus TCP协议,那么当准备处理一个新数据帧的时候,移植层就必须首先向协议层发送一个事件标志。然后,协议栈调用一个返回值为接收到的Modbus TCP数据帧的函数,并且开始处理这个数据帧。如果数据有效,则响应的Modbus反馈帧将提供给移植层生成反馈帧。最后,该反馈帧被发送到客户端。二、实现FreeModbus协议所需要的软/硬件需求Modbus协议对硬件的需求非常少基本上任何具有串行接口,

4、并且有一些能够容纳modbus数据帧的RAM的微控制器都足够了。 一个异步串行接口,能够支持接收缓冲区满和发送缓存区空中断。 一个能够产生RTU传输所需要的t3.5 字符超时定时器的时钟。对于软件部分,仅仅需要一个简单的事件队列。 The STR71X/FreeRTOS 移植使用 FreeRTOS 队列作为事件队列来减少 Modbus 任务所需要的时间。小点的微控制器往往不允许使用操作系统,在那种情况下,可以使用一个全局变量来实现该事件队列(The Atmel AVR 移植使用这种方式实现)。实际的存储器需求决定于所使用的 Modbus 模块的多少。下表列出了所支持的功能编译后所需要的存储器。

5、 ARM 项数值是使用 GNUARM 编译器 3.4.4 使用 -O1 选项得到的。 AVR项数值是使用 WinAVR 编译器 3.4.5 使用 -Os 选项编译得到的。ModuleARM CodeARM RAM (static)AVR CodeAVR RAM (static)Modbus RTU (Required)1132Byte272Byte1456Byte266ByteModbus ASCII (Optional)1612Byte28Byte1222Byte16ByteModbus Functions 11180Byte34Byte1602Byte34ByteModbus Core (

6、Required)924Byte180Byte608Byte75BytePorting Layer (Required 2)1756Byte16Byte704Byte7ByteTotals7304Byte530Byte5592Byte398Byte1:实际大小决定于可支持的Modbus功能码的多少。 功能码可以在头文件mbconfig.h中进行配置。2:决定于硬件。已完成的移植:Cortex M3 devices: Atmel AT91SAM3S.ARM devices: STR71X with FreeRTOS/GCC. See STR71X/simple2.c for an example

7、. STR71TCP with FreeRTOS/lwIP/GCC. This port includes FreeRTOS, lwIP and a fully working PPP stack. The lwIP, PPP and FreeRTOS part is generic and therefore can be used for other ports ( or other projects ). LPC214X with Keil. See LPC214X/demo.c for an example. This port uses the Keil ARM Compiler 2

8、.41. AT91SAM7X with FreeRTOS/Rowley. See AT91SAM7X_ROWLEY/demo.c for an example.AVR devices: ATMega8/16/32/128/168/169 with WinAVR. See AVR/demo.c for an example.Coldfire devices: MCF5235 with GCC. See MCF5235/demo.c for an example. MCF5235 with CodeWarrior and FreeRTOS port for ColdFire. See MCF523

9、5CW/demo.c for an example. MCF5235/TCP with GCC. This port features FreeRTOS and the lwIP stack. The lwIP part is generic and therefore it should be used as a basis for other lwIP ports.MSP430 devices MSP430F169 with Rowley Crossworks. See MSP430/demo.c for an example. MSP430F169 with GCC. See MSP43

10、0/demo.c for an example.Z8Encore devices Z8F6422 and Z8F1622 port. See Z8ENCORE/demo.c for an example. The port uses ZDS II - Z8 Encore! 4.10.1 as development environment.Win32: A Win32 Modbus RTU/ASCII Port. A Win32 Modbus/TCP Port.Linux: A Linux (uCLinux or other distributions) Modbus RTU/ASCII Po

11、rt.任务一PortTimer.c中:xMBPortTimersInit( USHORT usTim1Timerout50us ) 负责配置一个时基,vMBPortTimersEnable( ) 启用这个时基。比如执行:xMBPortTimersInit( 10000 );vMBPortTimersEnable( );Port.c/* - System includes -*/#include hw_types.h#include interrupt.h /zd/* - Modbus includes -*/* - Variables -*/int VIC_Temp;/* - Start im

12、plementation -*/void EnterCriticalSection() IntMasterDisable(); /* Disable Interruptions _zd */void ExitCriticalSection() IntMasterEnable(); /* Enable Interruptions _zd */PortSerial.c/* * FreeModbus Libary: LM3S Port * Copyright (C) 2007 Tiago Prado Lone * * This library is free software; you can re

13、distribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY

14、WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Softwa

15、re * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * File: $Id: portserial.c,v 1.1 2007/04/24 23:15:18 wolti Exp $ */#include hw_memmap.h#include hw_ints.h #include hw_types.h#include sysctl.h#include hw_uart.h#include gpio.h#include interrupt.h#include uart.h/*-*/#inclu

16、de port.h/* - Modbus includes -*/#include mb.h#include mbport.h/* - Start implementation -*/void vMBPortSerialEnable(BOOL xRxEnable, BOOL xTxEnable) if (TRUE = xRxEnable) UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT); else UARTIntDisable(UART0_BASE, UART_INT_RX | UART_INT_RT); if (TRUE = xTxE

17、nable) UARTIntEnable(UART0_BASE, UART_INT_TX); else UARTIntDisable(UART0_BASE, UART_INT_TX); void vMBPortClose(void) UARTIntDisable(UART0_BASE, UART_INT_RX | UART_INT_RT | UART_INT_TX); IntEnable (INT_UART0);BOOL xMBPortSerialInit(UCHAR ucPORT, ULONG ulBaudRate, UCHAR ucDataBits, eMBParity eParity)

18、/* UCHAR PORT; ULONG BaudRate; UCHAR DataBits; eMBParity Parity; PORT = ucPORT; BaudRate = ulBaudRate; DataBits = ucDataBits; Parity = eParity; */ SysCtlPeripheralEnable (SYSCTL_PERIPH_UART0); SysCtlPeripheralEnable (SYSCTL_PERIPH_GPIOA); GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); /

19、Configure the UART for ulBaudRate, 8-EVEN-1 operation. UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), ulBaudRate, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_EVEN); / Enable the UART interrupt. IntEnable (INT_UART0); UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT | UART_INT_

20、TX); return TRUE;BOOL xMBPortSerialPutByte(CHAR ucByte) UARTCharPutNonBlocking(UART0_BASE, ucByte); return TRUE;BOOL xMBPortSerialGetByte(CHAR * pucByte) *pucByte = UARTCharGetNonBlocking(UART0_BASE); return TRUE;/* * Create an interrupt handler for the transmit buffer empty interrupt * (or an equiv

21、alent) for your target processor. This function should then * call pxMBFrameCBTransmitterEmpty( ) which tells the protocol stack that * a new character can be sent. The protocol stack will then call * xMBPortSerialPutByte( ) to send the character. */static void prvvUARTTxReadyISR(void) pxMBFrameCBTr

22、ansmitterEmpty();/* * Create an interrupt handler for the receive interrupt for your target * processor. This function should then call pxMBFrameCBByteReceived( ). The * protocol stack will then call xMBPortSerialGetByte( ) to retrieve the * character. */static void prvvUARTRxISR(void) pxMBFrameCBBy

23、teReceived();/ UART INT HANDLER ZDvoid UART0IntHandler(void) unsigned long ulStatus; ulStatus = UARTIntStatus(UART0_BASE, true); UARTIntClear(UART0_BASE, ulStatus); if (ulStatus & (UART_INT_RT | UART_INT_RX) prvvUARTRxISR(); if (ulStatus & UART_INT_TX) prvvUARTTxReadyISR(); /* * FreeModbus Libary: L

24、M3S Port * Copyright (C) 2007 Tiago Prado Lone * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later ver

25、sion. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the G

26、NU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * File: $Id: porttimer.c,v 1.1 2007/04/24 23:15:18 wolti Exp $ */PortTimer.c#include hw_memmap.h#include hw_ints.h#include hw_ty

27、pes.h#include sysctl.h#include interrupt.h#include hw_timer.h#include hw_types.h#include gpio.h#include timer.h/* - Platform includes -*/#include port.h/* - Modbus includes -*/#include mb.h#include mbport.h/* - Start implementation -*/BOOL xMBPortTimersInit(USHORT usTim1Timerout50us) SysCtlPeriphera

28、lEnable (SYSCTL_PERIPH_TIMER0); GPIOPinTypeTimer(TIMER0_BASE, TIMER_A); TimerConfigure(TIMER0_BASE, TIMER_CFG_32_BIT_PER); TimerLoadSet(TIMER0_BASE, TIMER_A, (SysCtlClockGet() / 20000) * usTim1Timerout50us); TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); TimerEnable(TIMER0_BASE, TIMER_A); IntEnable (INT_TIMER0A); return TRUE;void vMBPortTimersEnable() TimerEnable(TIMER0_BASE, TIMER_A);void vMBPortTimersDisable() TimerDisable(TIMER0_BASE, TIMER_A);void TIMERExpiredISR(void) (void

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1