Micriµm
© Copyright 2008-2012, Micriµm
All Rights reserved
µC/Modbus
V2.13.00
(µC/Modbus-S and
µC/Modbus-M)
User’s Manual
www.Micrium.com
µC/Modbus
Table of Contents
Revision History ................................................................................. 5
1.00
1.01
1.02
2.00
2.01
2.02
2.03
2.04
3.00
3.01
3.02
3.03
3.04
3.05
3.06
3.07
3.08
3.09
3.10
3.11
3.12
3.13
3.14
3.15
3.16
3.17
3.18
3.19
4.00
4.01
4.02
4.03
Introduction ......................................................................................... 6
Topologies .......................................................................................... 8
µC/Modbus
Architecture ............................................................... 10
Directories and Files ........................................................................ 13
Directories and Files, Target Independent Source Code ................. 13
Directories and Files, RTOS Interface .............................................. 14
Directories and Files, Product Specific Files .................................... 15
Directories and Files, CPU and Compiler Specific Files ................... 15
Using
µC/Modbus
.......................................................................... 17
Using
µC/Modbus,
MB_CfgCh() .................................................... 20
Using
µC/Modbus,
MB_ChToPortMap() ........................................ 22
Using
µC/Modbus,
MB_Exit() ........................................................ 23
Using
µC/Modbus-M,
MBM_FC01_CoilRd() ................................. 24
Using
µC/Modbus-M,
MBM_FC02_DIRd() .................................... 26
Using
µC/Modbus-M,
MBM_FC03_HoldingRegRd() ..................... 28
Using
µC/Modbus-M,
MBM_FC03_HoldingRegRdFP() ................ 30
Using
µC/Modbus-M,
MBM_FC04_InRegRd() .............................. 32
Using
µC/Modbus-M,
MBM_FC05_CoilWr() ................................. 34
Using
µC/Modbus-M,
MBM_FC06_HoldingRegWr() ..................... 36
Using
µC/Modbus-M,
MBM_FC06_HoldingRegWrFP() ................ 38
Using
µC/Modbus-M,
MBM_FC08_Diag() ..................................... 40
Using
µC/Modbus-M,
MBM_FC15_CoilWr() ................................. 42
Using
µC/Modbus-M,
MBM_FC16_HoldingRegWrN () ................. 44
Using
µC/Modbus-M,
MBM_FC16_HoldingRegWrNFP() ............. 46
Using
µC/Modbus,
MB_Init() ......................................................... 48
Using
µC/Modbus,
MB_ModeSet() ................................................ 49
Using
µC/Modbus-S,
MB_NodeAddrSet() ..................................... 50
Using
µC/Modbus-S,
MB_WrEnSet() ............................................ 51
Configuring
µC/Modbus
................................................................. 52
Configuring
µC/Modbus,
MODBUS_CFG_SLAVE_EN ................. 52
Configuring
µC/Modbus,
MODBUS_CFG_MASTER_EN .............. 52
Configuring
µC/Modbus,
MODBUS_CFG_ASCII_EN ................... 52
2
µC/Modbus
4.04
4.05
4.06
4.07
4.08
4.09
4.10
4.11
4.12
4.13
4.14
4.15
4.16
4.17
4.18
4.19
4.20
5.00
5.01
5.02
5.03
5.04
5.05
5.06
5.07
5.08
5.09
5.10
5.11
6.00
6.01
6.02
6.03
6.04
6.05
6.06
6.07
6.08
Configuring
µC/Modbus,
MODBUS_CFG_RTU_EN ..................... 53
Configuring
µC/Modbus,
MODBUS_CFG_MAX_CH ..................... 53
Configuring
µC/Modbus,
MODBUS_CFG_BUF_SIZE .................. 53
Configuring
µC/Modbus,
MODBUS_CFG_FP_EN ........................ 53
Configuring
µC/Modbus,
MODBUS_CFG_FP_START_IX ............ 53
Configuring
µC/Modbus,
MODBUS_CFG_FC01_EN .................... 54
Configuring
µC/Modbus,
MODBUS_CFG_FC02_EN .................... 54
Configuring
µC/Modbus,
MODBUS_CFG_FC03_EN .................... 54
Configuring
µC/Modbus,
MODBUS_CFG_FC04_EN .................... 54
Configuring
µC/Modbus,
MODBUS_CFG_FC05_EN .................... 54
Configuring
µC/Modbus,
MODBUS_CFG_FC06_EN .................... 54
Configuring
µC/Modbus,
MODBUS_CFG_FC08_EN .................... 55
Configuring
µC/Modbus,
MODBUS_CFG_FC15_EN .................... 55
Configuring
µC/Modbus,
MODBUS_CFG_FC16_EN .................... 55
Configuring
µC/Modbus-S,
MODBUS_CFG_FC20_EN ................ 55
Configuring
µC/Modbus-S,
MODBUS_CFG_FC21_EN ................ 55
Configuring
µC/Modbus,
RAM Memory Requirements ................. 56
µC/Modbus-S,
Accessing application data .................................... 57
µC/Modbus-S,
MB_CoilRd().......................................................... 58
µC/Modbus-S,
MB_CoilWr() .......................................................... 60
µC/Modbus-S,
MB_DIRd() ............................................................ 62
µC/Modbus-S,
MB_InRegRd() ...................................................... 64
µC/Modbus-S,
MB_InRegRdFP() .................................................. 66
µC/Modbus-S,
MB_HoldingRegRd() ............................................. 68
µC/Modbus-S,
MB_HoldingRegRdFP() ........................................ 70
µC/Modbus-S,
MB_HoldingRegWr() ............................................. 72
µC/Modbus-S,
MB_HoldingRegWrFP() ........................................ 74
µC/Modbus-S,
MB_FileRd() .......................................................... 76
µC/Modbus-S,
MB_FileWr() .......................................................... 78
Board Support Package (BSP) ......................................................... 80
BSP, MB_CommExit() ...................................................................... 80
BSP, MB_CommPortCfg() ................................................................ 81
BSP, MB_CommRxTxISR_x_Handler() ........................................... 82
BSP, MB_CommRxIntEn() ............................................................... 83
BSP, MB_CommRxIntDis() .............................................................. 83
BSP, MB_CommTx1() ...................................................................... 83
BSP, MB_CommTxIntEn()................................................................ 84
BSP, MB_CommTxIntDis() ............................................................... 84
3
µC/Modbus
6.09
6.10
6.11
7.00
7.01
7.02
7.03
7.04
7.05
8.00
9.00
9.01
9.02
9.03
9.04
10.00
Licensing
References
Contacts
BSP, MB_RTU_TmrInit() .................................................................. 85
BSP, MB_RTU_TmrExit() ................................................................. 85
BSP, MB_RTU_TmrISR_Handler() .................................................. 85
RTOS Interface ................................................................................ 86
RTOS Interface, MB_OS_Init() ......................................................... 89
RTOS Interface, MB_OS_Exit()........................................................ 90
RTOS Interface, MB_OS_RxSignal() ............................................... 91
RTOS Interface, MB_OS_RxWait() .................................................. 92
RTOS Interface, Configuration ......................................................... 93
No-OS Interface ............................................................................... 94
µC/Modbus
Program Flow ............................................................. 97
µC/Modbus-S,
ASCII Rx and Tx .................................................. 98
µC/Modbus-S,
RTU Rx and Tx .................................................. 100
µC/Modbus-M,
ASCII Rx and Tx................................................ 102
µC/Modbus-M,
RTU Rx and Tx .................................................. 104
Acronyms, Abbreviations and Mnemonics ..................................... 106
108
108
108
4
µC/Modbus
Revision History
Version
V1.00
V1.61
Date
2004/09/08
2005/07/29
Initial Release
Description
Converted code to use
µC/CPU
files.
Removed dependencies on ‘stdlib’ functions.
Improved the architecture.
Simplified the code.
Made error return codes 16 bits instead of 8.
Added support for Modbus Master.
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.
Added single thread support for Modbus Slave.
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.
Corrected bugs, changed version numbering system, improved MISRA-
C:2004 rules support, corrected style issues.
V2.00
2006/05/15
V2.10
2006/08/10
V2.11
V2.12
2008/11/14
2009/02/02
V2.13.00
2012/05/17
5