Menu

Modbus Slave- commands 3 and 16

mmotte
2018-02-01
2019-05-19
1 2 3 > >> (Page 1 of 3)
  • mmotte

    mmotte - 2018-02-01

    Last year I was doing some research and i wanted to record the Temperature and humidity (DHT22) in 22 compartments. This was in a factory with lots of steel and concrete and noise spread over a 500 ft radius. Wifi didn't look real feasible. So I opted for a wired network, RS485 and modbus protocol. There are modbus simulators that you can check the slave with from a PC. http://www.modbustools.com/modbus_poll.html . I actually used php to write a program to gather the data into a MySQL database every 5 minutes. Never got implemented yet at the factory but I do have 7 stations running full time at home . Don't get bothered by the BME280 stuff, i am just recording some data and this demonstrates how to add data to the outbuffer.

    ' Modbus RTU Slave
    ' Only two commands  3  read reg and 16 mod reg
    ' command 3  reads from the variable array "outbuffer(20)" which is ram with sensor data plugged in
    'command 16 writes to RAM  and is going to be used for limits
    'Adopted/severely modified from Andrzej Sokulski,
    ' andrzej@modbus.pl - www.modbus.pl
    ' All rights reserved.
    'Rewritten by Mike otte  December 2016/2017
    ' All rights reserved.
    ' This software is free you can redistribute it and/or
    '  modify it under the terms of the GNU Lesser General Public
    '  License as published by the Free Software Foundation; either
    '  version 2.1 of the License, or (at your option) any later version.
    '*
    '  This software is distributed in the hope that it will be useful,
    '
    '  but WITHOUT ANY WARRANTY;
    '  In no event shall the regents or co ntributors be liable for any direct,
    '  indirect, incidential, special, exemplary, or consequential damages.
    'Modbus slave based on PIC 16F886 PIC16F1705
    'This slave supports modbus function 3 (read holding registers) and 16 (preset multiple registers)
    ' command 3  reads from the variable array "outbuffer(20)" which is ram
    'command 16 writes to EEPROM  and is going to be used for limits
    'The RS232 is set to baudrate - 9600, data bits - 8, stop bits 1, parity - none
    'The hardware USART and MSSP/I2C are defined below
    'The Timer 2 is used for detecting end of modbus frame
    
    'Master  Query
    'read registers 4000040008 from slave device 17:
    'Example   = $0A$03$00$00$00$08$45$77
    'Field Name         (Hex)
    'Slave Address        $0A
    'Function             $03
    'Starting Address Hi  $00
    'Starting Address Lo  $00
    'No. of Points Hi     $00
    'No. of Points Lo     $08
    'Error Check ( CRC)   $45 ––  16bits = last two bytes of packet
    '                     $77
    
    'Slave RESPONSE
    '0A 03 10 01 83 00 D1 00 05 67 C0 00 08 04 F0 84 1B EF DF 13 3E
    'Example                ASCII       RTU
    'Field    Name  (Hex)   Characters  8Bit Field
    'Header  :              (colon)   None
    'Slave Address    $0A   0 A       0000 1010
    'Function         $03   0 3       0000 0011
    'Byte Count       $10   1 0       0001 0000
    'Data Hi          $01   0 1       0000 0001
    'Data Lo          $83   8 3       1000 0011
    'Data Hi          $00   0 0       0000 0000
    'Data Lo          $D1   D 1       1101 0001
    '.....
    'Data Hi          $EF   E F       1110 1111
    'Data Lo          $DF   D F       1101 1111
    'Error Check      $13   1 3       0001 0011        LRC (2 chars.) CRC (16 bits)
    'CRC              $3E   3 E       0011 1110
    'Trailer for ascii       CR LF
    '    Total Bytes: 25        11          ASCII mode takes many more chars
    'This code only implements RTU!
    
    ' Preset Multiple Holding  Registers
    '   ***********            Function 16   Hex $10
    '
    'Field Name (Hex)
    'Slave Address       $10
    'Function            $10
    'Starting Address Hi $00
    'Starting Address Lo $01
    'No. of Registers Hi $00
    'No. of Registers Lo $02
    'Byte Count          $04
    'Data Hi             $00
    'Data Lo             $0A
    'Data Hi             $01
    'Data Lo             $02
    'Error Check         $__ (LRC or CRC) –– two bytes
    '                    $__
    'Response from slave
    'Field Name (Hex)
    'Slave Address        $11
    'Function             $10
    'Starting Address Hi  $00
    'Starting Address Lo  $01
    'No. of Registers Hi  $00
    'No. of Registers Lo  $02
    'Error Check          $__(LRC or CRC) –– two bytes
    '                     $__
    ; ----- Configuration
    
      #chip 16F1705,8
      #option explicit
      #config  WDT_OFF, LVP_OFF
    
       'Generated by PIC PPS Tool for Great Cow Basic
        'PPS Tool version: 0.0.5.11
        'PinManager data: v1.55
        '
        'Template comment at the start of the config file
        '
        #startup InitPPS, 85
    
        Sub InitPPS
            UNLOCKPPS
    
                'Module: EUSART
                RXPPS = 0x0005    'RA5 > RX
                RC5PPS = 0x0014    'TX > RC5
                'Module: MSSP
                RC0PPS = 0x0010    'SCL > RC0
                SSPCLKPPS = 0x0010    'RC0 > SCL (bi-directional)
                RC1PPS = 0x0011    'SDA > RC1
                SSPDATPPS = 0x0011    'RC1 > SDA (bi-directional)
    
            LOCKPPS
        End Sub
        'Template comment at the end of the config file
    
      #include <BME280.h >
      #include <DHT.h >
    
    ; ----- Define Hardware settings
      ' Define I2C settings - CHANGE PORTS if required
      #define HI2C_BAUD_RATE 400
      #define HI2C_DATA PORTC.1
      #define HI2C_CLOCK PORTC.0
      'Initialise I2C Slave
      'I2C pins need to be input for SSP module
      Dir HI2C_DATA in
      Dir HI2C_CLOCK in
     'MASTER
      HI2CMode Master
    
    'DHT 22  Humidity and Temperature
      #DEFINE DHT_TYPE 22
      #DEFINE DHT_PIN PORTA.2
      '#define sensor  PortA.2  'PortA.0     ;RH/Temp sensor on pin
      dir PORTA.2 in          'sensor in
    
    'InitUSART   usuart is on a RS485 network
      #define USART_BAUD_RATE 9600
      #define USART_BLOCKING
      #define MaxDir  PortA.4     'RS485 direction  Max485 chip
      dir PortA.4 Out         ' MAX485 direction control
    ' timer 2 determines the end of the frame
      pr2 = 0
      Inittimer2 PS2_16, 0 'Prescale 1:16 /Postscale 1:1
      Starttimer 2
    
      On Interrupt UsartRX1Ready Call SerialInterrupt
      On Interrupt Timer2Match Call Timer2Interrupt
    
    ;----- Variables
    Dim SlaveAddress as byte
    SlaveAddress = 10                 ' Modbus slave adress (1..255)
    
    dim DHT_rh ,DHT_cels, DHT_fahr as integer
    dim DHT_error  as Byte
    
    Dim buffer(74)             'Modbus frame buffer - change if want to get more than 32 registers in single frame
    Dim outbuffer(50)          ' buffer to collect data to send back before transfering to buffer
    Dim ADC_P, ADC_T as Long    ' variables used by BME280_Read_TPH
    Dim ADC_H as Word
    
    Dim  mbB0     as byte            'Variables definition
    Dim  mbB1     as byte             ' transmit this byte
    Dim  mbW0     as word             'address pointer
    Dim  MBFrame  as byte
    Dim  NewFrame as byte
    Dim  Length   as byte
    Dim  TMR2Ticks as byte            'used to determine end of RTU frame
    Dim  mbi      as byte             ' forloop index
    Dim  counter1 as word             ' waste time counter to do nothing
    Dim  counter2 as word             ' waste time counter to do nothing
    Dim Generator as word             ' CRC variable/constant 40961
    Dim Temp as word
    Dim CRC as word                   ' CRC result
    Dim mbj as byte                   ' forloop index
    Dim mbBit as bit                  ' temp bit var
    
    TMR2Ticks = 0
    Length = 0
    wait 500 ms
    
    mainloop:
    
    For counter2 = 0 to 5  ' The main program
    For counter1 = 0 to 10000  ' Write your code here
    next counter1
    next counter2
      'diagnostic - used for testing
      'MaxDir = 1
      'hserprint "I am here "
      'MaxDir = 0
      ' MaxDir = 1
      'hserprint Length
      'MaxDir = 0
    
    ' Modbus protocol function
      If NewFrame = 1 Then           ' Check if new modbus frame is in buffer
        NewFrame = 0
    
        Gosub checkMB            ' Check the modbus Received frame
        Select Case MBFrame
            case 3
                  'MaxDir = 1
                  'hserprint "case 3 "
                  'MaxDir = 0
                  mbReadRegResponse      ' Response for function 3
    
            case 16
                 mbwriteRegResponse     ' Response for function 16
    
            case else
                 mbwriteBadRequest      ' Response for error
        end select
    
        Length = 0
      End if
    
    Goto mainloop
    
    Sub charout
    xmty:                  ' USART send single byte
      If TXIF = 0 Then goto xmty            ' Wait for transmit register empty
      TXREG = mbB1                     ' Send character to transmit register
    End Sub
    
    Sub crc__16
    'crc__16:                  ' Function to calculate CRC16 checksum
    CRC = 65535                 'CRC is  word and is set to all 1's to start
    Generator = 40961
    For mbi = 1 To Length
        Temp = buffer(mbi)
    
        CRC = CRC # Temp      ''XOR ed
    
        For mbj = 1 To 8
    
            STATUS.C = 0
            Rotate CRC right  'CRC = CRC >> 1
            mbBit = STATUS.C
            If mbBit Then
               CRC = CRC # Generator  'XOR ed
            End If
         Next
    Next
    
    'crc16(2) = CRC / 256            ' CRC16 high byte
    'crc16(1) = SysCalcTempX           ' CRC16 low byte
    'CRC contains the CRC word  16 bit
    End Sub
    
    Sub checkMB
    
    'checkMB:
    'Check the modbus frame
      if (buffer(1) <> SlaveAddress) then     'Wrong Slave address
        MBFrame = 0
        Exit Sub
      end if
    
      if (buffer(2) <> 3) AND (buffer(2) <> 16) then 'Wrong Modbus function
        MBFrame = 0x81
        Exit Sub
      end if
      'hserprint "wrong"
      'if ((buffer(5)>0)OR( buffer(6) > 32)) then 'Too many registers
      '  MBFrame = 0x83
      'Exit Sub
      'end if
      'hserprint "Toomanyreg"
      if (Length > 74) then  'Too many bytes in frame
        MBFrame = 0x82
        Exit Sub
      end if
      'hserprint "len74"
      if (Length <9) then 'Frame too short
        MBFrame = 0x81
        Exit Sub
      end if
    
      'Check CRC
      Length = Length - 3
      crc__16
    
      'diagnostic CRC values(1)
      'MaxDir = 1
      'hserprint crc
      'MaxDir = 0
    
      if (buffer(Length+1) <> [byte]CRC) OR (buffer(Length+2) <> CRC_H) then 'Bad CRC16 checksum
        MBFrame = 0
      else
        MBFrame = buffer(2)   ' Frame OK !
      End if
    
    End Sub
    
    Sub mbReadRegResponse
        'readRegResponse:                ' Response for modbus function 3 (Read Holding Registers)
        'UPDATE Registers first
        ' DHT22  fills outbuffer 1-4 are written in the DHT22 sub
        readDHT( DHT_rh , DHT_cels,  DHT_fahr ,  DHT_error )
        outbuffer(1)=DHT_rh_H       ' Write data to buffer
        outbuffer(2)=DHT_rh         'Remember Holding Registers asked byt the master are 16 bit
        outbuffer(3)=DHT_cels_H     ' so that is two bytes
        outbuffer(4)=DHT_cels
        BME280_Read_TPH
        outbuffer(5)=adc_P_E       ' Write data to buffer
        outbuffer(6)=adc_P_U
        outbuffer(7)=adc_P_H
        outbuffer(8)=adc_P
        outbuffer(9)=adc_T_E       ' Write data to buffer
        outbuffer(10)=adc_T_U
        outbuffer(11)=adc_T_H
        outbuffer(12)=adc_T
        outbuffer(13)=adc_H_H
        outbuffer(14)=adc_H       ' outbuffer is 50 bytes of which we only filled 14 so far
        mbW0 = buffer(3)*255 + buffer(4)    'Starting address
        'mbW0 = mbW0 * 2
        mbW0 = mbW0 - 40000                    ' 40000 is secret MODBUS offset for holding registers
        buffer(3) = buffer(6)*2             ' buffer(6) is num of points(words) LO which is getting buffer ready for Tx
        'buffer(3) is the number of data bytes to xfer
        ' Header neads  MBaddress byte, MBcommand byte, Number of bytes to Xfer in the header
        'they are already there
        for mbB0=1 to buffer(3)
             buffer(mbB0+3) = outbuffer(mbB0)             ' Put data in buffer from ram ,leave room for header
        Next
        Length = buffer(3) + 3
        'Buffer(3) = Length
        crc__16
        buffer(Length +1) = [byte]CRC  'crc16(1)         ' Calculate the CRC16 for response frame
        buffer(Length +2) = CRC_H       'crc16(2)
        Length = Length + 4
        MaxDir = 1               'MAX485 direction control = Tx
        For mbB0 = 1 To Length            ' Send the response to Master
          mbB1 = buffer(mbB0)
          Gosub charout
        Next
        MaxDir = 0                 'MAX485 direction control + Rx
    End sub
    
    Sub mbwriteRegResponse
    'writeRegResponse             ' Response for modbus 16 function (Preset Multiple Registers)
    ''Slave Address       $0A     'buffer(1)
    'Function            $10      'buffer(2)
    'Starting Address Hi $00      'buffer(3)
    'Starting Address Lo $01      'buffer(4)
    'No. of Registers Hi $00      'buffer(5)
    'No. of Registers Lo $02      'buffer(6)
    'Byte Count          $04      'buffer(7)
    'Data Hi             $00
    'Data Lo             $0A
    'Data Hi             $01
    'Data Lo             $02
    'Error Check         $__ (LRC or CRC) –– two bytes
    '                    $__
    
        mbW0 = buffer(3)*255 + buffer(4) ' Calculate the starting address of registers (Holding registers are 16 bit)
        mbW0 = (mbW0 * 2) -1                   ' Claculate starting memory  byte to write to.... 2 bytes per holding register
        for mbB0 = 0 TO (buffer(7)-1)     ' buffer (7) contains the byte count
          mbB1 = buffer(mbB0 + 8)         ' Get byte of data
          'EPWrite mbW0,mbB1              ' Write data to EEPROM memory
          outbuffer(mbW0) = mbB1          ' write data to memory
          mbW0 = mbW0 +1                  ' increment memory pointer
          'wait 10 ms
        NEXT
    'Response from slave
    'Field Name (Hex)
    'Slave Address        $0A     all ready in buffer(1)
    'Function             $10     all ready in buffer(2)
    'Starting Address Hi  $00    all ready in buffer(3)
    'Starting Address Lo  $01     all ready in buffer(4)
    'No. of Registers Hi  $00     all ready in buffer(5)
    'No. of Registers Lo  $02     all ready in buffer(6)
    'Error Check          $__(LRC or CRC) –– two bytes
    '                     $__
    Length = 6                    'Tell crc how many to calc
    crc__16                       ' Calculate the CRC16 for response frame
    'CRC field is appended to the message as the last field in the message.
    'the loworder byte of the field is appended first, followed by the
    'highorder byte.
    buffer(length+1) = [byte]CRC    'crc16(1)
    buffer(length+2) = CRC_H        'crc16(2)
    Length = Length + 4
    MaxDir = 1
    For mbB0 = 1 To Length            ' Send the response to Master
      mbB1 = buffer(mbB0)
      Gosub charout
    Next
    MaxDir = 0
    End Sub
    
    Sub mbwriteBadRequest
    'writeBadRequest:              ' Response for error in modbus poll
    'the following message is sent as ascii and you can see what the crc of the master should be
    ' put the decimal value in the programmers calculator, switch to hex, and reverse the two bytes
    ' remember crc is low byte first, high byte second in the frame packet
    MaxDir =1
    hserprint "bad crc should be = "
    hserprint crc
    HSerPrintCRLF
    MaxDir =0
    
    if (MBFrame <> 0) then            ' If MBFrame = 0 then no response
      buffer(2)=buffer(1)+ 0x80        ' Set the error code in modbus frame
      buffer(3)=MBFrame - 0x80         ' Set the error nr
      Length = 3
      crc__16
      buffer(length+1) = [byte]CRC    'crc16(1)       ' Calculate the CRC16 for response frame
      buffer(length+2) = CRC_H        'crc16(2)
      Length = Length + 4
      MaxDir = 1
      For mbB0 = 1 To Length          ' Send the response to Master
        mbB1 = buffer(mbB0)
        Gosub charout
      Next mbB0
      MaxDir = 0
    End if
    End Sub
    
    'readMB:
    Sub SerialInterrupt
    
      If OERR   then                'OERR or  FERR   RC1STA.2 If USART error then clear the error flag
          CREN = 0                             'CREN
      end if
      If FERR   then                'OERR or  FERR   RC1STA.2 If USART error then clear the error flag
          CREN = 0                             'CREN
      end if
    
      CREN = 1
    
      if RCIF then                      ' RCIF  USART REC Interrupt (PIR1.5 = 1)
        TMR2Ticks = 0         ' reset time out which indicates end of MBFrame
        If (NewFrame = 1) OR (Length = 0) then      'New modbus frame start
          NewFrame = 0
          T2CON.2 = 1               ' Enable Timer2
          Length = 1
          End If
    
         do while RCIF               'Write modbus frame to buffer  (PIR1.5 = 1)
           buffer(Length) = RCREG
           Length = Length + 1
           if Length = 75 then
            Length = 0
           End If
         loop
      End If
    End sub
    
    Sub Timer2Interrupt
      if (TMR2IF = 1) then                        ' Timer2 interrupt flag
       TMR2IF = 0
       TMR2ON = 0                               ' Timer2 disable
       TMR2Ticks = TMR2Ticks + 1
         If TMR2Ticks > 120 then                     ' ~ 10 ms without new char
          NewFrame = 1                               'There was no new char on USART => end of modbus frame
         else
          TMR2ON = 1                                'Enable timer
         End If
      End If
      'Resume
    End Sub
    

    This is only RTU implementation not ascii. Only used HSer routines for developement and trouble shooting (some are left). It was easier to read and write to the USART. Modbus is a Master /Slave protocol. The Master asks for data or sends data and tells the slave where to put it. The commands sent to the slave and the data sent back from the slave are in packets starting with the slaves address and ending with a CRC16 check. I included some modbus documentation.

    GL
    Mike

     
  • Anobium

    Anobium - 2018-02-02

    Very nice code. Excellent work.

    Do have any photos of the opertional solution?

     
  • mmotte

    mmotte - 2018-02-02

    I do have a few pics. Should I post them here or send them via other method? i will post one now

     
  • Anobium

    Anobium - 2018-02-02

    Wonderful - can you send to Bed? And, I can we publish on the WebSite with some nice words?

     
  • bed

    bed - 2018-02-07

    Took the challenge.
    Thanks for sharing your work

     
  • BASIL HATZILAIOS

    Mike,

    about the code for modbus 3 and 16....I would like to use a PLC as master and a glcd as slave.....what modifications must do to above code modbus RTU slave, to work with PIC16F1939 ? the pic that work as slave is connected to a glcd, to diplay text that I send from PLC (modbus master)...so, what is the variable (Rx) that will checked for incoming data in above code ? the above code uses var outbuffer ....below is my first approach to slave code ....the code for writing to glcd is ok....just to setup pic uart for RS-485 and check for incoming ..
    modbus slave ........initialize
    glcd ......initialize
    var( Rx)= modbus slave : check for incoming
    locate glcd cursor ...... var ( Idx = total pixels of glcd ).....go to the begging of row
    read holding register value.......var (pic_reg)=modbus slave: read holding reg (Idx)
    print value to glcd......print (pic_reg)
    modbus error loop .....if Rx=255 then output 1 to a pin .
    an opinion for how to add the above code to glcd code...
    thanks in advance,
    Basil

     
  • mmotte

    mmotte - 2019-02-12

    Basil,
    First question is who is Master and who is slave. Who initiates the communication? Modbus Master sends the command and the slave sends the response. In my experience the slave was the PLC and my Distributed ControlSytem would send and receive from the Holding registers of the PLC thus making the DCS the master.

    If you can make your PLC act as Master, then that is fine because everything you need is in the code for Modbus 3 and 16. Your PLC would send the command 16 (modbus 16 function (Preset Multiple Registers)) to the PIC with the data and you would simulate holding registers in the PIC . Remember the holing registers are 16bit words. Then you LCD part of the slave program would write it to the LCD.

         mbB1 = buffer(mbB0 + 8)  ' getting data from input buffer
      EPWrite mbW0,mbB1 ' Write data to EEPROM memory  'writing data to holding registers  or you LCD
    

    Then the slave sends back the response confirming the transaction.. Header +the number of bytes and CRC16.

    What brand and model PLC are you using?

    I will help you through this.
    Mike

     
  • mmotte

    mmotte - 2019-02-13

    Basil,
    I tried to comment and answer your questions in the above message.

    "what modifications must do to above code modbus RTU slave, to work with PIC16F1939 ?"
    Change the #chip 16F1939 ,8
    define port for max485 direction
    define usart port pins

    "the pic that work as slave is connected to a glcd, to diplay text that I send from PLC (modbus master)..."
    I am assuming you know how and where to make the PLC Master

    "so, what is the variable (Rx) that will checked for incoming data in above code ?"
    The master will send a command and it will be received in the " buffer()", It comes in as a data packet and when
    the TMR2 times out it says the "Frame" Is received, Then the frame(all the bytes are in the buffer) is checked for address,
    command, number of bytes, crc16 and then the command is executed. In your case ,Command 16, you would put the bytes
    where you can use them for LCD display, Then a packet is sent back confirming reception.

    "the above code uses var outbuffer"
    outbuffer has nothing to do with the Modbus code, It is part of my DHT22 code only

    "....below is my first approach to slave code ....the code for writing to glcd is ok...."
    "just to setup pic uart for RS-485 and check for incoming .. modbus slave ........initialize"
    usart baud blocking
    set up pins tx, rx, dir
    setup interrupts

    "glcd ......initialize"
    yours

    "var( Rx)= modbus slave : check for incoming"
    automatically comes in when frame is received complete

    "locate glcd cursor ...... var ( Idx = total pixels of glcd ).....go to the begging of row"
    what are doing with pixels?

    "read holding register value.......var (pic_reg)=modbus slave: read holding reg (Idx)"
    Your data is in the buffer and will be sent to your buffer with "Sub mbwriteRegResponse"
    which processes the command 16

    "print value to glcd......print (pic_reg)"
    Your displaying the data

    "modbus error loop .....if Rx=255 then output 1 to a pin ."
    If errors occur then Modbus sends error message back to the master.

     
  • BASIL HATZILAIOS

    Mike,
    many thanks for your detailed answer...
    The PLC is Schneider Modicon M221... PLC configured as master and the board with pic-glcd is the slave....from PLC we send a text that displayed to glcd...the communication starts from PLC that send commands and the slave responds.. .because my knowledge about GCB is limited , would you like to help me to merge the two codes?....Anobium has be done an excellent work to help me, and sends to me a code to write characters to a glcd with a pic(PIC16F1939)....I send you that demo code to add if it possible the part of modbus slave code....for now instead of master ( i'll get Modicon later ) I use ComTestPro as modbus master simulator to send commands to slave board.....is it possible to send larger characters to glcd, or ghraphics (bmp) ? for any other info please let me know...
    thanks in advance.
    Basil

     
  • mmotte

    mmotte - 2019-02-13

    Basil,
    Good information.

    Are you making a message display or aiming for a HMI? Could you give a typical message?

    I will look this over.

     
  • BASIL HATZILAIOS

    Mike,
    I made a modification to code , to display some text...just to test the code....I send you the modified code.... as glcd I use a 240x128 type AGM2412A ( DISPLAYTRONIC) with T6963C...for the hardware I use a PIC16F1939 , an RS-485 connector , an SN75176 as receiver/transmitter for modbus data, the glcd as above ....( If you need schematic please let me know), the connections pic-glcd are : port B to D0-D7 of glcd , RW to pin D.3 , RD to pin C.4, CE to pin C.5, CD to pin D.5, RESET to pin D.6 , FS to pin A.0........connections SN75176 to pic..: pin 1( R) to C.7 pin (RX)..pin 4(D) to pin C.6 (TX)...direction pin ( RE, DE) to pin A.1....

     
  • BASIL HATZILAIOS

    Mike,
    I send you a short video to see glcd with pcb that I was designed as modbus monitor....

     
  • mmotte

    mmotte - 2019-02-14

    Basil,
    This is what I had last night at 11pm.
    It wouldn't compile for me because of LCD errors.... I am running 98.03GCB and don't have your GLCD in my library. There are more things I want to change in the interrupts but this is close to running.

    I don't have your GLCD nor the PIC for a test bed

    GL
    Mike

     
  • BASIL HATZILAIOS

    Mike,
    very good work ...it compile for me, so can I send some characters with ComTestPro to test? is not critical for me the same type of glcd or pic...any type of glcd 240x128 even and 240x64 can be used ...Anobium make the code pic-glcd using a glcd 240x64....with a modification easy can work with 240x128....only to have controller T6963 or similar....I'll make some tests at next hours and inform you about....
    best regards
    Basil

     
  • BASIL HATZILAIOS

    Mike,
    I made some tests to send characters with ComTestPro...I had no response...I send 10 chars with mb command 16...as it seems at log there is no response with time out error...I was checked hardware for errors...ok...

     
  • BASIL HATZILAIOS

    Mike,
    the glcd screen after power on before send charcters..no change at tests...

     
  • mmotte

    mmotte - 2019-02-15

    Basil,
    I am working to put together a test board so I can get immediate feedback and trouble shoot.

    What you sent looks correct. The time out could be the time out setting on comtestpro is 100 ms and had the scan really slow at 4sec

    do Forever
            wait 4 s
          ' Modbus protocol function
    

    Try increasing the comtestprotime out to 5000ms Or turn the wait down to something much lower. This would not be a solution but a test.

    I probably need to take the "' Modbus protocol function" out and trigger it by itself. When a frame is complete.

    I will work on this as I get time. I have to go to town today.

    BR
    Mike
    I moved the processing of the Frame out of the main loop! See attached. This is a severely revised Version that I was working on last night. Worth a try.

     

    Last edit: mmotte 2019-02-15
  • BASIL HATZILAIOS

    Mike,
    I changed slave address to 07 to mb master according to code....the same ...no response...

     
  • mmotte

    mmotte - 2019-02-15

    Basil,
    The time out is beacuse of the setting on the comtestpro timeout in upper right corner 100ms and I had put the processing of the new fram in the display main loop which cycles at 4000ms.

    I moved the processing of new frame to the interrupt of the mbtimer2match. this is not ideal but worth a try.

    working at putting some hardware together so i can test here

    BR
    Mike

     
  • BASIL HATZILAIOS

    Mike,
    after change the mb slave address to 07 , I send 10 chars (ABCDEFGHIJ) , I had response error (time out) , but I had the chars on glcd as below ..

     
  • BASIL HATZILAIOS

    Mike,
    but in the next cycles chars changed as below.... I will try the updated code in a few minutes...

     
  • mmotte

    mmotte - 2019-02-15

    That's exciting! We're close!

     
  • BASIL HATZILAIOS

    Mike,
    test for V1.55....the same as previous...responce error (time out) , 10 chars ok, but the first 4 chars changed in the next cycles....

     
  • BASIL HATZILAIOS

    Mike,
    hoping to help, I send you a code in C (for FC7), that works fine with a lcd 4x20 with modbus protocol...

     
1 2 3 > >> (Page 1 of 3)

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.