Modbus001 start address

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Not applicable
Hi,

I have just started with the implementation of a MODBUS RTU slave according to DAVE3 app MODBUS001_Example.

By using the callback function " MyHoldingCB" in the Example2, I always receive with the variable "usAddress" with a value bigger by 1 as my adjusted address.
Here the declaration of this function:
eMBErrorCode MyHoldingCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNRegs, eMBRegisterMode eMode );

Has some one recognised the same behavior or can explain the reason for that?

Thanks,
0 Likes
3 Replies
Not applicable
Maybe this behavior caused by the Modbus-Master system. In some documents I have found " 0-based, 1-based, addressing style".
I'm using the Modbus Devices Tester by Global Multimedia.
0 Likes
Travis
Employee
Employee
First solution authored Welcome! 500 replies posted
Hi abkai,

From the software function, it seems quite reasonable for the "usAddress" to be more than value 1 else it is consider an error. Did you manage to get into the switch (eMode)?

if( ( usAddress >= REG_HOLDING_START ) &&
( usAddress + usNRegs <= REG_HOLDING_START + REG_HOLDING_NREGS ) )
{
iRegIndex = ( int )( usAddress - usRegHoldingStart );
switch ( eMode )
{
/* Pass current register values to the protocol stack. */
case MB_REG_READ:
0 Likes
Not applicable
Hi Travis,

If I understand you right, the address will start from 1.
On my MODBUS Master system I can choose the address range (starting form 0 or 1). When the Master systems starts from 1 anything is fine. But if I choose the start address from 0, I could not adjust this in the MODBUS functions. I have to handle this in my application code.
In the main.c software from Dave3 example the start address is set to 1 (usRegHoldingStart=1) but when you chamge it to 0 or another value it has no influance on the MOSBUS function.
0 Likes