Assignment:embedded programming

1. Read data sheet of ATtiny44
2. Program my Hello-world board
  • Correct mistakes in my Hello-world board
  • Step1: Config Arduino for ATtiny24/44/84
  • Step2: Burning the Bootloader
  • Step3: Uploading program in Arduino with USBTiny
  • Step4: Create the Makefile and source C file
  • Step5: Uploading program with FabISP

  • You can download ATtiny24/44/84 data sheet here.

    The following is the main features:
  • High Performance, Low Power AVR® 8-Bit Microcontroller
  • RISC Architecture
  • 2/4/8K Bytes of In-System Programmable Program Memory Flash
  • 128/256/512 Bytes of In-System Programmable EEPROM
  • 128/256/512 Bytes of Internal SRAM
  • One 8-Bit and One 16-Bit Timer/Counter with Two PWM Channels
  • 10-bit ADC
  • Universal Serial Interface
  • In-System Programmable via SPI Port
  • Internal Calibrated Oscillator
  • Available in 20-Pin QFN/MLF & 14-Pin SOIC and PDIP
  • Operating Voltage:2.7 – 5.5V
  • Speed Grade: 0 – 20 MHz @ 4.5 – 5.5V
  • I use ATtiny84 microcontroller, it has 8K Flash program memory , 512Bytes of In-system Programmable EEPROM and 512 Bytes Internal SRAM.

    Home

    Correct mistakes in my Hello-world board

    On week six's assigment, I made my hello-world board. After making, I didn't test it. When I tried to program the bootloader to it this week, an error message occours. This error interrupted me for a few days. At last, I found I made a mistake in using the capacitor of crystal, I used 1UF instead of 10pf. When I changed the right capacitor, the hello-world board works.


    Step1: Config Arduino for ATtiny24/44/84

    This section I refer to Ye Xiaohua and highlowtech.org , they give me a lot of help.

    download ATtiny24/44/84 data sheet here.

    In Arduino, you can install the ATtiny support using the built-in boards manager. If you don't install Arduino, you can download Arduino here.

  • Open the preferences dialog in the Arduino Software. Top Menu "File -> Performane"
  • Paste the following URL into the field, use a comma to separated it from any URLs you have already added
  • https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json
  • Click the OK button to save your updated perference.
  • Open the board manager from top menu "Tools -> Board ->Boards Manager", input "tiny" in the filter text box,the attiny board message list in the list box. Click it and then click the Install button on the down-right.
  • Close the boards manager,You will now see an endtry for ATtiny in the "Tool -> Board"menu, click to choose it.
  • Set the Processor to ATtiny84. From the top menu "Tools -> Processor -> Attiny84"
  • Set the Clock to External 20MHZ. From the top menu "Tools -> Clock -> External 20MHz"

  • Step2: Burning the Bootloader

  • I use USBTiny,Set the Programmer to USBTiny. From the top menu "Tools -> Programmer -> USBTiny"
  • Burn Bootloader to ATtiny84. From the top menu "Tools -> Burn Bootloader". "Done burning bootloader" display in the message bar.

  • Step3: Uploading program in Arduino with USBTiny

    The Pin number of ATtiny84 used in Arduino display following. In the hello-world board, the key was connected to Pin3 and the LED was connect to Pin7.

    I made a program, which function is: In normal state,the LED is bright like a breath light, when the key is pressed,the LED flashes. You can download the program here.

    From the above picture, my program used 16% storage memory space and 2% of dynamic memory.

    The following is the video example of the hello-world board.


    Step4: Create the Makefile and source C file

    At first, I create a new source file name cao.c .

    You can download the program here.

    												
    #include <avr/io.h>
    #include <util/delay.h>
    int main (void) {
        DDRA |= (1 << PA7); // set LED pin as output
        while(1) { // main loop
          PORTA |= (1 << PA7); // switch on the LED
          _delay_ms(100); // wait a second
          PORTA &= ~(1 << PA7); // switch off the LED
          _delay_ms(100); // wait a second
        }
    }

    Then I modify the makefile.

    You can download the makefile here.

    PROJECT=cao
    SOURCES=$(PROJECT).c
    MMCU=attiny84
    F_CPU = 20000000
    
    CFLAGS=-mmcu=$(MMCU) -Wall -Os -DF_CPU=$(F_CPU)
    
    $(PROJECT).hex: $(PROJECT).out
    	avr-objcopy -O ihex $(PROJECT).out $(PROJECT).c.hex;\
    	avr-size --mcu=$(MMCU) --format=avr $(PROJECT).out
     
    $(PROJECT).out: $(SOURCES)
    	avr-gcc $(CFLAGS) -I./ -o $(PROJECT).out $(SOURCES)
    	
    clean:
    	rm -f $(SOURCES).hex $(PROJECT).out 
    	
    all: $(PROJECT).hex 
    	avrdude -p t84 -P usb -c usbtiny -U lfuse:w:0x5E:m 
    	avrdude -p t84 -P usb -c usbtiny -U flash:w:$(PROJECT).c.hex
     
    prog: $(PROJECT).hex
    	avrdude -p t84 -P usb -c usbtiny -U flash:w:$(PROJECT).c.hex
    
    prog-f: $(PROJECT).hex
    	avrdude -p t84 -P usb -c usbtiny -U lfuse:w:0x5E:m
    


    Step5: Uploading program with FabISP

    At first,my FabISP doesn't work when hello-world board connects to it, After checking, I find the VCC pin in SPI connector has no power. According the tutorial of week4, the 0ohm resistor is removed. I solder the 0ohm resistor back, it works.

    The FabIsp is the same with the USBTiny, so operate is the same.

    Press make all in the DOS command window to program the fuse and the board with the FabISP with one command.


    Home