Embedded Programming

Making lights blink

Getting One's Bearings

This week was on Embedded Programming. This is the process by which we write code that will control our microcontrollers to do (almost) anything. Due to the depth and complexity of the architectures of the microcontrollers we have nowadays, this topic is certainly something that takes years of practice to really master.

In relation to modern microcontrollers and microprocessors that are in our phones and computers, the ATTiny microcontrollers are much more simple. That being said, there is still a host of things that the microcontrollers can do if one knows how to take full advantage of all their capabilities. Beginning to understand those capabilities and being able to leverage them in the programs we write was the task of this week. Besides reading this datasheet for the ATTiny44A, we were tasked to make the board we fabricated last week do something.

Please note that having taken MIT's Computation Structures course, 6.004 (for which there's an online version here), provides a lot of background knowledge that makes understanding the internals of a microcontroller easier. Without this knowledge, understanding the ATTiny datasheet, what registers are, and how program instructions are carried out in a CPU would be a massive bite to chew. Even with this previous knowledge, applying it in this setting and learning the additional knowledge about interfacing with MCU peripherals and all the individual characteristics about the ATTiny and how those are controlled using the C programming language is still a lot.

Reading the Datasheet

The full ATTiny44A datasheet is 286 pages long, and has basically everything an embedded programmer would need to know to take full control over every aspect of the microcontroller. This document is ground truth. It contains 27 sections, and covers topics from pin configurations to the CPU architecture to register descriptions to peripheral systems like ADCs, clock systems, and analog comparators. This document is a beast, and not something to memorize, but definitely a reference to keep close by.

The two things that immediately stood out to me were the feature list and block diagram of the ATTiny.

The features list stood out because it was a pretty sussinct paragraph of everything you'd want to know in order to decide if this particular microcontroller fits your application needs. The block diagram for the ATTiny stood out to me because it looked really similar to what we talked about in 6.004. You can easily see the General Purpose Registers connected to the ALU block, the result of which is put into status registers. There's the Program Counter that feeds into the flash memory where the program is stored and retrieves the next instruction. What wasn't as familiar were all the peripherals on the right hand side and the I/O stuff on the bottom of the diagram.

The datasheet brakes down each and every one of those blocks down into their respective components, and gives detailed instructions on how to interact with them in assemby and in C.

Programming the Blink Board

The programming assignment was to make the board I fabricated last week do something. The board I made was a fairly simple ATTiny44A driven board with an external oscillator, an LED, and a button. So as my first real program, I wanted to make the LED turn on when the button was pressed.

It's important to note that the LED I have is connected to pin PA7. Similarly, the button on the board is connected to pin PB2.


Word1, Word2

Technologies Used

C Programming language, ATTiny44A

Resources Used