Sunday, 22 April 2012

Double the space – using a 1284P on Sanguinololu.

(Edit - see summary at end, the first attempts were not completely successful)

We have recently had a number of inquiries about upgrading the ATMEGA 644P on Sanguinololu to the ATMEGA 1284P. The original specs on the reprap wiki for the board stated it was “drop-in compatible”. It is physically; both the 644P and the 1284P are the same 40 pin DIP package, with the same pin-outs. Turns out it is not as “drop-in compatible” as far as bootloaders and firmware go.

A number of threads on the forums have talked about using this chip, either on the Sanguinololu or the Gen 7 electronics with people suggesting the Mighty 1248P bootloader. Written by ManiacBug and available on github this bootloader suffers from one rather large issue – it's designed for Arduino 1.0. The firmware I am familiar with (Sprinter and Marlin) are pre-1.0 Arduino. A bit more searching found that there was a version of Sanguino available for Arduino 0023 which supported the 1284P. Brilliant!

Loading the bootloader

The first thing to be aware of is that you need a ISP capable of working with the 1284P. We have previously used the USBTiny ISP by ladyada, which works great; reliable and economical, but cannot handle AVRs with flash memory over 64k. Looking around I got hold of a Pololu ISP, which can handle the 1284P.

Getting the Pololu ISP recognised by my computer in Windows 7 was straightforward. The ISP also has a TTL breakout as a second COM port but this is not required here. If you are used to the USBtiny, be aware that the Pololu ISP does not provide power through the ISCP connection. This fact was lost on me the first time I tried to load the bootloader, but after applying power separately to the Sanguinololu board it works fine.

The next step is to get the Arduino IDE setup right in order to burn the bootloader. I had to configure two things, the new Pololu ISP, and the 1284P bootloader.
Starting with the ISP; I added the following lines to “Arduino-0023\hardware\arduino\programmers.txt”:

The option “AVR ISP v2” will now appear within the IDE under the programmers menu.

For the 1284P bootloader I got the Sanguino files from google code and installed them within the Arduino directory. I extracted the entire zip into “Arduino-0023\hardware\Sanguino\”. Restarting the Arduino-0023 IDE gives:(note the Mighty 1284P... listing is there from previous experimenting)

I burnt the “Sanguino W/ATMega1284p 16Mhz” bootloader using the AVR ISP v2 programmer selection with no issues.

Quick Test

To confirm the bootloader had uploaded properly I ran a couple of quick test programs from the Arduino examples:

“Blink” worked fine, changed the blinking pin to pin 31 as this is easily accessible on the expansion header (A0 on extension header). (edit thanks to Alan Ryder - I had my analogue port numbering back to front and originally wrote pin 24, which is actually A7)
Next test was the “AnalogInOutSerial” example which also worked fine:

Passing these quick tests gave me the confidence that the bootloader was working. Next: Firmware.

Firmware

Sprinter compiles fine in Arduino 0023 choosing the Sanguino 644P option and so I had high hopes for it compiling with no issues choosing the 1284P. It did compile ok but then proceeded to hand on upload with no errors, just an infinite time to upload.

Doing a bit more searching I came across eMaker’s 1284P Github download (not sure why I did not find this earlier!). JM references Steve’s Fix It Shop blog where he mentions the different fuse settings required as the Sanguinololu uses a ceramic resonator, not a crystal oscillator:

Low 0xD6High 0xDCExt 0xFD

These fuses get set in the boards.txt file.

So with a new fuse settings in the boards.txt I started from the beginning again. Upload bootloader: Tried the Sanguino 0023 version again with the different fuse settings and got the following error for the Arduino IDE:

With more than a little frustration I gave up on the Sanguino 0023R3 bootloader and switched to the version that came in the zip from JM at eMaker linked above. In the readme it is stated to be the Mighty 1284P; however the boards.txt file looks identical to the Sanguino 0023R3 with the modified fuse settings.

Update: make sure you copy the avrdude.conf from JM's zip. This contains the definition of the 1284p - if you don't have this then the Arduino environment will say that a 1284p is "unknown". I overwrote the stock avrdude.conf in arduino-0023\hardware\tools\avr\etc\

This time the bootloader uploaded with no problems and a quick test with the "AnalogInOutSerial" example went fine as well.

Third time lucky with the Sprinter upload! A quick test with pronterface shows the firmware connects and talks back (M105 gives temp return).

Next test was Marlin which also uploaded fine. I setup the board in a test environment with a potentiometer in place of the hotend thermistor for the extruder (to trick the firmware into thinking the hotend was hot) and with no stepper drivers or anything connected. I then dumped a large g-code file onto an SD card and will let that run for a bit to see if anything breaks before connecting the board to an actual printer:

Summary

Use a ISP programmer capable of burning a AVR with 128k flash, like the Pololu programmer.

Check your fuse settings, Crystal Oscillators vs Ceramic Resonators.

I had best luck with Jean-Marc's bundle of bootloader and Sanguno core, available on github

8 comments:

"make sure you copy the avrdude.conf from JM's zip. This contains the definition of the 1284p, if you don't have this then the Arduino environment will say that a 1284p is "unknown". I overwrote the stock avrdude.conf in arduino-0023\hardware\tools\avr\etc\ "

This is at the loading the bootloader stage. I am actually trying to burn the atmega644 bootloader to an atmega644 chip but thought I would follow your guide becuase it is well explained. Unfortunately, I must have gone wrong somewhere, any idea?

Thanks, this helped alot. I found that I had to burn the bootloader using yours and an Arduino Uno programmed as an AVR ISP then restore the standard hardware setup I had in there to program my Sanguino board with Marlin. Worked great then.