AVR web to modbus/tcp
This package contains an example application which can send
a modbus/tcp request and display the result.
For more information about the modbus protocol
see:
http://www.modbus.org/specs.php
The modbus/tcp protocol is documented at:
http://www.modbus.org/docs/Modbus_Messaging_Implementation_Guide_V1_0b.pdf
For more detailed documentation see http://tuxgraphics.org/electronics/
All parts needed to build this AVR ethernet solution can be ordered from
http://shop.tuxgraphics.org/.
You can also order the email account which you need for the test_emailnotify
application from the tuxgraphics online shop.
Copyright of the software and all diagrams: Guido Socher, tuxgraphics.org
License for everything: GPL V2
See http://www.gnu.org/licenses/gpl.html
Other licenses are available on request.
!! READ THIS FIRST !!
---------------------
! Edit the file main.c and change the lines:
! static uint8_t mymac[6] = {0x54,0x55,0x58,0x10,0x00,0x29};
! static uint8_t myip[4] = {10,0,0,29};
! IP address of the modbus server to contact:
! static uint8_t msrvip[4] = {68,62,255,136};
! Internal Ip of your DSL router
! static uint8_t gwip[4] = {10,0,0,2};
The actual modbus example application is main.c.
The code test_web_client.c is just there to test
compatibility and for me to make sure that no existing functions broke
during development.
Check the file "Makefile" and make sure the MCU is set correctly:
! MCU=atmega168
! DUDECPUTYPE=m168
! or
! MCU=atmega328p
! DUDECPUTYPE=m328
Adapt also the "LOADCMD" variable at the begining of the Makefile
to be able to run "make load".
You need an avr-gcc development environment in order to compile this.
See http://tuxgraphics.org/electronics/200901/avr-gcc-linux.shtml
To compile the final software use the command:
make
Note: windows users may use and modify the supplied winmake.bat to setup the
environment correctly.
The command
make load
will execute the avrdude command to load the main.hex software (web
to modbus/tcp gateway)
Note your programmer might interfer with the enc28j60! For the avrusb500
with 30cm cable you can normally leave the cable on. For all other programmers
it is however saver to remove the programmer cable and power down/up the device.
This is because the SPI interface is used for loading of the software and
communication to the enc28j60.
To see a list of all possible build targets run the command:
make help
Selecting the right clock source
--------------------------------
Tuxgraphics hardware sold as of march 2007 is prepared to use the clock
signal from the enc28j60. To use this you need to change the
low fuse byte once from 0x62 to 0x60:
avrdude -p m168 -c stk500v2 -u -v -U lfuse:w:0x60:m
or
avrdude -p m328 -c stk500v2 -u -v -U lfuse:w:0x60:m
or just type in your Linux shell:
make fuse
After programming the fuse settings of atmega168 and atmega88 should be:
low fuse: 0x60
high fuse: 0xdf
ext. fuse: 0x01
For the atmega328p the hfuse and efuse bytes look slightly different.
The idea is however the same. Just change the lfuse from factory default
to 0x60. The fuse settings of the atmega328 are after programming:
lfuse reads as 0x60
hfuse reads as 0xD9
efuse reads as 0x07
details of the lfuse bits:
CKDIV8 = 0
CKOUT = 1
SUT1 = 1
SUT0 = 0
CKSEL3 = 0
CKSEL2 = 0
CKSEL1 = 0
CKSEL0 = 0
If you are unsure what the current fuse setting are on the atmega
then you can read the fuse settings with a command like:
avrdude -p m168 -c stk500v2 -v -q
The result should be this (default factory settings for atmega168):
avrdude: safemode: lfuse reads as 62
avrdude: safemode: hfuse reads as DF
avrdude: safemode: efuse reads as 1
The result should be this (default factory settings for atmega328p, the
efuse is dependent on the chip revision):
avrdude: safemode: lfuse reads as 62
avrdude: safemode: hfuse reads as D9
avrdude: safemode: efuse reads as 7
Compiling on non-Unix systems
-----------------------------
Please use the provided Makefile !!!
It will also work under Windows.
Take a look at the supplied winmake.bat and winload.bat file. This bat script
might be needed to set the environment correctly.
A description of what makefiles are and how they work can be found at:
http://tuxgraphics.org/electronics/200912/makefiles.shtml
Revision history
----------------
2010-01-29: version 0.1 -- first version of the new stack with client_tcp_req
interface
vim:sw=8:ts=8:si:et