Sparkfun Pocket AVR Programmer with IDE (again)

There are two parts to your problem:

  1. You need to program in an Arduino-style bootloader to your chip. To do this you need the Sparkfun AVR Programmer and the AVRDude executable. There isn't really an "off the shelf" 644P compatible bootloader; if you search for Optiboot and get the sources, it has support for the 644p.

  2. After your bootloader works, you would use a plain serial connection to your chip (using USART0 with an appropriate USB to TTL converter - SparkFun sells those also). The boards.txt file works with the Arduino IDE to specify the various settings for your project.

I read somewhere that it is possible to use a programmer like the Pocket AVR programmer while you use the Arduino IDE (basically you don't need the serial connection), but I don't have any idea how that would work.

-- Steven

Thanks.

I mate has used the 644P for a few Arduino projects with no issues at all, using the Sanguino Bootloader. It acts just like a regular Arduino but with more IO etc.

Its just the part of getting the IDE to program over the ISP port via the Pocket Programmer that I dont understand how to set up.
Getting the IDE to program over USB via a FTDI connection to a 644P is no problem.

I just dont know how to put them both together.
I dont have the board on me to test either. Its currently being used in a workshop, so when I go to do the upgrade I need to do, I need it to work else the machine will be out of action till I figure out how to fix it.
I programmed it via Bascom AVR using an old Parallel programmer in the past, but want to upgarde it to Arduino and use the newer sparkfun pocket programmer as the PC that had the parallel port has since died, and I cant find the parallel programmer I used either...

Thanks
J

Using the Sparkfun programmer should be identical to using the Bascom/parallel port programmer - it's the same concept. AVRDude will talk to the Sparkfun programmer no problem.

Yes I realise this, however I want to use the Arduino IDE as the projects I do from now on I want to be Arduino IDE based, rather than Bascom based.

So this project is currently in Bascom, which I am porting to Arduino IDE, and now I just need a method of writing it.

Sorry for the confusion or if I am not being clear.

sanguino.upload.protocol=stk500

That seems to be the part you would need to change, but I dunno what to change it to yet.

BOOM! FOUND
How to Use the Arduino IDE with an External Programmer

You'll have to figure out what to change on the boards.txt but shouldn't be too hard. Heck I may do this myself.
This should work for 328 w/arduino as isp.

##############################################################

usbtiny328.name=[avrisp]ATmega328

usbtiny328.upload.using=avrisp
usbtiny328.upload.maximum_size=32768

usbtiny328.build.mcu=atmega328p
usbtiny328.build.f_cpu=16000000L
usbtiny328.build.core=arduino

Thankyou!

I will try this!

I have added this entry:

atmega644p.name=[usbtinyisp]ATmega644P

atmega644p.upload.using=usbtinyisp
atmega644p.upload.maximum_size=63488

atmega644p.build.mcu=atmega644p
atmega644p.build.f_cpu=16000000L
atmega644p.build.core=arduino

However I am wondering if its possible to set the fuse bits with this also, like what is done for the bootloader, but without actually uploading a bootloader hex file...

Like can I add the following lines (just as an example), and when I tell it to upload the bootloader, it will just modify the fuse bits to suit etc?

atmega644p.bootloader.low_fuses=0xFF
atmega644p.bootloader.high_fuses=0xDC
atmega644p.bootloader.extended_fuses=0xFD
atmega644p.bootloader.unlock_bits=0x3F
atmega644p.bootloader.lock_bits=0x0F

Thanks
J

Maybe I will just have to write the fuses via the AVRdude and then program with the method above, since fuses only get set once (or at least low freq).

avrdude.exe -F -c usbtiny -p atmega644p -U lfuse:w:0xff:m -U hfuse:w:0xdb:m -U efuse:w:0xfd:m

It would be nice to have this in the bootloader section though, without actually having to have a bootloader... hmm.

You'll want to confirm what the fuse values to use, as those in the ".bootloader." section are set assuming you are using an Arduino bootloader.

By the way, here's a site for calculating fuse values: AVR® Fuse Calculator – The Engbedded Blog

Yep already done, thanks though.

Ya know that makes me wanna start building a "Never Ending boards.txt" file for whoever needs it because it's aggrivating to see that things are done time and time again, and documented but then it get's swept in a sea of data that's really hard to search for, and then you have to go looking for it all over again. Maybe something of a wiki?

How I change fuse settings without ever leaving the IDE...

The examples are based on a breadboard ATmega168 running from either an external 16 MHz crystal, or the internal oscillator at 8 MHz, or the internal oscillator at 1 MHz.

  1. Ensure the Arduino IDE is not running.

  2. Add entries to "boards.txt"...

###########################################################################

bb168at16.name=ATmega168 @ 16 MHz

# The following MAY work (pick one)...
# bb168at16.upload.protocol=avrispv2
# bb168at16.upload.using=arduino:arduinoisp
bb168at16.upload.using=pololu

bb168at16.upload.maximum_size=16384
bb168at16.upload.speed=19200

# Start-up time PWRDWN/RESET: 16K CK/14 CK + 65 ms; [CKSEL=1111 SUT=11]
# Brown-out detection level at VCC=4.3 V; [BODLEVEL=100]
# Preserve EEPROM memory through the Chip Erase cycle; [EESAVE=0]
# Serial program downloading (SPI) enabled; [SPIEN=0]
# Boot Flash section size=128 words Boot start address=$1F80; [BOOTSZ=11]

bb168at16.bootloader.low_fuses=0xFF
bb168at16.bootloader.high_fuses=0xD4
bb168at16.bootloader.extended_fuses=0x07
bb168at16.bootloader.path=empty
bb168at16.bootloader.file=empty168at16.hex

bb168at16.bootloader.unlock_bits=0x3F
bb168at16.bootloader.lock_bits=0x0F

bb168at16.build.mcu=atmega168
bb168at16.build.f_cpu=16000000L
bb168at16.build.core=arduino

###########################################################################

bb168at8.name=ATmega168 @ 8 MHz

# The following MAY work (pick one)...
# bb168at8.upload.protocol=avrispv2
# bb168at8.upload.using=arduino:arduinoisp
bb168at8.upload.using=pololu

bb168at8.upload.maximum_size=16384
bb168at8.upload.speed=19200

# Int. RC Osc. 8 MHz; Start-up time PWRDWN/RESET: 6 CK/14 CK + 65 ms; [CKSEL=0010 SUT=10]; default value
# Brown-out detection disabled; [BODLEVEL=111]
# Preserve EEPROM memory through the Chip Erase cycle; [EESAVE=0]
# Serial program downloading (SPI) enabled; [SPIEN=0]
# Boot Flash section size=128 words Boot start address=$1F80; [BOOTSZ=11]

bb168at8.bootloader.low_fuses=0xE2
bb168at8.bootloader.high_fuses=0xD7
bb168at8.bootloader.extended_fuses=0x07
bb168at8.bootloader.path=empty
bb168at8.bootloader.file=empty168at8.hex

bb168at8.bootloader.unlock_bits=0x3F
bb168at8.bootloader.lock_bits=0x0F

bb168at8.build.mcu=atmega168
bb168at8.build.f_cpu=8000000L
bb168at8.build.core=arduino

###########################################################################

bb168at1.name=ATmega168 @ 1 MHz

# The following MAY work (pick one)...
# bb168at1.upload.protocol=avrispv2
# bb168at1.upload.using=arduino:arduinoisp
bb168at1.upload.using=pololu

bb168at1.upload.maximum_size=16384
bb168at1.upload.speed=19200

# Int. RC Osc. 8 MHz; Start-up time PWRDWN/RESET: 6 CK/14 CK + 65 ms; [CKSEL=0010 SUT=10]; default value
# Divide clock by 8 internally; [CKDIV8=0]
# Brown-out detection disabled; [BODLEVEL=111]
# Preserve EEPROM memory through the Chip Erase cycle; [EESAVE=0]
# Serial program downloading (SPI) enabled; [SPIEN=0]
# Boot Flash section size=128 words Boot start address=$1F80; [BOOTSZ=11]

bb168at1.bootloader.low_fuses=0x62
bb168at1.bootloader.high_fuses=0xD7
bb168at1.bootloader.extended_fuses=0x07
bb168at1.bootloader.path=empty
bb168at1.bootloader.file=empty168at1.hex

bb168at1.bootloader.unlock_bits=0x3F
bb168at1.bootloader.lock_bits=0x0F

bb168at1.build.mcu=atmega168
bb168at1.build.f_cpu=1000000L
bb168at1.build.core=arduino

###########################################################################
  1. Start the Arduino IDE.

  2. Enter or load an empty / do nothing sketch...

void setup( void )
{
}

void loop( void )
{
}
  1. Select the first board from your new set (e.g. "ATmega168 @ 16 MHz")

  2. Click Verify

  3. Open Explorer (the thing used to browse the harddrive)

  4. Navigate to the temporary directory; in Windows the path "%TEMP%" gets you there.

  5. In a sub-directory in the temporary directory, locate the corresponding dot-hex file. If the sketch is named "sketch_feb28a" the dot-hex will be named "sketch_feb28a.cpp.hex".

  6. Copy the dot-hex file.

  7. Navigate to the "Arduino/hardware/arduino/bootloaders" directory.

  8. Create a sub-directory named "empty".

  9. Navigate into the "empty" sub-directory.

  10. Paste the dot-hex file.

  11. Rename the dot-hex file to something appropriate for the board like "empty168at16.hex". This filename is the value for the "bootloader.file" entry in "boards.txt".

  12. Switch to the Arduino IDE.

  13. Select the next board (e.g. "ATmega168 @ 8 MHz").

  14. Click Verify

  15. Switch to Explorer

  16. Navigate to the temporary directory (%TEMP%)

  17. In a sub-directory in the temporary directory, locate the corresponding dot-hex file. If the sketch is named "sketch_feb28a" the dot-hex will be named "sketch_feb28a.cpp.hex".

  18. Copy the dot-hex file.

  19. Navigate to the "Arduino/hardware/arduino/bootloaders/empty" directory.

  20. Paste the dot-hex file.

  21. Rename the dot-hex file to something appropriate for the board like "empty168at8.hex".

  22. Repeat steps 16 through 25 for any additional boards.

  23. Close and restart the Arduino IDE.

It is now possible to change the fuse settings with impunity...

  1. Select one of the new boards (like "ATmega168 @ 16 MHz").

  2. Click Tools / Burn Bootloader.

The fuse settings are changed and an empty / do nothing sketch is uploaded. The processor is "hardware safe" and ready with the new fuse settings. For more examples, refer to the Tiny Core boards.txt file and "bootloaders"...
http://code.google.com/p/arduino-tiny/

Now that is beautiful.

So I just need to create the hex of a blank app and load that with the boards.txt and I am away laughing.
I will test it now

Thank you very much

Just curious about the BOOTRST fuse bit.
If I understand correctly, when this bit is programmed, it executes the bootloader code, and then the application code after a reset?
If the bit is unprogrammed, then it executes the application code immediately after a reset?

So I assume, when you normally have a bootloader present, you want BOOTRST programmed?
But in this case, I assume it doesnt really matter since the bootloader file is blank?

Is that correct, or have I interpreted this incorrectly.

Regards
J

##############################################################

atmega644p.name=[usbtinyisp]ATmega644P

atmega644p.upload.using=usbtinyisp
atmega644p.upload.maximum_size=63488

# Ext. Crystal Osc 8Mhz+, Start-up time 16K CK + 65 ms; [CKSEL=1111 SUT=11]
# Brown-out detection level at VCC=4.3 V; [BODLEVEL=100]
# Serial program downloading (SPI) enabled; [SPIEN=0]
# Boot Flash section size=512 words Boot start address=$7E00; [BOOTSZ=11]
# Boot Reset vector Disabled [BOOTRST=1]

atmega644p.bootloader.low_fuses=0xFF
atmega644p.bootloader.high_fuses=0xDF
atmega644p.bootloader.extended_fuses=0xFC
atmega644p.bootloader.path=empty
atmega644p.bootloader.file=empty644p.hex
atmega644p.bootloader.unlock_bits=0x3F
atmega644p.bootloader.lock_bits=0x0F

atmega644p.build.mcu=atmega644p
atmega644p.build.f_cpu=16000000L
atmega644p.build.core=arduino

##############################################################

Time for some testing

JADB:
Just curious about the BOOTRST fuse bit.

Does this help...

Just confirming the boards.txt I listed above works perfectly, with the procedure to make the bootloader.hex blank file that Coding Badly gave.

Brilliant, thanks.

J

Thank you for taking the time to follow-up.