Skip to content
/ avr-lab Public

👽 Template and Examples in C for AVR Microcontrollers, optionally built via Docker

License

Notifications You must be signed in to change notification settings

duddel/avr-lab

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AVR Lab

build

👽 Template and Examples in C for AVR Microcontrollers, optionally built via Docker.

  • Using default gcc-avr and avr-libc, see Dockerfile for details
  • Mainly written for ATtiny85, if not stated otherwise
  • Check out the examples in src/
  • Utilize existing code for an own project or start with a basic example
  • Having Docker in place, the projects can be built with a single command

Examples and Helper Modules

Example projects, roughly sorted by complexity.

Example Code Info
blink src/blink/main.c Hello world blink example
timemeas src/timemeas/main.c No delay blink example using time measure
togglebutton src/togglebutton/main.c Debounced button input
states src/states/main.c Simple state logic with debounced button input
sleep_pci src/sleep_pci/main.c Sleep and wake-up via pin change interrupt
ws2812 src/ws2812/main.c WS2812B control via Bit-Banging

Helper modules.

Module API Code Info
debounce src/debounce.h src/debounce.c Button debouncer
timemeas src/timemeas.h src/timemeas.c Time measurement
ws2812b_attiny13 src/ws2812b_attiny13.h src/ws2812b_attiny13.c WS2812B interface. 3rd party, see below
zzz src/zzz.h src/zzz.c Power down sleep mode

Set up Docker

A Docker installation and basic Docker knowledge is required. Run these commands in the repository root.

First, build the Docker image (once).

docker build -t avrlab .

Build a project

This builds a project in an auto-removing container, from the image created above. Recommended in most cases.

# Bash
docker run --rm -v $(pwd):/code avrlab /bin/bash -c "cd src/blink && make hex"

# Powershell
docker run --rm -v ${PWD}:/code avrlab /bin/bash -c "cd src/blink && make hex"

Advanced (more Control over Container)

Start container with interactive shell.

# Option 1: Auto-removing container after usage
# Bash
docker run --rm -it -v $(pwd):/code avrlab

# Powershell
docker run --rm -it -v ${PWD}:/code avrlab

# Option 2: Named container
# Bash
docker run -it -v $(pwd):/code --name avrlab_01 avrlab

# Powershell
docker run -it -v ${PWD}:/code --name avrlab_01 avrlab

# For option 2, start container like this
docker start -i avrlab_01

Build a project.

cd src/blink
make hex

avrdude Example Commands

  • Install avrdude on host (recommended)
  • Use stk500v1 compatible ISP (e.g. using Arduino with ISP example sketch)

Program

avrdude -p attiny85 -P com3 -c stk500v1 -b 19200 -U flash:w:main.hex

Fuses

Attention: inappropriate fuse settings can brick the microcontroller, check [1]

# Set 1MHz clock
avrdude -p attiny85 -P com3 -c stk500v1 -b 19200 -U lfuse:w:0x62:m

# Set 8MHz clock
avrdude -p attiny85 -P com3 -c stk500v1 -b 19200 -U lfuse:w:0xE2:m

References

[1] https://www.engbedded.com/fusecalc/

License

The source code in this repository is licensed under the MIT license (if not stated otherwise). For Licenses of thirdparty components, see below.

Thirdparty

Makefile_template

ws2812b_attiny13

About

👽 Template and Examples in C for AVR Microcontrollers, optionally built via Docker

Topics

Resources

License

Stars

Watchers

Forks