Debugging the openEEG-Hardware

(updated 2003-11-24)

modularEEG V1.0,V0.7,V0.6

Before debugging and testing the following should be read and understood:

digital part

The debugging and testing procedures described can be used with the following hardware versions:
All hardware versions can use as IC102 either the

Requirements for debugging and testing

Note: The modularEEG itself is platform independent, however some of the tools and procedures I will describe here will only work on Windows OS. Linux should also work, however other software will be required.  
Note: The OLIMEX AVR-PG1B - STKxxx COMPATIBLE ICSP SERIAL PORT DONGLE PROGRAMMER will work also but requires another programming software (e.g. Pony Prog from Claudio Lanconelli) - I have not tested this combination, so you are on your own if you want to use it.

Problem Reason
  • SP12 programming software does not recognize the uP Type
  • firmware can not be flashed
  • modularEEG has no power (e.g. low battery)
  • wrong programming adpater
  • wrong parallel port (the physical port of the PC and the port address in the SP12 configuration file must match)
  • Programming adapter shifted or rotated on J101. Make sure that J101 pin 1 matches with the red (sometime marked blue) cable of the programming adapter.
  • wrong KANDA mode (SP12)
    # Set KANDA=1 to adapt the parallel port pinout
    # to the cable/dongles supplied with the
    # Atmel/Kanda STK200/300 starter kits.
    # When KANDA=0 (default) the pinout conforms
    # to the original SP12 cable and Ken Huntington's
    # dongle.
    KANDA=1 is also required with the OLIMEX parallel programming adapter (AVR-PG2B (PARALLEL PORT) 10 PIN ICSP AVR MICROCONTROLLER PROGRAMMER)
  • direct parallelport access not enabled (Win NT,2000,XP) (does not apply to Win95,98,98SE,ME)
  • wrong timing (with SP12) on LPT2 with Multi IO-card.
    After creating  "_sp12rc" with (sp12.exe -i) following entries have to be changed for LPT2 on 222N-2 Multi IO-card (NetMosMultiFunction, PCI, 9835 Multi-I/O Chip, Win98SE, 1.333Ghz ATHLON) :

    file: _sp12rc
    # This port address will be used:

    (This is LPT2)

    # Set clockSpdDefault to a suitable value in MHz.

    (The default value of 0.7 results in abort after 3 write retries)

device does not send any data to the PC (running hyperterminal)
  • device has no power

  • PC com port does not work
  • Serial (RS232) cable
    • defective (e.g. swapped pins, broken wires, shortcuts)
    • connected to other port that set up in hyperterminal
PC loopback test
  • IC106 (MAX232) defective
  • C127,128,126,129 mounted with false polarity or have less voltage than specified.
  • Optocouplers defective (IC104) or inserted with wrong orientation (be carefull: IC104 is rotated 180 deg due to layout reasons) (IC103 is only for receiving data), wrong resistor values around IC104, broken traces, shortcuts.
uP loopback test

TxD Speaker test
  • IC102 (AT90S4433, ATmega8) not flashed with firmware.
  • XTAL X101 not oscillating

data sent from EEG to PC does not make sense
AT90S4433 and ATmega8 require _different_ firmware versions.
ATmega8 requires proper flashing of the fuses, otherwise it will run on internal 1Mhz.
Check fuses of ATmega8

TxD Speaker test

How to flash the firmware (AT90S4433 version) on Win NT/2000/XP


Download the "sp12 v2.0.7 for XP/NT/W2000" package from
or directly from:

Unpack the tgz archive file until you get the SP12v2_0.7 folder.

Follow these instructions:

(If you have already installed GIVEIO or some other driver that enables direct port access under Windows XP you can skip the first part)

From "" in "sp12v2_0_7-Win32.tgz.gz"


   If you are running Win NT/2000/XP, you
   will need to install the GIVEIO device driver.

   Installing Giveio:

   To install the device driver you need Dale Roberts' device driver
   giveio.sys and the program instdrv.exe.  Both of these are included
   in the WinNT sub-directory of this installation.  The original files
   and documentation for Giveio can be found at
   (  Instdrv is
   from the device driver kit (DDK) for Windows NT.

   * Copy the driver giveio.sys from the archive into
   * Use command line to install the driver using instdrv:
           instdrv giveio %SystemRoot%\system32\drivers\giveio.sys

   * In order to start this driver at every reboot automatically,
     change the start up behaviour to automatic:
       * 2000/XP: start regedit and change the value of the key "Start" in
                "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\giveio" to 2.
       * NT: Control Panel->Devices->giveio->Start Up->Automatic.

   Sp12.exe should be put somewhere in your PATH. It is advisable
   to set the environment variable SP12 by adding a line like
   "Set SP12=C:\SP12\" to your environment. Sp12 looks for two
   files in the directory pointed to by this variable: _sp12dev and
   _sp12rc. Without it, you'll need copies of those files in all
   your project directories.

   Copy _sp12dev into the chosen directory, and run

      sp12 -i

   To make sp12 create an _sp12rc for your system. Depending on your
   computer it may take a few seconds or somewhat longer to
   calibrate the timing loop.

   Note: If heavy multitasking is going on, the autocalibration will
   produce time constants which are too small. Therefore _sp12rc
   should be created on a lightly loaded system.  When you are
   actually programming an uC, heavy background loads may slow down
   the job, but they won't really hurt; the AVR serial mode
   programming time constraints are minimum values.
   _sp12rc is in plain language and may be edited (with care), for
   instance to make SP12 use a different parallel port (read
   _sp12rc and sp12rc.txt for details).

   Finally, run

      sp12 -t

   The command presents a progress bar, which should take about 10
   seconds to complete, counting from the moment when you hit the
   return on the command line. (There may a brief pause before the
   bar appears, which nevertheless is part of the ten seconds.)
   I wouldn't worry if it's eight or 15 seconds. But the deviation
   is large,  read `bugs & bother' below.

Connect the programming cable (2x5, 10 poles, digital pcb version 0.7 and later) with the PC-parallelport and the modularEEG 2x5 pinhead programming connector. Make sure PIN1 of the connector is aligned with PIN1 of the programming cable.

Activate the power supply for the modularEEG.

Flash the ROM-image (AT90S4433_modeeg_v0_07.rom) into the AT90S4433 uP:
    sp12.exe -wpfC AT90S4433_modeeg_v0_07.rom -T1

You should see the following:

SP12 version 2.0.7 performing init...
Path to _sp12rc and _sp12dev: Local directory
Running in SP12 cable/dongle compatible mode.
Enabling AVR serial reading/programming...
The device code bytes 0,1,2: 0x1e, 0x92, 0x3 were read
from parallel port 0x278 and indicate the following:
You have connected an AT90S4433
The device was made by Atmel
Performing chip erase...
Writing content of AT90S4433_modeeg_v0_07.rom into program area.
AT90S4433_modeeg_v0_07.rom written and verified.
write retries: 0, byteWrite: 25 percent of default
Checksum program area: 4893
Reset was left high.

If you see the above you have successfully flashed the firmware into the uC.

One final but important step:

Always disconnect the SP12cable before connecting the EEG to a test subject !!!!

That is important because the programming cable (SP12cable) crosses the opto-isolator and connects PC-ground to EEG-Ground. So with the programming cable attached the modularEEG does not have any safety isolation.

How to set up and use hyperterminal

A pictured example how to make a direct COM - connection to a modem can be found here:
and here:

Here is a simliar procedure for the modularEEG:

Launch the HyperTerminal program:

If you see the error message 'Cannot find HYPERTRM' you will need to

Install HyperTerminal:

    Note: You may be asked for your Windows installation disk for this procedure.

(If HyperTerminal is already installed you can alternatively start it by following the Start menu to Programs - Accessories - HyperTerminal (The exact position varies slightly for different Windows versions))

BTW: You can use any other terminal program. There is nothing special about
hyperterminal besides that it is distributed with Windows95, 98, Me, NT, 2K & XP

Setting com port, protocol and baud rate

A pictured example can be found here:

Setting protocol and baud rate for the openEEG:

At this point you will see data from the openEEG scroll down the screen, if it is connected and powered.

Some final steps:
(this is that the local echo is not misinterpreted when doing the hardware loopback test)

PC loopback test

No power (for the device) is required for this test.

You now have a simple loopback circuit that echoes any data on (PC side) TxD to RxD.

Now use a terminal program (Hyperterminal),

You should now get an echo of any character you type in.

Disconnect IC106 (empty socket) PIN 14 and PIN 13 (remove the wire inserted above).

You should no more get an echo of any character you type in.

If all of this works you have just verified the correct operation of:

uP loopback test

(has to be written)

Checking fuses of ATmega8

Make sure the device has power.

Connect the programmer cable.
Type to read out the fuses of your ATmega8:

    sp12.exe -rF

If you get the text below ( CKSE is 0001 ), your ATmega8 runs on internal 1Mhz instead of using the external 7.3728Mhz XTAL.

SP12 version 2.0.7 performing init...
Path to _sp12rc and _sp12dev: Local directory
Running in SP12 cable/dongle compatible mode.
Enabling AVR serial reading/programming...
The device code bytes 0,1,2: 0x1e, 0x93, 0x7 were read
from parallel port 0x378 and indicate the following:
You have connected an ATmega8
The device was made by Atmel

11100001 are the fuse bits read from an ATmega8
0xxxxxxx - BODLEVEL 4V (default 2.7V)
x0xxxxxx - brownout detection enabled
xxSUxxxx - reset delay, datasheet p28
xxxxCKSE - clock select, datasheet p24

To fix the problem try this here:

    sp12.exe -wF11111111

TxD Speaker test

Power on.
All ICs inserted:
Connect a little speaker or earphone from IC106 PIN14 (TXD) to GND1.

Does it sound like this here?

Finding VGND

Here is a picture of the modularEEG analog pcb with all VGND pins and vias highlighted in green:

VGND highlighted in EAGLE