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]
Rating:
Author: Simon Platten
Last Updated: 2013-02-16
Package Version: 1.0.2.7
Category: Communication
Downloaded: 12380 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.
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".
DOWNLOAD LINK | RELATED COMPILER | CONTAINS |
---|---|---|
1361012128_serial_modbus_sl_mikroc_pic.zip [144.39KB] | mikroC PRO for PIC |
|
[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 communicating with EasyPic v7 @ 115200 bps.
View full imageThis 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