Week8 Assignment

Read a microcontroller data sheet

program your board to do something, with as many different programming languages. and programming environments as possible

In this week, we're going to use Attiny44 for microcontroller. I read it's datasheet and tried to figure out every pin's role. Especially pin 7 MOSI(Master Out Slave In) and pin 8 MISO(Master In Slave Out)

Then I tried to use a USBtinyISP to load program to my board.

First, download hello.ftdi.44.echo.c, hello.ftdi.44.echo.c.make

Then connect my board with USBtinyISP:

Enter into the download folder, use command: make -f hello.ftdi.44.echo.c.make

Then sudo make -f hello.ftdi.44.echo.c.make program-usbtiny-fuses

It didn't work:

avr-objcopy -O ihex hello.ftdi.44.echo.out hello.ftdi.44.echo.c.hex;\
    avr-size --mcu=attiny44 --format=avr hello.ftdi.44.echo.out
AVR Memory Usage
----------------
Device: attiny44

Program:     758 bytes (18.5% Full)
(.text + .data + .bootloader)

Data:         64 bytes (25.0% Full)
(.data + .bss + .noinit)


avrdude -p t44 -P usb -c usbtiny -U lfuse:w:0x5E:m

avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.


avrdude done.  Thank you.

make: *** [program-usbtiny-fuses] Error 1

I checked this tutorial and tried to understand fues.

What are the fuses?

There are 3 bytes of permanent storage in the chip called 'fuse low byte', 'fuse high byte' and 'fuse extended byte'. These bytes are called fuses and can be reprogrammed as many times as you want and determines the behaviour of the chip. To do that, their value is not erased when the chip is powered off or reprogrammed.

Each microchip has its own definition for the values that must have the fuses.

I googled the error message and find this fab note, it recommended install FTDI chip drivers. But error still occur after installing FTDI driver.

Something went wrong with my board. I should make a new board after our lab reopen next week...

update

I make a new board and fuse again:

Next step

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

Now I can burn program into the board. Download term.py

python term.py /dev/ttyUSB0 115200, didn't work:

Traceback (most recent call last):
  File "term.py", line 89, in <module>
    ser = serial.Serial(port,speed)
  File "/Library/Python/2.7/site-packages/serial/serialutil.py", line 180, in __init__
    self.open()
  File "/Library/Python/2.7/site-packages/serial/serialposix.py", line 294, in open
    raise SerialException(msg.errno, "could not open port %s: %s" % (self._port, msg))
serial.serialutil.SerialException: [Errno 2] could not open port /dev/ttyUSB0: [Errno 2] No such file or directory: '/dev/ttyUSB0'

Then my classmate told me to try Arduino.

  1. Add board

    open Arduino preference, Additional Boards Manager URLs:

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

  2. Settings

    Set board:"ATtiny", Processor:"ATtiny44", Clock:"20 MHz", Port:"USB"

  3. Program

    Load the Blink example, change pin No. from 13 to 7:

  4. Burn Bootloader

  5. It worked!

Ref:


Round1: make your own ISP

The FabISP is an in-system programmer for AVR microcontrollers, designed for production within a FabLab. It allows you to program the microcontrollers on other boards you make.

FabISP: Programming tutorial

Steps on OSX

  • Download and Install Crosspack AVR
  • Get Make (via XCode)
  • Download the firmware FabISP Firmware for MacOS 10.8.2
  • unzip and cd into the firmware directory
  • Open the Makefile with TextEditor
  • change avrisp2 to usbtiny

    Go to the line that says:

    #AVRDUDE = avrdude -c usbtiny -p $(DEVICE) # edit this line for your programmer
    AVRDUDE = avrdude -c avrisp2 -P usb -p $(DEVICE) # edit this line for your programmer
    
    • If using the USBtiny programmer or another FabISP, remove the "#" in front of the line with "usbtiny" in it. Add a "#" to beginning the line with the "avrisp2" in it to comment it out. Save the Makefile
  • cd firmware directory, make clean

    • the result should be rm -f main.hex main.lst main.obj main.cof main.list main.map main.eep.hex main.elf *.o usbdrv/*.o main.s usbdrv/oddebug.s usbdrv/usbdrv.s

      when make hex, error occured

      kidults-NMB:fabISP_mac.0.8.2_firmware kidult$ make hex
      avr-gcc -Wall -Os -DF_CPU=20000000     -Iusbdrv -I. -DDEBUG_LEVEL=0 -mmcu=attiny44 -c usbdrv/usbdrv.c -o usbdrv/usbdrv.o
      make: avr-gcc: No such file or directory
      make: *** [usbdrv/usbdrv.o] Error 1
      

      Then I plugin my FabISP, it showed:

  • Next, need to set the fuses so the board will use the external clock (crystal) by typing: make fuse

    It seemed that something went wrong:

      avrdude -c usbtiny -p attiny44  -U hfuse:w:0xDF:m -U lfuse:w:0xFF:m
      avrdude: Error: Could not find USBtiny device (0x1781/0xc9f)
      avrdude done.  Thank you.
      make: *** [fuse] Error 1
    

    I couldn't figure out why. It seemed like a gcc complling problem or my board didn't work.

Round2: Using a USBtinyISP

Other attempts

Try to use Arduino as ISP

Tutorial: Arduino board as ATtiny programmer

Installing ATtiny support in Arduino

  • Open the preferences dialog in the Arduino software.
  • Find the “Additional Boards Manager URLs” field near the bottom of the dialog.
  • Paste the following URL into the field (use a comma to separate it from any URLs you’ve 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 preferences.
  • Open the boards manager in the “Tools > Board” menu.
  • Scroll to the bottom of the list; you should see an entry for “ATtiny”.
  • Install
  • Close the boards manager. You should now see an entry for ATtiny in the “Tools > Board” menu.

把 USBtinyISP 通过 usb 连接到 new MacBook,指示灯不亮。开始了折腾之旅。。。

连接到 MacBook pro,指示灯亮,但是上传不了程序

查到一个说明文档 ,发现电脑上没有安装 avrdude, 但还是不知道该怎么装。

突然间看到 new MacBook 电量低,想起会不会是因为电量不足所以识别不了 USBtinyISP? 插上插头。。。果然

results matching ""

    No results matching ""