Zápisník experimentátora
This question is asked by people trying to program another microcontroller using the Arduino. If other components are connected to the microcontroller, and the microcontroller has a program that manipulates the pins through which it is programmed, is there a real chance that Arduino will be damaged? To get the answer to this question, let's look at how ISP programming works.
The ISP programming algorithm is as follows:
There is ArduinoISP
sketch for Arduino. In its source code, you can view the entire algorithm.
void start_pmode() {
// Reset target before driving PIN_SCK or PIN_MOSI
// SPI.begin() will configure SS as output, so SPI master mode is selected.
// We have defined RESET as pin 10, which for many Arduinos is not the SS pin.
// So we have to configure RESET as output here,
// (reset_target() first sets the correct level)
reset_target(true);
pinMode(RESET, OUTPUT);
SPI.begin();
SPI.beginTransaction(SPISettings(SPI_CLOCK, MSBFIRST, SPI_MODE0));
// See AVR datasheets, chapter "SERIAL_PRG Programming Algorithm":
// Pulse RESET after PIN_SCK is low:
digitalWrite(PIN_SCK, LOW);
delay(20); // discharge PIN_SCK, value arbitrarily chosen
reset_target(false);
// Pulse must be minimum 2 target CPU clock cycles so 100 usec is ok for CPU
// speeds above 20 KHz
delayMicroseconds(100);
reset_target(true);
// Send the enable programming command:
delay(50); // datasheet: must be > 20 msec
spi_transaction(0xAC, 0x53, 0x00, 0x00);
pmode = 1;
}
void end_pmode() {
SPI.end();
// We're about to take the target out of reset so configure SPI pins as input
pinMode(PIN_MOSI, INPUT);
pinMode(PIN_SCK, INPUT);
reset_target(false);
pinMode(RESET, INPUT);
pmode = 0;
}
Due to the fact that the target microcontroller is reset before programming and can not set the HIGH / LOW to the pin, there can be no unnecessary shortcut on programming pins. However, it is important that these pins are no hardly connected to power or GND. If there are LEDs with a resistor, it is completely safe.
Neither the connection to power or GND should not damage Arduino. Arduino has internal protection diodes, which will also survive short circuit and ISP programmer should very quickly find out that its pins can not control and disconnect. From my own experience, I can confirm that the ATtiny85 and ATmega328P microcontrollers will also survive short switch of the VCC and GND, so in normal circuits you should under no circumstances manage to destroy your Arduino.
24.02.2018