AVR-Eclipse plug-in provides an integrated interface for editing code, compiling and uploading to the device. And, not to be undervalued, also has a GUI to set fuses and lock bits. It generates Makefiles, so if and when you are ready to graduate from an IDE back to bare bones then you will have something familiar to work from.
This sound great but to make it work you also have to install (avr-libc, binutils-avr, gcc-avr) libraries. I found it easies to do it through the terminal with:
sudo apt-get install gcc-avr binutils-avr gdb-avr avr-libc avrdude
I also installed Package Manager for Ubuntu to able install upgrade and remove software packages (softwares called package in Ubuntu). Finally I feel I have control over what I have installed and an easy way to modify it.
I followed several tutorials on how to set up eclipse for AVR but I could not adjust my configuration for my programmer AVRDude. All I got was a warning saying AVRDude is not supported for static library projects. I spent embarrassedly many hours trying to figure it out. It was only when I went back and created my third project i saw my mistake. Turned out that I had chosen the wrong project setting, and this is something you can not change after project is created.
But the celebration did not last long before I bumped in to next issue, my knowledge of C is next to zero so I had no clue where to go from here... do I create a class or a source file? ...and whats up with that .h? I decided to get out of this rabbit hole as I had spent way to much time on it.
I followed highlowtech.org tutorial on Programing aTTiny with arduino IDE. Compared to Eclipse, Arduino IDE seems like a toy. It strength but also it's weakness is it's simplicity. I have to run the Arduino IDE 1.6.0 with Sudo command to give it access to the USB ports. I can connect and upload sketches but something is of with my serial connection!
Debugging the serial problem
In the code the serial was set to Serial.begin(9600) but in the serial monitor all bauds except 1200 gave me gibberish. This means that the clock speed was off. Turned out that when I made the fuse in the Make file in week 6 I had the wrong setting. "U lfuse:w:0x5E:m" which is 94 in decimal, and i have a crystal at 20mht so my clock speed was wrong and therefor giving me this strange result.
I Burned a bootloder through Arduino IDE with my correct settings and now I got the correct speed and serial monitor is working on the right baud.
Next up where pin confusion, Working with the Arduino IDE you can not follow the data sheet for pin reference! Below is a image of of Arduino pin layout.
Having figured out the pins I could get cracking at the code. I programed the button with state shift. It works like a charm.
#include ]
SoftwareSerial Serial(0, 1); // RX, TX
const int ledPin = 8;
const int buttonPin = 7;
boolean lastButton = LOW;
boolean currentButton = LOW;
boolean ledOn = false;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
Serial.begin(9600);
}
boolean debounce(boolean last){
boolean current = digitalRead(buttonPin);
if(last != current){
delay(5);
current = digitalRead(buttonPin);
}
return current;
}
void loop() {
currentButton = debounce(lastButton);
if(lastButton == HIGH && currentButton == LOW){
ledOn = !ledOn;
Serial.println("o");
}
lastButton = currentButton;
digitalWrite(ledPin, ledOn);
}
State change.Coded with Arduino IDE, programed with Fab ISP.
Writing C code in a text editor seems temptingly minimalistic, but at the same time a bit hard core. Sublime text 3 have a package Sublime C Improved that formats the text to C.
There is no compiler compiler within Sublime (although I think you can write some script for making it automatic) but as I had downloaded AVR-GCC (compiler) and AVRDDUDE (upload to aTTiny within44) I did it through the terminal with the following commands (big thanks to Jani Ylioja)
Compiling was done with GCC and converter it to an .elf file. "Wall"= gives warning i something wrong "-o" rename the exported file and target .c file.
Creat a hex file:
Up load it to the attiny 44 with the fab USBtiny:
PROJECT=FileName
SOURCES=$(PROJECT).c
MMCU=attiny44
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)
program-avrisp2: $(PROJECT).hex
avrdude -p t44 -P usb -c avrisp2 -U flash:w:$(PROJECT).c.hex
program-avrisp2-fuses: $(PROJECT).hex
avrdude -p t44 -P usb -c avrisp2 -U lfuse:w:0x5E:m
program-usbtiny: $(PROJECT).hex
avrdude -p t44 -P usb -c usbtiny -U flash:w:$(PROJECT).c.hex
program-usbtiny-fuses: $(PROJECT).hex
avrdude -p t44 -P usb -c usbtiny -U lfuse:w:0x5E:m
Compile and upload:
If this is the first time you program you micro controller you have to make a fuse before you can start uploading code to it. This will among other things configure your micro controller with the right clock speed
As before open a terminal window in your folder where you saved the Makefile and .c file. Run: sudo program-usbtiny-fuses. You will only have to do this once unless you change your configuration on your board.
DDRB |= BIT(2); // set as output. set bit in register. LED
DDRA &= ~BIT(7); // set as input. clear bit in register. BUTTON
PORTA |= BIT(0) //Turn on 0th bit
PORTA &= ~BIT(0) //Turn off 0th bit
PORTA ^= BIT(0) //Toggle on 0th bit
if (PORTA & BIT(0)) //test to see if bit is set
Code embedded with GitHub Gist.
In week 10 I came back to interrrupts and made this C code for my hello board.
Following tutorial of Scott Zitek: link I downloaded a AVR assemmbler Gerd's AVR Assembler and installing it.
Sublime Test 3 also have a package for assembly code. With the help of Francisco I wrote the assembly code and saved it as an .asm file.
Next I compile the .asm file with gavrsm compiler. In the folder where I saved the blink.asm file. I run gavrsm (through terminal) with the command gavrsm blink.asm. (gavrasm 'filename.asm') This creates 2 files in the same folder, a .hex and a .list file
After that I created (modify) a make file. MakeFile is a utility for automatically building executable programs and libraries from source-code. Project to the file name of my assembly file Open a terminal window in the same folder as the .hex and.list file. I run the command "make fuse" (fuse to initialize the board run once and "make program" (commands that are defined in the make file and uses avrdude) this copies the assembly code over to the ATtiny44
Code Blocks is a free C, C++ and Fortran IDE It is designed to be very extensible and fully configurable, built around a plug-in framework. Any kind of functionality can be added by installing/coding a plug-in. For instance, compiling and debugging functionality is already provided by plug-ins!
This worked so much better the Eclipse. Code Blocks also have a project setting for AVR I could get a project up and running with ease.
How ever on compiling my C code I got a compiler error about #include
But that is how far I got. I was not able to upload or debug any code on my ATtiny44. This is the tutorial I followed but still could not make it work correctly. So at the moment it is just a fancy text editor and nothing more.