avr_io

(last updated: 2002/10/10)

Purpose: Allows a PC to control an Atmel AVR microcontroller. Provides digital and analog I/O to a PC.

Overview

In embedded systems development you are sometimes faced with developing software which interfaces to hardware that you have little experience with, such as an LCD module having a controller you've never used before. You can use the avr_io to get familiar with the interface by developing your code on a PC first, even if your final target platform is not a PC or even an AVR. This project would not be appropriate if the hardware you're interfacing to has strict timing requirements. You can also use this project to provide analog and digital, or even an SPI interface, to the PC in order to control relays, LED's, etc. Perhaps you could even use it as a learning tool; become familiar with the AVR without having to re-flash the AVR every time you want to change your code.

Here are some possible uses:

- Get the readings from a thermistor through the AVR's A/D and start working on linearization tables.

- Evaluate LCD modules by displaying images or characters.

- Control relays.

- Evaluate any IC that has an SPI interface.

Specifications

    1. Allow a host computer to write and read the Atmel AVR registers through the AVR's UART.
    2. Message format (commands incoming to AVR):
    3. <STX><command id><register id><data byte><ETX>
    4. command id – see item 3 below.
    5. register id – register address as per the AVR's reference guide
    6. data byte – if command is to write a register, this is the byte which will be written; if command is to read, then this byte is ignored.
    7. Commands
    1. Errors
    2. Errors are detected and an error id is stored. The host can get this stored error id as per the "get current error" command (see above). The error remains until the next packet arrives – except for the "get current error" command packet. The following errors are detected.
    3. 0 – no error (this error id is set whenever a valid command packet is processed; except for the "get current error" command)
    4. 1 – invalid start of frame (expected STX byte but received a different byte)
    5. 2 – invalid end of frame (expected ETX byte but received a different byte)
    6. 3 – invalid command (command id in message does not match any of the supported command id's)
    7. 4 – receive timeout (see below)
    8. Upon detection of an error, the object which parses the command packet is reset and starts to look for STX.
    9. Upon receiving any byte, a 5ms timer is started. The next byte must arrive before this timer expires, else the "receive timeout" error is detected.
    10. AVR's UART is set for 19200 8N1 at power up.
    11. The AVR's source code is written for AVRGCC.
    12. Commands are executed after receiving the ETX character.

My Setup:

- PC

- STK200 development board with AT90S8515

- dio_test – A Java console mode program which sends commands out the PC's serial port. The files are located in the \test\dio_test director in the source code. It was developed using JBuilder 6, the communications API, and the Java 1.4 SDK. The following tests are performed:

Step 1 – Set all ports as outputs. Connect a set of 8 LEDs to each port. The program activates each LED.

Step 2 – Verify start frame error

Step 3 – Verify end frame error

Step 4 – Verify invalid command error

Step 5 – Verify receive byte timeout error

Step 6 – Set all ports as inputs. Connect a set of 8 switches to each port. The ports are read as the switches are manually set.

Step 7 – Read the A/D (future)

Note1: PD0 and PD1 are used for the UART, so these pins are not available in the above tests.

Note2: On the STK200, PB5 and PB7 include 1K pull-ups and a diode near the ICP header. Additionally, PB5-PB7 include 10K resistors in series between the header and the uC. Connecting switches to PB5 and PB7 will therefore have no effect (see "PB5_7.jpg" in attachments). When the switch is closed, .4V is across the 1K resistor, .5V is across the diode, and 4.07V is across the 10K resistor; so the digital input will see a 'high' signal (the voltage across the 10K resistor).

Note 3: Here's my set of LED's and switches (see "led_switch_board.jpg" in attachments).

Download (see Attachments)

avr_io - source code

avr_io.hex - just the executable

Links

LCD Demonstrator – uses the avr_io to interface to LCD modules

javr_io - GUI interface to control the IO manually through a PC

Terms of Use

Home

Copyright Steven R. Nickels, 2008. All rights reserved.