Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

malfunction in a bus with high trafic #39

Open
negroKiordi opened this issue Jun 21, 2022 · 1 comment
Open

malfunction in a bus with high trafic #39

negroKiordi opened this issue Jun 21, 2022 · 1 comment

Comments

@negroKiordi
Copy link

negroKiordi commented Jun 21, 2022

Hi to everyone!
Is my first time doing a contibuition in github. Sorry if here is not the place to do it.
I have tested the library in using a Attiny board. The application was a remote thermometer, so with this tiny board I had to interrogate a DS18B20 and to implement the Modbus slave.
It took me the 92% of the total memmorie but I reach the objetive.
When I comunicate with de slave in a bus with just this slave everithing goes rigth. The problem apeared when I tried to included in crouded bus, where the master interrogate almos the 100% of the time.
I made a little change in the code of the librarie and now is working OK.
I would like to share with you the solution.

The problem is the implementation of the timeout T1_5 in modbus_update() function.
The original code is:

  while (mySerial.available())
  {
    // The maximum number of bytes is limited to the serial buffer size of 128 bytes
    // If more bytes is received than the BUFFER_SIZE the overflow flag will be set and the 
    // serial buffer will be red untill all the data is cleared from the receive buffer.
    if (overflow) 
      mySerial.read();
    else
    {
      if (buffer == BUFFER_SIZE)
        overflow = 1;
      frame[buffer] = mySerial.read();
      buffer++;
    }
    delayMicroseconds(T1_5); // inter character time out
  }

Here the "time out" is not implemented, insted a delay off the entire timeout is included.
I have conclude this is the reason why in the crowded bus this slave can not follow the trafic.
So I remplaced the code by follows. It now use a 94% inted of 92% of total memmorie

    unsigned long timeOut = micros();
     while ((*_port).available() || (timeOut+T1_5 <= micros())) {
      if((*_port).available()) {
         timeOut = micros();
          // The maximum number of bytes is limited to the serial buffer size of 128 bytes
          // If more bytes is received than the BUFFER_SIZE the overflow flag will be set and the
          // serial buffer will be red untill all the data is cleared from the receive buffer.
          if (overflow)
              (*_port).read();
          else {
              if (buffer == BUFFER_SIZE)
                  overflow = 1;
              frame[buffer] = (*_port).read();
              buffer++;
          }
      }
    }


Thank you for the librarie!!!






@ssarna1
Copy link

ssarna1 commented Feb 26, 2023

Have You tried the low latency mode instead?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants