Skip to content

Commit 15da182

Browse files
Peter Van HoyweghenPeter Van Hoyweghen
Peter Van Hoyweghen
authored and
Peter Van Hoyweghen
committed
Support at89sx mcu's by adding the possibility to specify the polarity of the target reset signal.
1 parent 56e0910 commit 15da182

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@ void heartbeat() {
123123
analogWrite(LED_HB, hbval);
124124
}
125125

126+
static bool rst_active_high;
127+
128+
void reset_target(bool reset)
129+
{
130+
digitalWrite(RESET, ((reset && rst_active_high) || (!reset && !rst_active_high)) ? HIGH : LOW);
131+
}
132+
126133
void loop(void) {
127134
// is pmode active?
128135
if (pmode) {
@@ -242,23 +249,32 @@ void set_parameters() {
242249
+ buff[18] * 0x00000100
243250
+ buff[19];
244251

252+
// avr devices have active low reset, at89sx are active high
253+
rst_active_high = (param.devicecode >= 0xe0);
245254
}
246255

247256
void start_pmode() {
248257
SPI.begin();
249-
digitalWrite(RESET, HIGH);
258+
// SPI.begin() has configured SS as output,
259+
// so SPI master mode is selected.
260+
// We have defined RESET as pin 10,
261+
// which for many arduino's is not the SS pin.
262+
// So we have to configure RESET as output here,
263+
// (reset_target() first sets the level correct)
264+
reset_target(false);
250265
pinMode(RESET, OUTPUT);
266+
251267
digitalWrite(SCK, LOW);
252268
delay(20);
253-
digitalWrite(RESET, LOW);
269+
reset_target(true);
254270
delay(50);
255271
spi_transaction(0xAC, 0x53, 0x00, 0x00);
256272
pmode = 1;
257273
}
258274

259275
void end_pmode() {
260276
SPI.end();
261-
digitalWrite(RESET, HIGH);
277+
reset_target(false);
262278
pinMode(RESET, INPUT);
263279
pmode = 0;
264280
}

0 commit comments

Comments
 (0)