View previous topic :: View next topic |
Author |
Message |
georgestheking
Joined: 06 May 2005 Posts: 134
|
Posted: Sun Aug 23, 2015 2:14 pm Post subject: Modbus 4 read multiple inputs |
|
|
Hi,
I want tu use "Print Makemodbus(1 , 4 , 43 , "
But it is not possible Bascom AVR does not have Modbus funtion 4 only 3,6 and 16.
Can I use the Bascom CRC16 to make myself the right Modbus message ?
Thanks for all
Best regards
Georges
(BASCOM-AVR version : 2.0.7.8 ) |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Mon Aug 24, 2015 8:46 am Post subject: |
|
|
you can use the crcmb from the modbus.lib
but since functions 3 and 4 are similar, you can also alter the lib.
Change :
Cpi R22,3 ; test if we read
Brne _SendMODBUS1a ; no must be 6 or 16
into :
Cpi R22,3 ; test if we read
BREQ _SendMODBUS1aT4 ; yes
Cpi R22,4 ; test 4
BREQ _SendMODBUS1aT4 ; yes
rjmp _SendMODBUS1a ; test other functions
SendMODBUS1aT4: _________________ Mark |
|
Back to top |
|
|
georgestheking
Joined: 06 May 2005 Posts: 134
|
Posted: Thu Aug 27, 2015 7:39 pm Post subject: Modbus CRC |
|
|
Thanks Albert,
By the way, here is the Basic program :
Mb_crc = 65535
For P = 1 To 6
Mb_crc = Mb_crc Xor M(p)
For N = 0 To 7
A = Mb_crc And 1
If A = 1 Then
Shift Mb_crc , Right , 1
Mb_crc = &HA001 Xor Mb_crc
Else
Shift Mb_crc , Right , 1
End If
Next ' Next bit in the byte
Next ' Next byte in the frame
Georges
Last edited by georgestheking on Thu Aug 27, 2015 7:42 pm; edited 1 time in total |
|
Back to top |
|
|
georgestheking
Joined: 06 May 2005 Posts: 134
|
Posted: Thu Aug 27, 2015 7:40 pm Post subject: Modbus CRC |
|
|
Here the complete the Basic program :
Dim M(16) As Byte
M(1) = 1
M(2) = 4
M(3) = 0
M(4) = &H43
M(5) = 0
M(6) = 3
M(7) = &H41
M( = &HDF
Dim Mb_crc As Word
Dim P As Byte
Dim N As Byte
Dim B As Byte
Dim A As Byte
Mb_crc = 65535
For P = 1 To 6
Mb_crc = Mb_crc Xor M(p)
For N = 0 To 7
A = Mb_crc And 1
If A = 1 Then
Shift Mb_crc , Right , 1
Mb_crc = &HA001 Xor Mb_crc
Else
Shift Mb_crc , Right , 1
End If
Next
Next
m(7)= Low(mb_crc)
m( = High(mb_crc)
best regards
Georges |
|
Back to top |
|
|
|