Jaclyn Berry

wk7: Embedded Programming


Installation Woes

The week started off a bit difficult. I attempted to install CrossPack, however the installation did not seem to work at all. Every time I tried to check the installation by typing "avr-help" in the terminal I got the following error:

Calvin pointed me to this tutorial that installs Homebrew instead of CrossPack. This went better, but I received another error when trying to install the avr-libc.

It looked like avr-libc should have pulled avr-gcc and some kind of utilities file, so I checked the Homebrew reposiory on GitHub and followed their instructions to install avr-gcc from the README. That installation was successful, but I was still concerned that I may have missed some things from avr-libc. I tried searching internet for answers, but in the end Jonah helped me flash a simple a blink program written in C with the packages I already installed. The code uploaded successfully, so I guess everything installed alright.

Fuses and Bricks

Jonah helped start us off in C programming with a short tutorial about talking directly to the microcontroller pins in C. There were some problems in the original code I uploaded to my board, so I dug through the datasheet directly to figure out what address to use for my led. I found the answer on page 69 of the attiny data sheet. For Pin PA2 (my led pin) I would use address 0b0000100 to set my pin high.

Although the sketch uploaded successfully and the led turned on and off, the blink rate was way too slow. Apparently the F_CPU definition does not set the hardware clock speed. In order to set the clock speed I had to set the clock fuses. Here again Calvin pointed me to another tutorial page to understand fuses. This link combined with Lady Ada's AVR Tutorial and the Attiny Data sheet helped me understand what was happening a little bit more.

7 6 5 4 3 2 1 0 BITS
0 1 0 1 1 1 1 0 BYTE ASSIGNED TO LFUSE

It turns out I still didn't really understand how this worked, because I misread the fuse settings in the Makefile from Brian's tutorial, ran 'make fuses' and bricked my board. I went to replaced the attiny on my board and whole bunch of unfortunate events unrolled.

When I used the heat guns, instead of removing the attiny, the fiberglass material on the board blistered and burned (and a capacitor popped off). The copper traces in the burned areas also started to peel up. I had to cut these pieces away and remove one of my O ohm jumper resistors.

First I considered milling an entirely new board. However, there was only one remaining 1/64" endmill and no more sheets of copper. Instead, I tried to salvage my board. I managed to find one last Attiny44 in an incorrect bin. I went to solder, but only one soldering iron was fully functional (and occupied). One soldering iron was mysteriously broken and another soldering iron had a broken tip.

I replaced the broken tip and fortunately that iron still worked beautifully. I soldered the new attiny44, capacitor, and a jumper wire to reconnect my ground trace. Then I prayed to the universe.

Programming Interrupts in C

I was interested in learning how to use interrupts with the attiny because they might be relevant for my antisocial robot project. I searched through the datasheet, found some information, got really confused, searched for more information on the internet, found a good tutorial (here) and finally was able to write some code.

It took me a few tries to get it right. But this (above) code is what worked in the end. Pressing the button causes an interrupt, which then toggles the LED.

In this process, I discovered that bitwise operators (stuff that looks like << |= ^=) are much easier to use than trying to assign binary bytes. I will definitely try to use this more going forward. A few operators I learned (I probably oversimplified again):

|= bitwise inclusive OR turns stuff on
^= bitwise exclusive OR (XOR) toggles on and off
<< binary left shift operator turns specific bits on

How to Make (Almost) Everything | Fall 2017