So, we have connected 2 Nano with RS485, without anything else.
We configured the master with no protocol, and the slave with RTU protocol.
the on-line monitoring and view variable is file attached.
The problem is concerning the last byte of the outcom frame , you can see it in the docklight view.
Master :
1st scan :
SETPROTOCOL 1,10
SETBAUD 1,&H13
REFRESH
RETURN
Every scan :
DM[1] = &H03 ' node address of slave
DM[2] = &H03 ' function 03
DM[3] = &H00 ' upper 8 bit of address
DM[4] = &H01 ' lower 8 bit of address
DM[5] = &H00 ' upper 8 bit of count
DM[6] = &H01 ' lower 8 bit of count
//X = CRC16 (DM[1],6) & &HFFFF ' compute the CRC16 of DM[1] to DM[6]
DM[7] = 212 //X / 256 ' upper 8 bit of CRC16
DM[8] = 40 // & &HFF ' lower 8 bit of CRC16
FOR I = 1 to 8 ' send out the MODBUS RTU command in binary
OUTCOMM 1, DM[0+I]
NEXT
DELAY(100) ' delay for a while to wait for response (30)
FOR I = 1 to 8 ' get rest of response
DM[10+I] = INCOMM (1)
NEXT
IF DM[1]=DM[11] and DM[2]=DM[12] and DM[13]=2 and DM[16]=193 and DM[17]=132
else
DM[20]=DM[20]+1
ENDIF
DM[21]=DM[21]+1
B=DM[14]*256 + DM[15]
DM[40]=B*66/1000
REFRESH
IF DM[14]<0 OR DM[15]<0 THEN
DM[22]=DM[22]+1
ELSE
DM[22]=0
ENDIF
IF DM[22]=1 THEN
DM[31]=DM[40]
DM[23]=DM[23]+1
ENDIF
IF DM[22]=2 THEN
DM[32]=DM[40]
DM[24]=DM[24]+1
ENDIF
IF DM[22]=3 tHEN
DM[33]=DM[40]
DM[25]=DM[25]+1
ENDIF
IF DM[22]=4 tHEN
DM[34]=DM[40]
DM[26]=DM[26]+1
ENDIF
IF DM[22]=5 THEN
SETIO OUT3
DM[35]=DM[40]
PAUSE
ENDIF
Slave :
SETPROTOCOL 1,1
SETBAUD 1,&H13
REFRESH
RETURN