I have built my own ATTiny programmer, but made a bit of a mistake along the way - I didn't align the headers properly, and now instead of them plugging into pins 10, 11, 12 and 13 as per the ArduinoISP example - they now plug into pins 8, 9, 10 and 11.
If I use some jumper cables to wire the pins to match the ArduinoISP example, it all works fine, meaning the wiring on the actual board is OK, however, I want to be able to just plug my board I have made straight in, and thus need to get the bootloader burning and the uploading to work via pins 8, 9, 10 and 11 instead.
I have tried modifying the example myself by replacing the references to RESET, MOSI, MISO and SCK with my own pin numbers, but this doesn't seem to suffice. When I try to burn the bootloader now, I get the following error:
avrdude: stk500_program_enable(): protocol error, expect=0x14, resp=0x50
avrdude: initialization failed, rc=-1
Double check connections and try again, or use -F to override
this check.
avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x51
If I try to upload a sketch using my version which has the custom pin numbers, I get this error:
avrdude: stk500_getsync(): not in sync: resp=0x00
The wiring of my programmer is the same as can be found here: http://highlowtech.org/?p=1706 except I want the programmer sketch to work with different pins.
Thanks
2 Answers 2
You can't change the pins.
ArduinoISP uses the SPI interface on pins 10-13 which is provided by the underlying AVR hardware.
As a practical matter, you're much better off correcting things so you're using the original pins, which correspond to hardware SPI.
However, it's not terribly hard to implement SPI in software (at a lower performance, of course):
static uint8_t
SPITransfer(uint8_t out)
{
uint8_t in = 0;
for (int i=0; i<8; ++i) {
digitalWrite(MOSI, (out & 0x80) != 0);
out <<= 1;
digitalWrite(SCK, HIGH);
in = (in << 1) | digitalRead(MISO);
digitalWrite(SCK, LOW);
}
return in;
}
There are several SPI modes, but this implements the one used for ISP.