Background Image

Embedded Programming

Background Image

Program my board with C & Arduino

This week's mission is to program my board to blink, with as many different programming languages and programming environments as possible.

Background Image

Program an ATtiny with Arduino

image

Read data sheet

I started by reading the entire data sheet for ATtiny 44A. Then followed the tutorial by high-low tech to program the micro-controller with Arduino.

image

Choose Board

image

Turn Arduino board into an “in-system programmer” (ISP)

image

Connect the Arduino board and the ATtiny

image

Use the Arduino as ISP to upload the blink program to the ATtiny

Basic Knowledge Review

Feature Image Feature Image
Project Image
Project Image

Program with C

image

Bit manipulation

Set a bit: bit_fld |= (1 << n)
Get a bit: bit_fld & (1 << n)
Clear a bit: bit_fld &= ~(1 << n)
Toggle a bit: bit_fld ^= (1 << n)
Test a bit: bit_fld & (1 << n)

  b7 b6 b5 b4 b3 b2 b1 b0
ch 1 0 0 0 0 0 1 1
mask 0 0 0 0 1 0 0 0
ch & mask 1 0 0 0 1 0 1 1

This table answers why AND, OR, XOR, NOT, and bit shifts are used for bitwise operations.
OR mask and character set only b3 to 1, leave others unchanged. AND get b3. To clear b7 from 1 to 0, NOT the mask first, then AND with ch, this set b7 to 0.
A little tutorial here.

image

Connect

Irina got a very good tutorial on this part.
First, check the FabISP we made is actually programmed and recognized by the computer.
Next, connect the FabISP to the computer using a tinyUSB cable, connect the FabISP board to the new board with a 6-pin wire, and finally connect back the computer using an FTDI cable.

image

Create a .hex file

Download Neil's hello.ftdi.44.echo.c and hello.ftdi.44.echo.c.make files. Each .c files has to have a .make counterpart.
Open the directory in which the files are located from Terminal.
Use command make -f hello.ftdi.44.echo.c.make to create a .hex file, which check errors, compiles and transfers the .c instructions into bit information.

image

Prepare the chip to write

Command: make -f hello.ftdi.44.echo.c.make program-usbtiny-fuses

image

Program the .c instructions onto the board

Command: make -f hello.ftdi.44.echo.c.make program-usbtiny

image

Use CoolTerm to test Echo

image

Echo Board

The serial communication works!

image

image

Blink

I adapted and modified Irina's blink code blink.c and blink.make to make my butterfly shine.
Command: make -f blink.c.make

image

Prepare the chip to write

Command: make -f blink.c.make program-usbtiny-fuses

image

Program the .c instructions onto the board

Command: make -f blink.c.make program-usbtiny

image

blink.c

image

blink.make

image

blink.c.hex

image

blink.out

image

Some failures

Check connections

image

I've made another two boards, but both of them gave me these errors. Thanks to Honghao letting me try out with his board.

Project Image
Project Image
Project Image
Project Image