0
\$\begingroup\$

I want to make a Arduino ISP-Shield universal exchangeable between Arduino models. For this purpose I want to use the ISP-Header in combination with Pin 10 (like the Arduino Ethernet-Shield does). The reason for this is the different pin out on UNO, Leonardo and Mega boards.

At the moment I'm breadboarding to test using pin 10 on ATmega2560 as Slave-Reset. On the Mega I put the default ISP-Sketch (you can found it on GitHub) and changing the following line:

#define RESET     SS

(which is PB0 broken out on PIN 53 of ArduinoMega2560) to

#define RESET     10

(PB4 of the ATmega2560)

With this change the board could later use the same layout for UNO and Mega Arduinos.

The RESET constant is used for "slave-select" which, in my knowledge does not need to be on any special pin as the other pins that should use hardware SPI pins. But when changing to pin 10 it does not work. It's driving me crazy. Here's the avrdude verbose output:

Binary sketch size: 826 bytes (of a 8,192 byte maximum)
/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/avrdude -C/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/etc/avrdude.conf -v -v -v -v -pattiny85 -cstk500v1 -P/dev/tty.usbmodemfa131 -b19200 -Uflash:w:/var/folders/yp/trpfnkdn75zfzpl33tyw0tpm0000gn/T/build385603139236268699.tmp/Blink.cpp.hex:i 

avrdude: Version 5.11, compiled on Sep  2 2011 at 18:52:52
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/etc/avrdude.conf"
         User configuration file is "/Users/mose/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : /dev/tty.usbmodemfa131
         Using Programmer              : stk500v1
         Overriding Baud Rate          : 19200
avrdude: Send: 0 [30]   [20] 
avrdude: Send: 0 [30]   [20] 
avrdude: Send: 0 [30]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [10] 
         AVR Part                      : ATtiny85
         Chip Erase delay              : 4500 us
         PAGEL                         : P00
         BS2                           : P00
         RESET disposition             : possible i/o
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65     6     4    0 no        512    4      0  4000  4500 0xff 0xff
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           flash         65     6    32    0 yes      8192   64    128  4500  4500 0xff 0xff
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           lock           0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           lfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           hfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           efuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           calibration    0     0     0    0 no          2    0      0     0     0 0x00 0x00

         Programmer Type : STK500
         Description     : Atmel STK500 Version 1.x firmware
avrdude: Send: A [41] . [80]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [02] 
avrdude: Recv: . [10] 
avrdude: Send: A [41] . [81]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [01] 
avrdude: Recv: . [10] 
avrdude: Send: A [41] . [82]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [12] 
avrdude: Recv: . [10] 
avrdude: Send: A [41] . [98]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [00] 
avrdude: Recv: . [10] 
         Hardware Version: 2
         Firmware Version: 1.18
         Topcard         : Unknown
avrdude: Send: A [41] . [84]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [00] 
avrdude: Recv: . [10] 
avrdude: Send: A [41] . [85]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [00] 
avrdude: Recv: . [10] 
avrdude: Send: A [41] . [86]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [00] 
avrdude: Recv: . [10] 
avrdude: Send: A [41] . [87]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [00] 
avrdude: Recv: . [10] 
avrdude: Send: A [41] . [89]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [00] 
avrdude: Recv: . [10] 
         Vtarget         : 0.0 V
         Varef           : 0.0 V
         Oscillator      : Off
         SCK period      : 0.1 us

avrdude: Send: A [41] . [81]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [01] 
avrdude: Recv: . [10] 
avrdude: Send: A [41] . [82]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [12] 
avrdude: Recv: . [10] 
avrdude: Send: B [42] . [14] . [00] . [00] . [01] . [01] . [01] . [01] . [03] . [ff] . [ff] . [ff] . [ff] . [00] @ [40] . [02] . [00] . [00] . [00]   [20] . [00]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [10] 
avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny85
avrdude: Send: P [50]   [20] 
avrdude: ser_recv(): programmer is not responding
avrdude: stk500_recv(): programmer is not responding

To check my wiring, I tried using the default pin 53 instead of 10 and with this simple change everything works just fine. What is wrong here? How do I get it working with pin 10? I even tried using another Mega2560 board with the same results :-(

It's clear to me that the program stops at the point where it avrdude tells to start program mode and call start_pmode();. In void start_pmode() the constant RESET is used, but I can not see anything wrong there...

\$\endgroup\$
0
\$\begingroup\$

I’m pretty sure you CAN use a different output pin as as the slave select, but you have to take care of the original SS pin to avoid becoming accidentally enslaved yourself. Either set pin 53 as an output, or pull it high.

See section 21.1.2 in the 2560 data sheet for details.

By adding

pinMode(53,OUTPUT);

in void setup() it should work.

\$\endgroup\$
  • \$\begingroup\$ Yeah, that did the trick! I added pinMode(53,OUTPUT); to void setup() and now it's working fine. I don't know why this change is needed? I read 21.1.2 in the data sheet, but I have no peripherial circuit connected to 53, it's NC. It would be nice if you could add why this happens without anything connected? \$\endgroup\$ – Mose May 13 '13 at 16:58
  • \$\begingroup\$ I thought some more about it and I'm pretty sure someone at my local FabLab did the same on his Leonardo without the need for setting SS to OUTPUT... I'm confused... \$\endgroup\$ – Mose May 13 '13 at 17:06
  • \$\begingroup\$ By default, a pin is in INPUT mode, and an unconnected pin may be more likely than not to read LOW. That part is a bit beyond my EE skills to determine fully, but it makes sense that at best, you have a random chance of SS being high. \$\endgroup\$ – microtherion May 13 '13 at 17:11
  • \$\begingroup\$ I’ve done this kind of thing on a Micro, without adverse consequences, but on a Leonardo / Micro, SS is connected to a LED, so most likely the pin is set to OUTPUT by the boot loader. It would be interesting to see what happened if you set SS explicitly to INPUT on those boards. \$\endgroup\$ – microtherion May 13 '13 at 17:12
  • \$\begingroup\$ I'll check if it's because of this LED thing and floating pins... I'll add it as an edit to your answer as soon as I get my hands on a Leonardo. TY \$\endgroup\$ – Mose May 13 '13 at 17:15
0
\$\begingroup\$

Walking through your the code vs. your output, shows it likely is getting stuck on SPI.transfer(a); from spi_transaction(0xAC, 0x53, 0x00, 0x00); of void start_pmode() in response to avrdudes P [50] [20].

Asking one self why?. Well the SPI is either not ON or not Clocking. The SPI.begin() sets SS as HIGH/output and SPCR as MSTR|SPE. Basically turning on the SPI, waiting for SPDR to send.

Note the SS is defined by ..\hardware\arduino\variants\standard\pins_arduino.h(40): static const uint8_t SS = ??; which is different for each board. using different values you then need to set the correct pin in this case 53 as output.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.