没有合适的资源?快使用搜索试试~ 我知道了~
首页uC-Modbus源码指南.pdf
Modbus通讯协议最早由Modicon公司开发,是一种采用主从通信模式,即只有主机可以发起请求,从站设备通过向主机提供请求的数据或执行查询中请求的操作作为响应,广泛应用于工业现场的总线协议。 µC/Modbus是modbus ASCII RTU 主机模式和从机模式的开源C。 µC/Modbus配有µC/Modbus RTOS接口层,以便您可以开始使用µC/Modbus,如果您还使用µC-OS-II或µC-OS-III在您的产品中使用,或者将此接口层作为您自己的RTOS的示例。 µC/Modbus V2.13.00 (µC/Modbus-S and µC/Modbus-M) User’s Manual This document describes µC/Modbus, which implements the Modicon Modbus Protocol (referred to as Modbus) along with the “Daniel’s Extension” to the Modbus protocol, as specified by Daniel Flow Products.
资源详情
资源评论
资源推荐

µC/Modbus
2
Table of Contents
Revision History ................................................................................. 5
1.00 Introduction ......................................................................................... 6
1.01 Topologies .......................................................................................... 8
1.02 µC/Modbus Architecture ............................................................... 10
2.00 Directories and Files ........................................................................ 13
2.01 Directories and Files, Target Independent Source Code ................. 13
2.02 Directories and Files, RTOS Interface .............................................. 14
2.03 Directories and Files, Product Specific Files .................................... 15
2.04 Directories and Files, CPU and Compiler Specific Files ................... 15
3.00 Using µC/Modbus .......................................................................... 17
3.01 Using µC/Modbus, MB_CfgCh() .................................................... 20
3.02 Using µC/Modbus, MB_ChToPortMap() ........................................ 22
3.03 Using µC/Modbus, MB_Exit() ........................................................ 23
3.04 Using µC/Modbus-M, MBM_FC01_CoilRd() ................................. 24
3.05 Using µC/Modbus-M, MBM_FC02_DIRd() .................................... 26
3.06 Using µC/Modbus-M, MBM_FC03_HoldingRegRd() ..................... 28
3.07 Using µC/Modbus-M, MBM_FC03_HoldingRegRdFP() ................ 30
3.08 Using µC/Modbus-M, MBM_FC04_InRegRd() .............................. 32
3.09 Using µC/Modbus-M, MBM_FC05_CoilWr() ................................. 34
3.10 Using µC/Modbus-M, MBM_FC06_HoldingRegWr() ..................... 36
3.11 Using µC/Modbus-M, MBM_FC06_HoldingRegWrFP() ................ 38
3.12 Using µC/Modbus-M, MBM_FC08_Diag() ..................................... 40
3.13 Using µC/Modbus-M, MBM_FC15_CoilWr() ................................. 42
3.14 Using µC/Modbus-M, MBM_FC16_HoldingRegWrN () ................. 44
3.15 Using µC/Modbus-M, MBM_FC16_HoldingRegWrNFP() ............. 46
3.16 Using µC/Modbus, MB_Init() ......................................................... 48
3.17 Using µC/Modbus, MB_ModeSet() ................................................ 49
3.18 Using µC/Modbus-S, MB_NodeAddrSet() ..................................... 50
3.19 Using µC/Modbus-S, MB_WrEnSet() ............................................ 51
4.00 Configuring µC/Modbus ................................................................. 52
4.01 Configuring µC/Modbus, MODBUS_CFG_SLAVE_EN ................. 52
4.02 Configuring µC/Modbus, MODBUS_CFG_MASTER_EN .............. 52
4.03 Configuring µC/Modbus, MODBUS_CFG_ASCII_EN ................... 52

µC/Modbus
3
4.04 Configuring µC/Modbus, MODBUS_CFG_RTU_EN ..................... 53
4.05 Configuring µC/Modbus, MODBUS_CFG_MAX_CH ..................... 53
4.06 Configuring µC/Modbus, MODBUS_CFG_BUF_SIZE .................. 53
4.07 Configuring µC/Modbus, MODBUS_CFG_FP_EN ........................ 53
4.08 Configuring µC/Modbus, MODBUS_CFG_FP_START_IX ............ 53
4.09 Configuring µC/Modbus, MODBUS_CFG_FC01_EN .................... 54
4.10 Configuring µC/Modbus, MODBUS_CFG_FC02_EN .................... 54
4.11 Configuring µC/Modbus, MODBUS_CFG_FC03_EN .................... 54
4.12 Configuring µC/Modbus, MODBUS_CFG_FC04_EN .................... 54
4.13 Configuring µC/Modbus, MODBUS_CFG_FC05_EN .................... 54
4.14 Configuring µC/Modbus, MODBUS_CFG_FC06_EN .................... 54
4.15 Configuring µC/Modbus, MODBUS_CFG_FC08_EN .................... 55
4.16 Configuring µC/Modbus, MODBUS_CFG_FC15_EN .................... 55
4.17 Configuring µC/Modbus, MODBUS_CFG_FC16_EN .................... 55
4.18 Configuring µC/Modbus-S, MODBUS_CFG_FC20_EN ................ 55
4.19 Configuring µC/Modbus-S, MODBUS_CFG_FC21_EN ................ 55
4.20 Configuring µC/Modbus, RAM Memory Requirements ................. 56
5.00 µC/Modbus-S, Accessing application data .................................... 57
5.01 µC/Modbus-S, MB_CoilRd() .......................................................... 58
5.02 µC/Modbus-S, MB_CoilWr() .......................................................... 60
5.03 µC/Modbus-S, MB_DIRd() ............................................................ 62
5.04 µC/Modbus-S, MB_InRegRd() ...................................................... 64
5.05 µC/Modbus-S, MB_InRegRdFP() .................................................. 66
5.06 µC/Modbus-S, MB_HoldingRegRd() ............................................. 68
5.07 µC/Modbus-S, MB_HoldingRegRdFP() ........................................ 70
5.08 µC/Modbus-S, MB_HoldingRegWr() ............................................. 72
5.09 µC/Modbus-S, MB_HoldingRegWrFP() ........................................ 74
5.10 µC/Modbus-S, MB_FileRd() .......................................................... 76
5.11 µC/Modbus-S, MB_FileWr() .......................................................... 78
6.00 Board Support Package (BSP) ......................................................... 80
6.01 BSP, MB_CommExit() ...................................................................... 80
6.02 BSP, MB_CommPortCfg() ................................................................ 81
6.03 BSP, MB_CommRxTxISR_x_Handler() ........................................... 82
6.04 BSP, MB_CommRxIntEn() ............................................................... 83
6.05 BSP, MB_CommRxIntDis() .............................................................. 83
6.06 BSP, MB_CommTx1() ...................................................................... 83
6.07 BSP, MB_CommTxIntEn()................................................................ 84
6.08 BSP, MB_CommTxIntDis() ............................................................... 84

µC/Modbus
4
6.09 BSP, MB_RTU_TmrInit() .................................................................. 85
6.10 BSP, MB_RTU_TmrExit() ................................................................. 85
6.11 BSP, MB_RTU_TmrISR_Handler() .................................................. 85
7.00 RTOS Interface ................................................................................ 86
7.01 RTOS Interface, MB_OS_Init() ......................................................... 89
7.02 RTOS Interface, MB_OS_Exit() ........................................................ 90
7.03 RTOS Interface, MB_OS_RxSignal() ............................................... 91
7.04 RTOS Interface, MB_OS_RxWait() .................................................. 92
7.05 RTOS Interface, Configuration ......................................................... 93
8.00 No-OS Interface ............................................................................... 94
9.00 µC/Modbus Program Flow ............................................................. 97
9.01 µC/Modbus-S, ASCII Rx and Tx .................................................. 98
9.02 µC/Modbus-S, RTU Rx and Tx .................................................. 100
9.03 µC/Modbus-M, ASCII Rx and Tx................................................ 102
9.04 µC/Modbus-M, RTU Rx and Tx .................................................. 104
10.00 Acronyms, Abbreviations and Mnemonics ..................................... 106
Licensing 108
References 108
Contacts 108

µC/Modbus
5
Revision History
Version
Date
Description
V1.00
2004/09/08
Initial Release
V1.61
2005/07/29
Converted code to use µC/CPU files.
Removed dependencies on ‘stdlib’ functions.
Improved the architecture.
V2.00
2006/05/15
Simplified the code.
Made error return codes 16 bits instead of 8.
Added support for Modbus Master.
V2.10
2006/08/10
Corrected bug with Modbus ASCII LRC calculation. LRC was being computed
on ‘binary’ data instead of the raw ASCII message. Our test tool was
incorrectly calculating LRCs on the binary data and we followed the same
scheme.
Removed all calls to MB_TxErrChkCalc() since the LRC and CRC
calculations for Tx are done just before transmitting the response.
V2.11
2008/11/14
Added single thread support for Modbus Slave.
V2.12
2009/02/02
Now checking for ‘broadcast’ messages in Modbus Slave. We simply execute
the command but we don’t reply.
We also added a check so we don’t read more registers than can fit in a
frame.
V2.13.00
2012/05/17
Corrected bugs, changed version numbering system, improved MISRA-
C:2004 rules support, corrected style issues.
剩余107页未读,继续阅读
















安全验证
文档复制为VIP权益,开通VIP直接复制

评论0