Week 8 — Embedded Programming

1. The Board

During the Week 6 I've produced the simple hello world board with a button and a led. For programming it in C (GCC) i needed to know about the components on the board and how the Micocontroller works:

  • Microcontroller: Attiny44a
  • External clock: 16 Mhz Resonator
  • Isp Pins header
  • FTDI Pins header
  • 1 x Red led
  • 1 x Push button


2. Datasheet and Fuses setting

I read a bit about the Attiny44a in the datasheet.
At page 2 are described the microcontroller's pins; in my case the switch button is connected to the PB2 pin, and the led to the PA7.



Cause i had a different clock source (16Mhz instead of 20Mhz) I wanted to understand if i had to set the fuses differently in the Makefile. In this tutorial I got a good explanation of how to do that: all the we need is inside our microcontroller's datasheet.
Going at page 161 are shown the low 8 bits fuses, and those tells the microcontroller how to deal with the clock:



We have to set 8 bits: At page 25 is described how the microcontroller works with clock sources.
At the beginning of this section is decribed how to set the four CKSEL bits in order to select the proper clock source:



I have an external ceramic resonator, so I have a range of CKSEL (4 bits) fuses between 1000 and 1111. So – jumping at page 28 – there is the specific section for crystal oscillator and ceramic resonator. The first three bits of cksel (3:1) need to be set to 111 because I have a resonator > 8Mhz:



At this point I got it: the already setted fuses 5E in the makefile of the fabacademy repo was already good for me. But i wanted to know what we have set with those bits, as shown before we have:

[CKDIV8] [CKOUT] [SUT1] [SUT0] [CKSEL3] [CKSEL2] [CKSEL1] [CKSEL0]

And converting 5E to binary we have:
CKDIV8 = 0
CKOUT = 1
SUT1 = 0
SUT0 = 1
CKSEL3 = 1
CKSEL2 = 1
CKSEL1 = 1
CKSEL0 = 0

At page 32 we have the description of CKDIV8 (that is programmed in our settings):



Programming the board here in Opendot we all had some time dilation issue using this files to blink the led. Andrea found a solution adding these lines inside the int main (void) {...}:

CLKPR = (1 << CLKPCE); CLKPR = (0 << CLKPS3) | (0 << CLKPS2) | (0 << CLKPS1) | (0 << CLKPS0)

This is exactly what happens setting the CKDIV8 to 1 (unprogrammed), in fact changing the fuses to DE – instead of 5E – is another solution.


At page 30 we have the description of the CKOUT (unprogrammed); that can be used to output the clock:



At page 29 we find the rest of the puzzle that is about the start-up time of the microcontroller: CKSEL[0] and SUT[1:0]. In our case are setted as Raccomended Usage for ceramic resonator and a slowly rising power behaviour (CKSEL[0]=0 SUT[1]=0 SUT[0]=1):




3. Programming the board

Echo firmware

Software required: Crosspack, XCode and Python and Pyserial (how to install Pyserial)
Using the files in the fab academy assignment page I've set my folder with the Makefile, the Echo.c file and a blank term.py file
Then using the terminal I accessed the folder and gave the following commands descripted in the Makefile:
make to convert the firmware from C to hex
make program-usbtiny-fuses to program the fuses
make program-usbtiny to upload the hex file of the program to the microcontroller
python term.py /dev/cu.usbserial-FTFPCJUB 115200 in order to open the serial communication window (the serial port should be setted accordingly as arduino IDE suggest in Tools > Serial Port on your computer)





Blink firmware

Doing the same process of the echo file and giving the following command in the terminal:
make
make program-usbtiny-fuses
make program-usbtiny
the led start blinking, and keeping pushed the button it will blink faster.



4. The Satshakit: a fabbable Arduino

Using the eagle files in the Satshakit repository I lasercutted one board:



Soldered



After that I've tried to upload a blink sketch through the FabIsp in the Arduino IDE, and everythink worked well. I've tried to burn the bootloader in order to use the FTDI cable, but even if the bootloader uploading was fine it didn't work.



Go back in Home