Fast communication over ethernet for realtime applications
This is based on an the code and ideas from Rogier Schouten ( http://www.rogiershikes.tk )
In this example implementation three bytes of data are sent to the microcontroller.
The first byte is used as a sequece number the second is used to set the pins
on Port D according to the bit pattern given and the third byte is just some
constant.
The microcontroller sends the sequece number back and provideds on the next byte
the readings of the pins on Port C. The last byte is just a counter.
This is the software for the tuxgraphics.org
ethernet remote device. See http://tuxgraphics.org/electronics/
Copyright of software: Pascal Stang, Guido Socher, Rogier Schouten
Guido Socher (http://tuxgraphics.org)
Rogier Schouten (http://www.rogiershikes.tk)
Pascal Stang (http://www.procyonengineering.com/)
License for everything: GPL V2
See http://www.gnu.org/licenses/gpl.html
---------------------------------------------------------------------------
All parts needed to build this AVR ethernet solution can be ordered from
http://shop.tuxgraphics.org/
Note that the magnetics need to fit exactly the requirements of the enc28j60
chip. You can not just take any transformer.
ethcomavr_pre.hex
-----------------
A pre-compiled program with the mac address: 0x52,0x4f,0x47,0x49,0x45,0x52 ("ROGIER")
is available as ethcomavr_pre.hex
Compiling the software yourself
-------------------------------
!! READ THIS FIRST !!
---------------------
! Edit the file ethcomavr.c and change the line:
! static uint8_t mymac[6] = {0x52,0x4f,0x47,0x49,0x45,0x52};
! In the file linux-pc-application/ethcomrealtime.c you need to change
! the corresponding settings:
! #define ETH_DEST_MAC {0x52, 0x4f, 0x47, 0x49, 0x45, 0x52} // "ROGIER"
! // change this to fit the ethernet interface of your pc:
! #define ETH_DEVICE "eth0"
Check the file "Makefile" and make sure the MCU is set correctly:
#MCU=atmega88
#DUDECPUTYPE=m88
#MCU=atmega168
#DUDECPUTYPE=m168
MCU=atmega328p
DUDECPUTYPE=m328
You need an avr-gcc development environment in order to compile this.
You need at least avrlibc-1.4.x !! The atmega88 will not work with earilier
version.
To compile the final software use the command:
make
The above command will compile ethcomavr.hex
The command
make load
will execute the avrdude command to load the software:
E.g something like:
avrdude -p m88 -c stk500v2 -e -U flash:w:ethcomavr.hex
! 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
The linux application code is in the subdirectory linux-pc-application
and can be compiled with the command make in that directory.
You need to be root in order to execute the ethcomrealtime command.
Selecting the right clock source (fuse settings)
------------------------------------------------
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 m88 -c avrusb500 -u -v -U lfuse:w:0x60:m
or just type in your Linux shell:
make fuse
After this the fuses should be as follows:
low fuse: 0x60
high fuse: 0xdf
ext. fuse: 0x01
Note: Older hardware must use the atmega88 internal clock (8MHz).
Don't try to change any fuse bytes on the older hardware!! You will
not easily be able to undo such an operation on the older hardware.
It will completely halt and nothing will work anymore.
The older hardware must use the factory default fuses which look like this:
low fuse: 0x62
high fuse: 0xdf
ext. fuse: 0x01
If you are unsure what the current fuse setting are on the atmega88
then you can read the fuse settings with a command like:
avrdude -p m88 -c avrusb500 -v -q
The result should be this (default factory settings):
avrdude: safemode: lfuse reads as 62
avrdude: safemode: hfuse reads as DF
avrdude: safemode: efuse reads as 1
Compiling on non-Unix systems
-----------------------------
Please use the provided avr Makefile
It will also work under Windows except for the loading
of the software. That is compiling will work but not
"make load". Use then whatever tools and commands to download
the resuting .hex file into the micrcontroller
The linux application code would have to be re-written for
other operating systems.
Revision history
----------------
2008-12-31: version 0.1 -- First version that can run over the LAN, based on rogier-ethcom-0.1
vim:sw=8:ts=8:si:et