Quantcast
Channel: MCS Electronics Forum
Viewing all articles
Browse latest Browse all 20563

BASCOM-AVR : makemodbus given the right instruction : REPLY

$
0
0
Hello everyone. Instruction makemodbus function 6, we write registers 0 and 1 at the transmitter , but when I want to read registers 3 and 4, function 3 does not get anything in variable B. What is wrong, can someone help me . [code:1:56ca87b4a7] 'MODBUS_MASTER '------------------------------------------------------------------------------ $regfile = "m16def.dat" ' chip used $crystal = 16000000 ' xtal used $hwstack = 64 $swstack = 64 $framesize = 64 $baud = 19200 ' baudrate N,8,1 $lib "modbus.lbx" 'modbus.lib contains the crcMB function 'konfiguracija ulaznih pinova Config Pinb.0 = Input 'Taster provera LCD prvi sa leva na ploci Config Pind.4 = Input 'Taster provera tona drugi na ploci Config Pind.5 = Input 'Taster provera temperature LM35 treci sa leva Config Pind.6 = Input 'Taster cetvrti 'port pocinje portx.7 - - portx.0 ukljucuje pull up resistors Portd = &B01110000 Portb = &B00000001 Waitms 150 Config Print = Portd.2 , Mode = Set ' specify RS-485 and direction pin Rs485dir Alias Portd.2 'make an alias Config Rs485dir = Output 'set direction register to output Rs485dir = 0 Config Com1 = 19200 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0 '**************************************************************** ' MCU hardware configuration '**************************************************************** 'Declare LCD-a: 20*4 ili 16*1a Config Lcd = 20 * 4 Config Lcdbus = 4 Config Lcdpin = Pin , Db7 = Portb.6 , Db6 = Portb.5 , Db5 = Portb.4 , Db4 = Portb.3 , E = Portb.2 , Rs = Portb.1 Cursor Off Cls Lcd "MODBUS CONECT" Wait 2 Cls ' ********************************************************************************************** 'Definisanje variable Dim Moj_reg2 As Word 'make variable for two byte from register 2 Dim Pomreg0 As Bit , Pomreg1 As Bit Dim Moj_reg1 As Word , Moj_reg0 As Word Dim B As Byte Do Home U Lcd "R0" ; Moj_reg0 Lowerline Lcd "R1" ; Moj_reg1 If Pinb.0 = 0 And Pomreg0 = 0 Then Set Pomreg0 Moj_reg0 = Moj_reg0 + 1 Print Makemodbus(3 , 6 , 0 , Moj_reg0); ' slave 3, function 6, address 0 , value of w End If If Pinb.0 = 1 Then Reset Pomreg0 End If If Pind.4 = 0 And Pomreg1 = 0 Then Set Pomreg1 Moj_reg1 = Moj_reg1 + 5 Print Makemodbus(3 , 6 , 1 , Moj_reg1); ' slave 3, function 6, address 1 , value of w End If If Pind.4 = 1 Then Reset Pomreg1 End If Print Makemodbus(3 , 3 , 0 , 4); ' slave 3, function 3, address 0 , 13 byte If Ischarwaiting() <> 0 Then 'was something returned? B = Waitkey() 'then get it Thirdline Lcd Hex(b) ; ","; Waitms 200 'Print Hex(b) ; ","; 'print the info End If Loop [/code:1:56ca87b4a7] thank in advance

Viewing all articles
Browse latest Browse all 20563

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>