README.txt for avr directory
============================

Created 13 May 2009 by David Rowe
Modified 29 May 2009 by Elektra


Preparations
==============

In order to get the FXS board running we need to flash the Atmega8L by ISP
(In-System Programming).  Also we need to modify one of the configuration
fuses.  The luxurious and most comfortable method is to utilize a Atmel AVR
development board like the AVR STK500 (around 80US-$).  However building a
ISP programming adaptor is simple and fun. There are many howtos for
building DIY Atmel ISP adaptors on the web.

We'll describe the programming with a self-made programmer first. For
instructions how to do it with AVRs development board scroll down to the
section "Programming the Atmega8L with the AVR STK500 development board".


Igloo Cable for the Atmeg8L
===========================

It took me a few days to figure out but I think I have a working
cable for the atmega8l now.  In fact I have two cables, a 5V cable and a
3V3 cable.  The atmega8l can be powered from 5V to be programmed, but
this is not convenient when used with the rest of the fxs interface
circuit (and Mesh Potato) as the rest of the circuit is 3V3.

Jumper J5 (J1 on the Mesh Potato), which is located close to the Xilinx CPLD, must be open to program the Atmega8L.  Replace the jumper after programming.


2/ For 3V3 programming I used a modified Igloo circuit.  This tar ball
has the Igloo circuit:

http://blackfin.uclinux.org/gf/download/frsrelease/317/1070/JTAG_Programmer_for_BF1.zip

3/ The modifications are:

Igloo     J4 (J41) FXS interface
--------------------------------
~TRST     RESET pin 8
TCK       SCK pin 10
TDI       MOSI pin 9  (data from PC to Atmel)
TDO       MISO pin 7  (data from Atmel to PC)

4/ Add this to your avrdude.conf:

programmer
  id    = "igloo";
  desc  = "Igloo JTAG cable.";
  type  = par;
  reset = ~2;
  sck   = 4;
  mosi  = 5;
  miso  = 11;
;

5/ To test try to get the command line interface:

avrdude -c igloo -p m8 -t

Programming the configuration fuses
===================================

The Atmeg8L has two configuration fuses, hfuse, and lfuse.  The
default hfuse value (0xd9) is fine.  However to enable the external
crystal oscialltor we need to change the lfuse value from the default
0xe1 to 0xff.

To read the lfuse value:

  # avrdude -c igloo -p m8 -U lfuse:r:lfuse.txt:h
  # cat lfuse.txt
  0xe1

To write the lfuse value:

  # avrdude -c igloo -p m8 -U lfuse:w:0xff:m

Programming the Atmega8L
========================

  # avrdude -c igloo -p m8 -e -U flash:w:uart2spi.hex

Atmega 8L data sheet notes
==========================

p27  CKSEL bits
p223 hfuse and lfuse bits



Programming the Atmega8L with the AVR STK500 development board
==============================================================

If you have access to a AVR STK500 you don't need to bother about modifying
a cable for 3V3 operation (read: programming at 3.3 Volts).  The FXS board
can be powered from the STK500 and the supply voltage (Vtarget setting) can
be adjusted via uisp (command line), kontrollerlab (integrated AVR
development environment for Linux and BSDs) or AVR Studio (Atmels IDE for
Windows).

Make sure you have 3.3 Volts at the Vtarget (VTG) pin of the Atmel ISP
headers present before you connect the FXS board. You may damage
the CPLD when feeding them with 5 Volts. 

Jumper J5, which is located close to the Xilinx CPLD must be open to flash the
Atmega8L.

IMPORTANT NOTE:

The 10-pin ISP header on the FXS board has a pinout that is different to
Atmels 10-pin ISP header. So you can't just connect a 10-pin cable from the
STK-500 to the AtMega header. I have used individual cables to wire it up. 


Atmel 10-pin header:

+-------------------------+
| Pin1=MOSI | Pin2=Vtarget|
|			  |
| Pin3=NC   | Pin4=GND    |
|			  |
| Pin5=Reset| Pin6=GND    |
|			  |
| Pin7=SCK  | Pin8=GND    |
|			  |
| Pin9=MISO | Pin10=GND   |
+-------------------------+


FXS-board 10-pin header:

+-------------------------+
| Pin1=3V3  | Pin2=GND    |
|                         |
| Pin3=NC   | Pin4=NC     |
|                         |
| Pin5=NC   | Pin6=NC     |
|                         |
| Pin7=MISO | Pin8=Reset  |
|                         |
| Pin9=MOSI | Pin10=SCK   |
+-------------------------+


My recommendation would be to install kontrollerlab, avrdude and uisp if you are
using BSD or Linux (including all dependencies, naturally).

In Kontrollerlab select Project -> Configure Programmer. Select UISP from
the 'Configure Programmer' dialog, avrdude doesn't support controlling
Vtarget. Select the serial port and speed from the 'UISP General' dialog. Head on to
'UISP - STK500' settings and adjust Vtarget. Save settings.

Verify the Voltage at Pin2 is 3V3 with a digital multimeter. Connect the FXS board.

Select Project -> Upload hex file. Choose and write the file.
Select Project -> Fuses. Configure the fuses. Tick all fuse bits, low
byte. 

Connect a jumper to J5 and you are set!

Have fun!