Electrical – How to connect Arduino Uno to an energy meter

modbusrs485

How do I connect an energy meter, such as the L&T (Larsen & Toubro) Quasar Intelligent meter (datasheet,) which uses Modbus RTU protocol with RS485 communication to an Arduino Uno?

I am using MAX 485 to convert RS485 to TTL and I have written my program using the ModbusMaster library.

I always get a Time Out error or Slave Id error. Please help me out of this situation.

Best Answer

If the device you want to talk to presents its data via Modbus over RS-485, then on your end you have to implement RS-485 in hardware, and a Modbus master in firmware.

You will need a RS-485 transceiver chip between the UART signals of your micro and the RS-485 bus.

The tricky part is knowing when to set the bus transceiver to transmit mode instead of receive mode. Most UARTs that come with micros don't include this. If your does, just connect the data direction line to the transceiver direction line, possibly requiring inversion in between. If not, you will have to create the direction signal in firmware in your UART driver.

A simple way to do this in firmware is to have a periodic interrupt that runs several times per data byte. This will be useful for implementing the Modbus timing too. Whenever the app writes a byte to the UART driver, the direction line is set to sending before anything else is done. The periodic interrupt then sets the line to receiving if there are no bytes waiting in the software write FIFO, in the UART hardware, and the UART is finished clocking out the last character.

You will probably want to use this same periodic interrupt to time the gap between received bytes. Somehow you then communicate to the application whether the gap before each received byte was long enough to indicate the start of a new packet or not. The remaining Modbus logic can then be handled above the low level UART driver layer.