FreeModbus 精简版本(Only RTU) for M128 (Modbus Slave)

1、硬件连接:
M128
PD3 INT3/TXD1  ---> PC 232COM Pin 2
PD2 INT2/RXD1  ---> PC 232COM Pin 3
GND                  ---> PC 232COM Pin 5

image

image

2、Modbus Poll软件配置:
软件下载地址:http://www.cnblogs.com/worldsing/p/3231855.html

9600 8 N 1 与 Modbus Poll连接地址为1 , M128时钟为8M

image

 

image

3、状态:
通信过程中PA7 LED闪烁

4、代码信息:只留RTU模式 优化代码

image

ModbusUser.c      用记功能代码
ModbusFun.c       整合FreeModbus的功能c代码文件;
ModbusRTU.c       Modbus的RTU模式桢处理,整理FreeModbus去除ASCII模式;
ModbusPort.c      关于硬件的移植包括串口、定时器、桢队列功能实现(目前是单桢处理);
                  (此文件是ATMEGA128硬件的代码,其它CPU需要自己移植)

FreeModBus会功能打开时IAR 5.40环境下 代码尺寸为:
5 287 bytes of CODE memory (+ 12 range fill )
941 bytes of DATA memory (+ 14 absolute )
#define MB_FUNC_HANDLERS_MAX                    ( 16 )//使用的功能码数量

#define MB_FUNC_OTHER_REP_SLAVEID_BUF           ( 8 )

#define MB_FUNC_OTHER_REP_SLAVEID_ENABLED       (  1 ) //报告从设备功能

#define MB_FUNC_READ_INPUT_ENABLED              (  1 ) //读输入寄存器功能

#define MB_FUNC_READ_HOLDING_ENABLED            (  1 ) //读保持寄存器功能

#define MB_FUNC_WRITE_HOLDING_ENABLED           (  1 ) //写操持寄存存功能

#define MB_FUNC_WRITE_MULTIPLE_HOLDING_ENABLED  (  1 )//写多个操持寄存存功能

#define MB_FUNC_READ_COILS_ENABLED              (  1 )//读线圈

#define MB_FUNC_WRITE_COIL_ENABLED              (  1 )//写线圈

#define MB_FUNC_WRITE_MULTIPLE_COILS_ENABLED    (  1 )//写多个线圈

#define MB_FUNC_READ_DISCRETE_INPUTS_ENABLED    (  1 )//读离散输入

#define MB_FUNC_READWRITE_HOLDING_ENABLED       (  1 )//读写多个寄存器

 

代码下载:http://pan.baidu.com/share/link?shareid=3612729954&uk=2483252218

posted on 2013-08-05 10:57  Worldsing  阅读(2292)  评论(0编辑  收藏  举报