SparkFun Forums 

Where electronics enthusiasts find answers.

Discussions on the software and hardware for Atmel's STK standard.
By SporkInTucson
#165392
I've been reading a bunch of online discussions about how to program AVRs but I'm not sure I've digested all the info correctly. I'm trying to determine if I can:
  • Code in Atmel Studio (or maybe WinAVR?), presumably producing a hex file, and then...
  • Upload said hex file to Sparkfun's Arduino Pro Mini 328 (5V, 16MHz) using AVRDUDE and Sparkfun's FTDI Basic (5V)
I'm not trying to put bootloaders on a blank AVR and I'm not trying to replace the bootloader that came installed on the Pro Mini, so I don't think I need an ISP. By turning on verbose upload output in the Arduino IDE, I can see the AVRDUDE command line it uses to upload the hex file it generates. I'm assuming that I can use the same command line for a hex file generated by Atmel Studio.
Code: Select all
C:\[...]/tools/avr/bin/avrdude 
   -CC:\[...]/tools/avr/etc/avrdude.conf 
   -v -v -v -v 
   -patmega328p -carduino 
   -P\\.\COM8 -b57600 
   -D 
   -Uflash:w:C:\[...]\some.hex:i
Am I on the right track?
By stevech
#165416
yes, you're on the right track. Studio's .hex file (intel hex format) can go to the AVR via the bootloader already loaded into the AVR's special area of flash. There are many different bootloaders to put into an AVR. Arduino is one of many.

What form of bootloader is in your AVR? Is the AVR an Arduino type?

You can also get a lot of expert help on the forum for avrfreaks.net.
By SporkInTucson
#165418
stevech wrote:There are many different bootloaders to put into an AVR. Arduino is one of many. What form of bootloader is in your AVR? Is the AVR an Arduino type?
I don't know what bootloader is on the Arduino Pro Mini 328 - whatever it shipped with. If there's a standard bootloader for Arduinos in general, I guess it would be that. The Pro Mini has an ATmega328P.
stevech wrote:You can also get a lot of expert help on the forum for avrfreaks.net.
I signed up on avrfreaks but thought I'd start here on SparkFun in case there were any Pro Mini owners that had already tried something similar. Thanks for responding - it's good to know that I've got it straight so far. I've just downloaded Atmel Studio 6, so I'll see if I can get an AVR blink demo turned into hex.
Last edited by SporkInTucson on Sun Nov 10, 2013 1:48 am, edited 1 time in total.
By SporkInTucson
#165422
Just wanted to follow up with a message saying that everything worked. Wrote blink.c in Atmel Studio 6 which compiled it to blink.hex. Was then able to upload blink.hex to the Pro Mini 328 via FTDI Basic using the same avrdude command line that the Arduino IDE uses. The blink.c code follows:
Code: Select all
#include <avr/io.h>
#include <util/delay.h>

int main(void) {
	DDRB |= _BV(DDB5);
	while (1) {
		PORTB ^= _BV(PORTB5);
		_delay_ms(500);
	}
}
By stevech
#167141
SporkInTucson wrote:Just wanted to follow up with a message saying that everything worked. Wrote blink.c in Atmel Studio 6 which compiled it to blink.hex. Was then able to upload blink.hex to the Pro Mini 328 via FTDI Basic using the same avrdude command line that the Arduino IDE uses. The blink.c code follows:
Code: Select all
#include <avr/io.h>
#include <util/delay.h>

int main(void) {
	DDRB |= _BV(DDB5);
	while (1) {
		PORTB ^= _BV(PORTB5);
		_delay_ms(500);
	}
}
Nit-pick: the _BV() macro is old and not recommended for continued use.
Many of us use this style: (1<<bitname);