Demand Peripherals     Robotics and Automation Made Easy

AVR: AVR Software Interface

The AVR peripheral lets you control an AVR microcontroller from a Linux application. It lets you program flash memory, program EEPROM, read AVR registers, and read and write RAM locations that you specify in your AVR application.



The AVR peripheral requires the MEGA card which has an ATmega88PB AVR microcontroller. More information about the MEGA card is available here cards/mega.html.



There are 2 separate categories of resources for this peripheral, programming related and real time data memory access. The programming related resources allow flashing of the program and EEPROM memories. The programming jumper must be installed to use the programming related resources.

The data memory access resources allow you to read and write both RAM and CPU registers while the program is running. Your host application would normally control the AVR application using these resources.

program : read and write program flash
Use this resource to load a program into the AVR or to read the program that is currently loaded. Be sure the programming jumper is in place and note that the file path must be fully qualified.

    dpset avr program /home/me/myavr/led.hex
    dpget avr program /home/me/myavr/ledcheck.hex

eeprom : read and write EEPROM
To flash the EEPROM, specify the beginning address in the EEPROM followed by the space separate hex values to be flashed. To dump the EEPROM, specify the beginning address in the EEPROM followed by the number of bytes to dump. EEPROM addresses range from 0x00 to 0x1ff. Be sure the programming jumper is installed. At most twelve bytes can be written at one tim. The forms of the commands are:

    dpset avr eeprom <address> <byte1> <byte2> ...
    dpget avr eeprom <address> <count>
    dpset avr eeprom 01f2 45 67 89 ab  # write 4 bytes of EEPROM
    dpget avr eeprom 01f2 4            # read 4 bytes of EEPROM
    dpset avr eeprom 0000 77           # set default LED blink rate

vram : read and write specific AVR RAM locations
Use this resource to read and write RAM in the AVR. Mapping the virtual RAM addresses to physical addresses is done in the SPI receive character interrupt handler. The sample LED application maps vram addresses into the 'hostRegs' array of bytes. Please see the programming section below for an example of AVR RAM location to virtual RAM mapping. The vram commands are of the form:

    dpset avr vram <address> <byte1> <byte2> ...
    dpget avr vram <address> <count>
    dpset avr vram 00 77     # set working LED blink rate
    dpset avr vram 01 01     # enable the LED flasher

fifo : read and write to a vram FIFO
Use this resource to write many values to a single RAM location, i.e. host register, in the AVR. Note that currently there is way to read many values from a single host register. Also, any one transaction is limited to 12 bytes of data written to the host register. The sample fifo application shows the usage of this resource. Commands are of the form:

    dpset avr fifo <address> <byte1> <byte2> ...
    dpset avr fifo 0 5 6 7 8 9a bc de    # write 7 values to a fifo
                                         # through vram location 0

reg : read and write AVR registers
Use this resource to directly read and write the AVR hardware registers. Register addresses must be in the range 0x23-0xc6. Please see the register summary in the data sheet for a list of the hardware registers. Addresses and data are given in hex and commands are of the form:

    dpset avr reg <address> <byte1> <byte2> ...
    dpget avr reg <address> <count>
    dpset avr reg 2b 80    # turn on the LED directly
    dpget avr reg 2a 2     # returns LED port DDR and PORT values


AVR Application Development:

Install gcc for the AVR with the following (for Debian):

    sudo apt-get install gcc-avr avr-libc binutils-avr

Code Overview
SPI is used for communication between the Linux host and the AVR. Most of the AVR code to support the resources described above is contained in the interrupt handler for SPI chip select transitions and in the interrupt handlers for SPI buffer full and empty. Hooks are provided in these handlers so you can tie your AVR application to SPI packet and byte arrival. A good example to use is the flashing LED application that is pre-loaded onto the AVR.

Development Walk-through
Download the dpdaemon source code. Navigate to the LED sample application. Change the timing of the LED flashing.

    git clone
    cd dpdaemon/fpga-drivers/avr/Code/samples/led
    vi led.c  # change _delay_ms(1) to _delay_ms(2)
Connect the FPGA card, the MEGA card, and start dpdaemon. While doing AVR development you may want to keep dpdaemon attached to your terminal. Print statements in the avr peripheral will give you more visibility into the programming process. You can test your setup with a command that changes the blink rate.
    dpdaemon -ef &
    dpset avr vram 00 11
When run as a daemon (without the -f option) dpdaemon uses root as its working directory. For this reason you need to give the full path to your hex file when programming. Install the programming jumper and load your modified LED program.
    dpset avr program /home/me/dpdaemon/fpga-drivers/avr/Code/samples/led/led.hex
You should see messages on the console showing the progress of the download and verification of the download. When the download is complete remove the jumper, stop dpdaemon, and power cycle the MEGA and FPGA cards. The new flash rate should half of what it was after the previous power-up.

When programming the AVR be sure to remove and reinstall the jumper if it was installed from a previous download. This resets the AVR and is a necessary step in programming it.

Getting a Linux host to communicate with an AVR microcontroller might seem a little complex. Please contact us at if you would like some help with your application.


FPGA Defined Peripherals
User Interface
FPGA Configuration
FPGA Buttons & LEDs
AVR Interface
Stereo Audio Amplifier
Text LCD and Keypad
Quad WS2812 Interface
Quad Slide Pot
IR Recv/Xmit
6 Digit LCD
RC Decoder
Keyfob RF Decoder
Rotary Encoder Interface
Quad Touch Interface
Motion Control
Dual DC Motor Controller
Dual Quadrature Decoder
Quad 13 Bit Servo
Bipolar Stepper Controller
Unipolar Stepper Controller
Simple Input / Output
Quad Binary Output
Quad Binary Input
Octal Input/Output
32 Channel Binary Output
32 Channel Binary Input
Octal 12-bit ADC
Quad Ping))) Interface
Octal SRF04 Interface
Quad Event Counter
Generic I2C
Generic SPI
Octal 8-Bit DAC
Quad Digital Potentiometer
Quad PWM Output
Quad PWM Input
Real Time Clock

Interface Cards
Control Cards
User Interface
Stereo Audio Amplifier
IR Recv/xmit
Six Digit LCD Display
Keyfob RF Receiver
Rotary Encoder
Quad Switch Card
Text LCD / keypad
Quad Slide Pot
Quad Touch Interface
Motion Control
Dual 7-amp H-bridge
Quad Open Drain Driver
Quad 10 Amp Relay Card
Input / Output
Octal 8-Bit DAC
Quad Digital Potentiometer
Octal 12-bit ADC
Octal SRF04
I2C Prototyping
SPI Prototyping
USB 2.0 Hub
Real Time Clock
Octal Input/Output
32 Channel Input
32 Channel Output
Power Distribution Card
15 Amp Power Distribution
5 Volt Switching Regulator
ATX Power Break-Out Card
Disk Drive Power Break-Out
MP43 Aluminum Mounting Plate
WW4 Large Prototyping Card
WW2 Prototyping Card
WW1 Small Prototyping Card
SMP SMD Prototyping Card