5

I have an Arduino Uno board, with these components:

In addition I have a level sensor which reads either 1 when it is above water, and 0 when it is below.

I need to be able to give the value of this sensor to a modbus master over rs485.

Cooking Hacks Tutorial

This page has a description of how to use the ModbusMaster485 library, but I can not find any information about the slave library.

I can not find any documentation for this library, and would really appreciate any pointers.

  • Can you post the links to all the library that you've tried so that none of us would post the same. Thanks. – Dat Ha Dec 9 '16 at 15:08
  • @Dat Ha I've tried using SimpleModBusSlave.h, but the problem is, I have to use Arduino Nano, while the data system in that library is using enum (so it starts from 0). Meanwhile, the data from master is reaching 3000+, which causing full-memory stack error – dhimaspw Dec 13 '16 at 2:23
2
+100

It's not very well documented for the slave but maybe that is because it only has two methods...

It looks like the slave library is contained in the same library as the master but with name ModbusSlave485.h

You can see in the .h it only has two public methods. One is connfigure() and the other is update(). see below an extract from the .h which explains what each method does.

#include "ModbusSlave485.h"

mySlave = ModbusSlave485();

void setup()
{
  mySlave.configure(slave, baud, parity, txenpin);
}

void loop()
{
  //check for update from master
  mySlave.update(regs, regs_size)
}

extract from .h

/* 
 * configure(slave, baud, parity, txenpin)
 *
 * sets the communication parameters for of the serial line.
 *
 * slave: identification number of the slave in the Modbus network (1 to 127)
 * baud: baudrate in bps (typical values 9600, 19200... 115200)
 * parity: a single character sets the parity mode (character frame format): 
 *         'n' no parity (8N1); 'e' even parity (8E1), 'o' for odd parity (8O1).
 * txenpin: arduino pin number that controls transmision/reception
 *        of an external half-duplex device (e.g. a RS485 interface chip).
 *        0 or 1 disables this function (for a two-device network)
 *        >2 for point-to-multipoint topology (e.g. several arduinos)
 */
  void configure(unsigned char slave, long baud);

/*
 * update(regs, regs_size)
 * 
 * checks if there is any valid request from the modbus master. If there is,
 * performs the requested action
 * 
 * regs: an array with the holding registers. They start at address 1 (master point of view)
 * regs_size: total number of holding registers, i.e. the size of the array regs.
 * returns: 0 if no request from master,
 *  NO_REPLY (-1) if no reply is sent to the master
 *  an exception code (1 to 4) in case of a modbus exceptions
 *  the number of bytes sent as reply ( > 4) if OK.
 */
  int update(int *regs, unsigned int regs_size); 

  // constructor
  ModbusSlave485() 
  {
    myDevice = RS485();
  }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.