Week08: Embedded Programming

Assignment


Microcontroller Data Sheet

I learned that so many information about the product is included in Data Sheet.
I could not understand as I expect, but I found some information related this week assignment which used in C programming.

10. I/O Ports
10.1.1 Configuring the Pin
Each port pin consists of three register bits: DDxn, PORTxn, and PINxn. As shown in “Register Description” on page 66, the DDxn bits are accessed at the DDRx I/O address, the PORTxn bits at the PORTx I/O address, and the PINxn bits at the PINx I/O address.


English Japanese.


Connecting Boards

FabISP
(Week04)
echo hello-world board
(Week06)

Connecting two boards by ISP cable. Ensure blown line is connected GND to GND.


To use USB-Serial FTDI, Virtual COM Port (VCP) Drivers is needed to be installed to PC.
When FabISP writes program, USB-Serial FTDI supplies 5V to echo hello-world board. After programmed, signals go from PC to echo hello-world board via USB-Serial FTDI.


How to run "term.py"

C Programming Language

Download hello.ftdi.44.echo.c.make and hello.ftdi.44.echo.c.
Make a folder on desktop and move these two into it.


Open Terminal, then move to the folder above.
$ cd Desktop/week08/

To program, I follow this file from class page.
$ make -f hello.ftdi.44.echo.c.make
$ sudo make -f hello.ftdi.44.echo.c.make program-usbtiny-fuses
$ sudo make -f hello.ftdi.44.echo.c.make program-usbtiny
.hex and .out were made.

Download term.py from class page and move to the same folder. Then run "term.py" from terminal.

Install pip
Download get-pip.py and move to the folder.
$ sudo python get-pip.py
Install pyserial
$ sudo pip install pyserial

Get serial port information
$ ls /dev | grep usb
cu.usbserial-AI02RJUC
tty.usbserial-AI02RJUC
or
$ ls /dev/tty.*
/dev/tty.Bluetooth-Incoming-Port /dev/tty.usbserial-AI02RJUC

Run term.py
$ python term.py /dev/tty.usbserial-AI02RJUC 115200



Arduino IDE

Choose serial port

Open Serial Console and set the same bps.


Program my board to do something


My board has LED from PA7(pin6) and Tactile Switch from PB2(pin5).


C Programming Language

I add LED blink to "hello.ftdi.44.echo.c".

#define led_pin (1<<PA7)
#define led_port PORTA
#define led_direction DDRA

void blink(){
	set(led_port, led_pin);
	_delay_ms(100);
	clear(led_port, led_pin);
	_delay_ms(100);
}

    output(led_direction, led_pin);
In main loop of while(1){}
      blink();

I changed "hello.ftdi.44.echo" to "hello.ftdi.44.echo.blink" in file name and "PROJECT=" in makefile.
$ cd type_and_blink/
$ make -f hello.ftdi.44.echo.blink.c.make
$ sudo make -f hello.ftdi.44.echo.blink.c.make program-usbtiny-fuses
$ sudo make -f hello.ftdi.44.echo.blink.c.make program-usbtiny
$ python term.py /dev/tty.usbserial-AI02RJUC 115200
download .zip



Arduino
Change "echo hello-world board" to Arduino compatible.

Copy this URL
" https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json ".

Open Arduino IDE -> Preference ->Paste the URL to "Additional Boards Manager URLs".


tool -> board -> Boards Manager...


In Filter your search..., type "attiny" and Install "attiny by David A. Melils".


Select Board, Processor, Clock, Serial Port and Programmer.






Write fuse-bit to the board.


Programming

My LED connected PA7 of ATtiny44, which is Arduino Pin 7.
My button connected PB2 of ATtiny44, which is Arduino Pin 8.
Open sample sketch "Button" and change number of the pins.
download .ino

I recognized I designed the button very close to ISP. It is difficult to press button using my finger and see LED light at same time. I need something thin to press.