As a brief reprieve from my main CPC2 project, I sidetracked into Arduino programming to solve a problem on the CPC2. I need to create an interface to a memory card, with only two wires. To do this, I’m going to use an Atmel (Microchip) ATtiny841 to interface between the memory card SPI interface and a two-wire serial UART. To program this device without spending heaps of money on a dedicated programmer, I’ll use an Arduino to program the Tiny. This post covers setting up an Arduino to write a bootloader into another Arduino or Atmel chip. To test this process, I used an Freetronics EtherTen to program a Freetronics Eleven that had a damaged bootloader. I’m using version 1.8.5 of the Arduino IDE.
First, the hardware. After much trial-and-error and reading various Arduino pages at arduino.cc, I worked out that the ISP pins can be connected straight through and must be configured in the ISP application. Here my notes on the connections:
- SPI defines the MOSI/MISO pins as either in or out depending upon the role of the device, so there’s no need to cross these over. Connect pin 1 to 1, 2 to 2 and so on for pins 1,2,3,4,6.
- Pin 5, [bottom left], is the reset pin and can be connected on the destination, but connected to pin 10 on the source. i.e. Don’t connect pin 5 on the source programmer.
- The 10uF capacitor that is sometimes mentioned in the forums is critical and essential. Do not omit this or you’ll likely see “protocol errors” during programming of the destination device.
Take a look at this image for hints and especially note the 10uF cap, in the source Arduino on the right. Omission of this cost me 2 hours of head scratching. Note the destination device on the left has a fully populated ISP connector.
To set up the source device, open the Arduino IDE and go to File->Examples->ArduinoISP->ArduinoISP. This creates the sample code for the programmer. This generally can be used as-is for the EtherTen. On the EtherTen the SPI pins are separate from the default pins 11,12,13 so the example code will use the hardware SPI. When I used the Eleven as the source, I had some problems, so I uncommented the following line:
This forced the use of pins 11,12,13 as the programming pins. These would need to be connected to the correct pins in the ISP header. See the source code for the correct wiring. Note that the GND pin(6) must be connected, but the VCC pin doesn’t need to be connected if the destination if self-powered.
When the code has been updated, hit CTRL-U or upload to load the sketch into the programmer. This will use the built-in bootloader to load in the new program.
- Note that the ‘Programmer:’ on the tools menu has no effect when using Sketch->Upload as the program upload goes through the USART.
Next, we’ll program the bootloader into the destination. Go to Tools->Programmer and select “Arduino as ISP”. The port should be unchanged as we’re going through source programmer. Next, select the correct destination board under Tools->Board. In my case I’m using a Uno. With this done, simply click on Tools->Burn Bootloader. This action will push the bootloader for the configured chip (Uno). With this done, the chip can be programmed with the Sketch->Upload menu option through its own USART connection.
Finally, if you’re also interested in programming the ATtiny series of chip, here’s the link to the ATtiny Arduino board support file. This can be applied in the File->Preferences page under “Additional Board Manager URL”. It’s added to the board list by going into board manager and downloading the ATtiny board support package.
To see how I’m planning to use this process, take a look at Part 32 of my CPC2 series!