Hi,
I'm experimenting with an Arduino Uno R3 and a MacBook. I want to compile and load a code via terminal, so, I go in the Arduino folder and I search for avr-gcc and avrdude.
I compile using avr-gcc a very simple Blink program that turns on and off a LED, and I get the hex file with no errors or warnings.
Then I run in the terminal (from the Arduino.app/Contents/Resources/Java/hardware/tools/avr/ folder)
To push the hex file into the Arduino, and I get the following output
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.00s
avrdude: Device signature = 0x1e950f
avrdude: safemode: Fuses OK
avrdude done. Thank you.
It seems that everything is ok, but the led doesn't blink, so the code has not been loaded on the Arduino. I double checked the code to be sure that's not a code problem. The avrdude configuration file is from the arduino IDE, so it should work. I think the problem is the programmer, but I don't know, maybe the problem is somewhere else.
Oh, and, if you know, is there a way to use Arduino as ISP via terminal?
No, the hex file is 2.0Kb, it is not empty.
I was using an avr-gcc downloaded from the internet that maybe adds automatically the main().
However I deleted it, and using the avr-gcc inside the arduino I had to rewrite the code:
However reading the avrdude manual I discovered that the avrdude command I typed is wrong, because it doesn't write nothing on the Arduino. The right command is this:
Now running the same avrdude command I get this error:
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.00s
avrdude: Device signature = 0x1e950f
avrdude: erasing chip
avrdude: reading input file "./test.hex"
avrdude: input file ./test.hex auto detected as invalid format
avrdude: invalid input file format: -1
avrdude: read from file './test.hex' failed
avrdude: safemode: Fuses OK
avrdude done. Thank you.
but if I compile with --mmcu=atmega328p I don't get that error, but my code seems to not work. It should switch on a led connected on pin 4. Here is my test code
#ifndef __AVR_ATmega328P__
#define __AVR_ATmega328P__ // microcontroller
#endif
#define F_CPU 16000000 // frequency of the cpu
#include <avr/io.h>
//#include <avr/interrupt.h>
#include <util/delay.h>
#include <util/atomic.h>
int main() {
DDRD = _BV(PIND4); // pin 4
PORTD = _BV(PIND4);
while (1) {
_delay_ms(1000);
PORTD = _BV(PIND4);
}
return 0;
}
avr-gcc does not produce .hex files, it produces elf format files which you would then convert to .hex files with "avr-objcopy" Something like:
avr-objcopy -O ihex -R .eeprom a.out float.hex
Being a "well behaved" unix-style program, avr-gcc will happily and silently allow you to name the elf file with a .hex "type", even though the format is entirely different.