Thursday, January 17, 2008

Hardware Setup

Hardware Setup

There are three things you have to do to get your hardware set up and begin programming:

(1) Build the board
(2) Build the USB-TTL adapter
(3) Load the bootloader onto the microprocessor

Once you've done these things, you can compile and run programs. Instructions follow.



Build the board:

Here are step by step photo instructions for building your board:

http://six.media.mit.edu:8080/6/direction/get-your-board-ready/stuff-the-board-with-these-instructions/

Your parts may look slightly different, and your board may look slightly different, but the idea is the same. Be patient and careful with your soldering. Be sure to heat the component and the pad thoroughly before adding the solder—to ensure that the solder bonds well. We'll go over this in class.



Build the USBTTL Adapter:

see http://robert-depot.blogspot.com/2008/01/build-usb-ttl-adapter-we-need-to.html



Installing the bootloader:

We are all going to install our bootloader with the computer in the lab, so we will follow these instructions:
http://six.media.mit.edu:8080/6/direction/install-bootloader/bootloading-on-the-pc/

Generally, the instructions are good, but I have a few details to add that help insure success. Here are my revised instructions, with additions in red:

The bootloader we use on the chalkroach was written by Simon Schiessl. You will download the bootloader zip file, and then load it on the ATMega32. There are a few ways to upload a bootloader on a chip, one of them being using a programming board. The STK500 is the programming board we will use here.


  • Download the bootloader zip file ((here)). In this zip file you will find bootloadermutated.hex, the file you will be loading on the microcontroller as well as the source code and the include files required should you decide to modify the code and recompile it.
  • Insert the ATMega32 on the STK500 board in the slot named sckt3100a3 with pin 1 looking away from serial port. Put jumpers on vtarget, aref, reset, xtal1 and between the top two pins of oscel.
  • Make sure that the 6-pin ribbon cable is connected between ISP6PIN and SPROG3 on the STK500.
  • Connect the STK500 to the serial port of your computer and plug in a power supply of between 10 and 15V
  • Open AVRStudio with the STK500 turned on (check that the red LED is lit)
  • Open the project bootloader_programming, if it exists. Otherwise:
    • Start a new project, selecting Project->New.
    • Select AVR GCC for project type.
    • Type in a project name. I used "bootloader_programming".
    • Specify a location and click Next.
    • On the right, select Atmega32 under Device. Debug platform should read AVR Simulator. Click Finish.
  • In the toolbar on the top, click on the black button labeled AVR, the software should automatically detect the STK500.
  • Check that ISP mode is selected under Programming mode.
  • click on the fuses tab and check the following boxe
    • On-Chip Debug Enabled (OCDEN=0)
    • Preserve EEPROM mem through Chip Erase Enabled (EESAVE=0)
    • Boot Flash = 1024 words Boot start address= $3c00 (BOOTSZ=01)
    • Boot Reset vector Enabled (BOOTRST=0)
    • Brown-out detection at 2.7V (BODLEVEL=1)
    • Brown-out detection enabled (BODEN=0)
    • CKOPT fuse enabled (CKOPOT=0)
    • Ext. Crystal/Resonator High Freq; Start-up time: 1K CK + 0 ms (CKSEL=1110 SUT=00)
  • click on program to set the fuse bits on the microcontroller.
  • click on the program tab. Select Atmega32 in the device box. Select ISP in Programming mode.
  • In Flash, under Input HEX file, browse for bootloadermutated.hex that you downloaded earlier. Click Program.
  • You have just loaded the bootloader on your chip. You are ready to put the chip in your board, and start programming!



Compile a program:

...and we'll see if it works! The program cmdlinetest.c, included with our sixcode examples, is a good place to start.

On OS X:
Follow these instructions:
http://six.media.mit.edu:8080/6/direction/start-programming/compiling-uploading/

On Windows:
Compile the program:
  1. Run Programmers Notepad. (installed with WinAVR)
  2. Select File-->Open, and choose the file cmdlinetest.c in the directory sixcodeexamplescmdline. You should see the source code for the program cmdlinetest.c open in the editor window.
  3. Select Tools-->[WinAVR] Make all. Your computer will compile the source code, and display its results in the Output window. If, at the end, you see > Process Exit Code: 0, then you will know the program compiled correctly.
And use Hyperterminal to upload the file to the chip: (as described at the end of this page) http://six.media.mit.edu:8080/6/direction/install-bootloader/bootloading-on-the-pc/




No comments: