Programming microcontrollers

From Fab Lab Wiki - by NMÍ Kvikan
Revision as of 18:51, 14 January 2010 by Amy (Talk | contribs)

Jump to: navigation, search

Programming hello-world microcontrollers through parallel port. There are multiple ways of putting your code on to the microcontroller. This tutorial is on how to do it through the BASH (shell/terminal) using gavrasm and avrdude, with the AMP MTA/DB25 (BSD) cable.

You should have:

  • a text file with asembly code with the extention .ASM
  • gavrasm installed
  • avrdude installed
  • the cable attached to the computer (where it fits)
  • your circuit ready, with a battery connected


First

First you need to make your .ASM asembly file into a .HEX hexadecimal file. For this you use gavrasm. Open the terminal window, and navigate to where your file.ASM is. If it is on the desktop, you type "cd ~/Desktop". The syntax for gavrasm is straight forward:

 gavrasm file.ASM

The above command will return a file.HEX with the same name, in the same place as file.ASM -provided your file.ASM contains valid assembly code. If it does not, gavrasm will echo the errors back to you.


Second

The second step is to upload the file.HEX to the chip. Connect the programming cable to your circuit board. We are using the "in-circuit programming AMP MTA plug <-> DB25M parallel (bsd) cable" found in the shoebox (http://fab.cba.mit.edu/about/fab/). Make sure your board has power from a battery or powersuply, since this perticular cable don't carry power. We call avrdude, and give it the right parameters for the job. We need to state what chip we are uploading to, wich cable we are using and the method for storing our program on the chip. That should give us something like the folowing:

 avrdude -d t44 -c bsd -U flash:w:file.hex

Quick breakdown: We tell avrdude that -d (the device) is a tiny44, the -c (cable) is the "bsd" one, and after -U we say that we are using "flash" memory, "w" for write and then we give it the file to upload.

Problems with /dev/parport0? Try these three:

 sudo modprobe parport
 sudo modprobe ppdev
 sudo chmod 777 /dev/parport0

Then again with the avrdude...

The chip will start executing the code when you disconnect the programming cable.


The C/P-list

 tiny45 load hex file, bsd cable: avrdude -p t45 -c bsd -U flash:w:file.hex
 tiny45 load hex file, dasa cable: avrdude -p t45 -P /dev/ttyUSB0 -c dasa -U flash:w:file.hex
 tiny44 load hex file: avrdude -p t44 -c bsd -U flash:w:file.hex
 tiny44 use 20 MHz xtal: avrdude -p t44 -c bsd -U lfuse:w:0x7E:m
 mega88 load hex file: avrdude -p m88 -c bsd -U flash:w:file.hex
 mega88 use 20 MHz xtal: avrdude -p m88 -c bsd -U lfuse:w:0x76:m
 mega644 load hex file: avrdude -p m644 -c bsd -U flash:w:file.hex
 mega644 use 20 MHz xtal: avrdude -p m644 -c bsd -U lfuse:w:0x76:m


More details

Details on the MOSI/MISO way of communicating can be found here: http://en.wikipedia.org/wiki/SPI_bus