MB_CfgCh()
This function is used to configure each Modbus channel in your product. MB_CfgCh()
MUST be called AFTER calling MB_Init()
. The function prototype is:
Prototype
MODBUS_CH *MB_CfgCh (CPU_INT08U node_addr, CPU_INT08U master_slave, CPU_INT32U rx_timeout, CPU_INT08U modbus_mode, CPU_INT08U port_nbr, CPU_INT32U baud, CPU_INT08U bits, CPU_INT08U parity, CPU_INT08U stops, CPU_INT08U wr_en);
Arguments
node_addr
is the node address of the channel as seen by the Modbus master connected to your product. Each channel can be ‘seen’ as having the same node address or have different node addresses for each channel.
master_slave
specifies whether this channel is a Modbus Master or a Modbus Slave. Values for this argument can either be MODBUS_MASTER
or MODBUS_SLAVE
.
rx_timeout
specifies the amount of time that a Modbus master will wait for a response from a slave. The time is specified in RTOS ticks (consult your RTOS documentation to determine the tick rate).
modbus_mode
specifies the operating mode (ASCII or RTU) and thus, this argument can either be: MODBUS_MODE_ASCII
or MODBUS_MODE_RTU
.
port_nbr
specifies which physical connection (i.e. port) is associated with the Modbus channel. In other words, it determines which UART will be associated with the Modbus channel. port_nbr
are typically assigned from 0
to the maximum number of physical UARTs you have in your product minus one. For example, if your product has 4 UARTs and all of them can be assigned to a Modbus channel then the UARTs would be numbered from 0
to 3
. However, you don’t have to number them from 0, the numbering scheme really depends on who writes the MB_BSP.C
file.
baud
is the baud rate of the Modbus channel. You would typically specify a ‘standard’ baud rate such as 9600
, 19200
, 38400
, etc.
bits
specifies the number of data bits used by the UART. For RTU, you’d typically specify 8
. For ASCII, you can either specify 7
or 8
. If you specify 7 bits, you will probably also need to specify the parity (see next argument).
parity
specifies the type of parity checking used when you use Modbus ASCII mode (if you want to use parity checking). Allowable values for this argument are:
MODBUS_PARITY_NONE
,
MODBUS_PARITY_ODD
and
MODBUS_PARITY_EVEN
.
stops
specifies the number of stop bits used by the UART. You can either specify 1 or 2. The typical value is 1 but check with the Modbus master node to see if you need to specify 2.
wr_en
this argument specifies whether a Modbus master is allowed to send ‘write’ commands to this Modbus channel. This argument can either be MODBUS_WR_EN
or MODBUS_WR_DIS
. In other words, if you don’t want a Modbus master to change values in your product, simply specify MODBUS_WR_DIS
. Note that your application code can actually change this setting at run-time by calling MB_WrEnSet()
(see section 3.06).
Returned Value
The function returns a pointer to the created channel which you can use when calling other functions.
Notes / Warnings
None
Called By
Your Modbus master or slave application.