1. How to program a microcontroller.


Microcontrollers need to have a program stored in memory in order to execute a particular task. The code gets coded on a computer that has the development environment installed with the relevant tools, the binary result gets downloaded into the target microcontroller through a programmer. The different options that will be available will depend on what operating system our host machine runs and what budgetary constraints we might have, there will be several alternatives to code the software and program the microcontroller to run it.

Nowadays is difficult not to find at least a microcontroller in any electronic consumer devices. A microcontroller is an integrated circuit designed to execute sequentially the instructions that command the processing unit what to do with the inputs, outputs and data memory of the microcontroller. These instructions will define the tasks carried out by the microcontroller within the consumer device.

In order to get the binary that gets burnt into the flash memory of the microcontroller, one of the first steps is to get an Integrated Development Environment set up in our machine. This environment would comprise a software toolbox (editor, compiler, linker, etc..) that will allow a developer to generate a program for the microcontroller, and consequently create a file with the relevant specific instructions that will get stored into the internal microcontroller persistent memory.

The process of downloading or programming the memory will be assisted by a hardware tool, in other words a programmer that gets connected between the programming pins of the microcontroller and the PC and will let a file transfer from the latter into the target’s memory space.

Programmer. Atmel AVRISP mkII

Programmer. Atmel AVRISP mkII

Atmel is one of the few silicon manufacturers that offers all the software tools required to work with their microcontrollers free of charge ( and with no restrictions). Therefore if we have a machine running Windows as its O.S. Atmel’s Integrated Development Environment will likely be a convenient choice to work with their microcontrollers, since it is a all in one professional solution at no extra cost. We would neither need to pay for any extra software tools nor licenses.

Regarding the programmer selection, their price vary from a few to several hundred euros. An interesting choice would be to use what Atmel has to offer, that way we could rest assured that the programmer will be fully supported and integrated by the development environment mentioned previously.

If we can’t or don’t want invest in a programmer a work around to get the binaries into the microcontroller would be to do it by a boot loader (similar to Arduino’s approach). A boot loader is a program that resides in non volatile memory (FLASH) within the microcontroller and that through the pins available could store the new binary files our environment will generate into memory every time we want to apply any software changes. However, a physical programmer is needed at least once in order to get the boot loader burnt before its normal use, needless to say that the boot loader will take some of the program memory that could be used for the microcontroller otherwise.

Summing up, in order to make use of a microcontroller in our circuits we will be required to:

  1. Code our program in the preferred development environment that will assist to implement the target functionality.
  2. Compile the code files so that the appropriate machine code file will be generated, and will reside in the microcontroller memory space.
  3. Burn the binary in the microcontroller via some sort of programmer.
  4. Test that the code is executed and the microcontroller functions as expected.

The former steps could have been carried out based on one of the following available tools:

  • Windows. Atmel Studio + programmer: link.
  • Downloading a binary file with avrdude + Arduino or low cost programmer: link.