TOP Contributors

  1. MIKROE (2760 codes)
  2. Alcides Ramos (374 codes)
  3. Shawon Shahryiar (307 codes)
  4. jm_palomino (118 codes)
  5. Bugz Bensce (90 codes)
  6. S P (73 codes)
  7. dany (71 codes)
  8. MikroBUS.NET Team (35 codes)
  9. NART SCHINACKOW (34 codes)
  10. Armstrong Subero (27 codes)

Most Downloaded

  1. Timer Calculator (139227 times)
  2. FAT32 Library (71733 times)
  3. Network Ethernet Library (57114 times)
  4. USB Device Library (47426 times)
  5. Network WiFi Library (43051 times)
  6. FT800 Library (42401 times)
  7. GSM click (29832 times)
  8. mikroSDK (28051 times)
  9. PID Library (26881 times)
  10. microSD click (26197 times)
Libstock prefers package manager

Package Manager

We strongly encourage users to use Package manager for sharing their code on Libstock website, because it boosts your efficiency and leaves the end user with no room for error. [more info]

< Back
Project

Serial Modbus Slave

Rating:

15

Author: Simon Platten

Last Updated: 2013-02-16

Package Version: 1.0.2.7

Category: Communication

Downloaded: 12350 times

Followed by: 5 users

License: MIT license  

This project demonstrates a set of functions and structures for implementing an RTU modbus slave on the serial port.


No Abuse Reported

Do you want to subscribe in order to receive notifications regarding "Serial Modbus Slave" changes.

Do you want to unsubscribe in order to stop receiving notifications regarding "Serial Modbus Slave" changes.

Do you want to report abuse regarding "Serial Modbus Slave".

  • Information
  • Comments (51)
DOWNLOAD LINK RELATED COMPILER CONTAINS
mikroC PRO for PIC
  • lib
  • src
  • exa
  • hlp
  • hex
  • sch
  • pcb
  • doc

Project Blog

[16/02/2013] Fixed problem with call-back routines, when a call-back was called this was crashing the program.  This has now been resolved.

[03/09/2012] For embedded Modbus Master implementation:

http://www.libstock.com/projects/view/441/modbus-master

[28/07/2012] More optimizations, reducing footprint.  Summary, data user 404 bytes, rom usage: 5304 bytes, total: 5708 bytes.

[08/07/2012] Renamed modbusSlave.h to modbus.h in preperation for modbusMaster implementation.  In preperation for the modbus Master project which is about to be started, some optimizations have been performed and removal of more unused variables.  Modified modbusSerialInit to take an optional argument, the slave address, this enables the decodePacket routine to ignore the message instantly if the packet is not addressed to the slave.

[07/07/2012] More optimization, decreasing memory footprint, thanks again to Janni.

[06/07/2012] Added analogue input using POT on channel 1, turning pot and view result in input register 1.

[05/07/2012] More optimization, improving performance and memory footprint.  Thank you again to 'janni' for his contributions.

[03/07/2012] Re-wrote the management of I/O reducing dramatically the overhead associated with each I/O point and adding call-backs to allow the application layer to act on the data when it has been modified by a Master write function. 

[01/07/2012] Improved register mapping, fixing an addressing problem when only one 8 bit port on a register.  Improved CRC calculation courtesy of janni.

[30/06/2012] More optimization, modified addHoldingReg and addInputReg, its now possible to map 8 bit ports into the hi-byte or lo-byte of a register.  Changed I/O in demo to:

coils: 20, status bits: 28, holding registers: 2, input registers 2

[29/06/2012] Move changes, thanks again janni for your efforts on sorting out the timing.

[28/06/2012] Moved reseting of indexes at the end of decodePacket.  Revisited interrupts and changed the way bytes are recevied and transmitted.

[27/06/2012] Re-wrote calcCRC to use lookup table.  Combine request and response buffer which simplified code.  Implemented new timeout code (thanks janni).

[25/06/2012] Increased gap timeout using 11 databits instead of 10.  Added while loop to wait until all data transmitted.

[24/06/2012] Adjusted packet gap timings, adding adjustment for framing. 8Mhz as well as 32Mhz seems to work too...still not sure why other clock frequencies are not working.

[23/06/2012] Added definitions for Timer0 presets MSB and LSB to modbusSlave.h.  Added definitions for additional clock speeds and tested, so far only 32Mhz is verified as working.  Found and fixed bug in function code 15 and 16 responses.

[21/06/2012] Implemented exception handling and exception responses, increased baud rate of demo to 115200 and tested.  Re-coded interrupt handler implementing timeout and function codes 15 and 16.

Supported modbus functions in this release:

01 Read Coils
02 Read Status Inputs
03 Read Holding Registers
04 Read Input Registers
05 Force Single Coil
06 Preset Single Coil
15 Force Multiple Coils
16 Preset Multiple Registers

[19/06/2012] Improved decode implementing ISR decode, increased all types of data in demo.  Function codes 5 and 6 now supported.  For writing to single coils and single registers.  Baud rate changed to 19200.

[17/06/2012] In this example PORTD is configured for input and PORTC for output.  Using the EasyPic v7 and a P18F45K22, you can drive the discrete inputs using the push buttons.  You will need a modbus master to communicate with the project using an RS232 serial connection.

Supported modbus functions in this release:

01 Read Coils
02 Read Status Inputs
03 Read Holding Registers
04 Read Input Registers

To do...Implement the following functions:
05 Force Single Coil
06 Preset Single Coil
15 Force Multiple Coils
16 Preset Multiple Registers

Other functions will be implemented on request.  The main.c module demonstrates how to use the functions and structures.

Comments welcome.

To test this software, connect a modbus master to the EasyPic v7 using an RS232 cable, set the software to communicate with a slave address (1) using 9600,N,8,1.

The demo project has the following configured:

8 coils, starting at address 1

8 status inputs, starting at address 1

1 Input register, starting at address 1

2 holding registers, starting at address 1

For testing I used a Windows application from Calta Computer Systems Limited, which is simple and easy to set-up, available from http://www.calta.com/homepage.htm

Modbus Master Running on Windows 7

Modbus Master Running on Windows 7

Modbus Master Running on Windows 7 communicating with EasyPic v7 @ 115200 bps.

View full image
Modbus Master set-up

Modbus Master set-up

Settings to run with demo.

View full image

Modbus Slave running on EasyPic v7

This video shows Windows 7 64bit system running the Calta Computer Systems modbus simulator as the Master, communicating with EasyPic v7 running at 32Mhz, 115200 baud.

Watch on YouTube

ALSO FROM THIS AUTHOR

Generic Linked List

0

This small project demonstrates how to use my generic linked list structure. Included in this project is a very small LED scanner, each LED is a node in the linked list.

[Learn More]

LED Faders

0

This project demonstrates my fading structure and functions. You can create multiple faders on any I/O port you specify. Faders can be either individual pins or a mask of multiple pins. You specify the speed of fade, direction (in or out) and what options you want.

[Learn More]

WiFi HTTP Demo Example v2.3

5

This is a variation on the MikroElektronika WiFi HTTP Demo project. I posted only because 'dejan.odabasic' of the mikroElektronika team suggested sharing it.

[Learn More]