Skip to content

Commit 832c5f3

Browse files
Peter Van Hoyweghen
authored andcommitted
Support at89sx mcu's by adding the possibility to specify the polarity of the target reset signal.
1 parent 7e4cdea commit 832c5f3

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

build/shared/examples/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) digitalWrite(LED_PMODE, HIGH);
@@ -238,23 +245,32 @@ void set_parameters() {
238245
+ buff[18] * 0x00000100
239246
+ buff[19];
240247

248+
// avr devices have active low reset, at89sx are active high
249+
rst_active_high = (param.devicecode >= 0xe0);
241250
}
242251

243252
void start_pmode() {
244253
SPI.begin();
245-
digitalWrite(RESET, HIGH);
254+
// SPI.begin() has configured SS as output,
255+
// so SPI master mode is selected.
256+
// We have defined RESET as pin 10,
257+
// which for many arduino's is not the SS pin.
258+
// So we have to configure RESET as output here,
259+
// (reset_target() first sets the level correct)
260+
reset_target(false);
246261
pinMode(RESET, OUTPUT);
262+
247263
digitalWrite(SCK, LOW);
248264
delay(20);
249-
digitalWrite(RESET, LOW);
265+
reset_target(true);
250266
delay(50);
251267
spi_transaction(0xAC, 0x53, 0x00, 0x00);
252268
pmode = 1;
253269
}
254270

255271
void end_pmode() {
256272
SPI.end();
257-
digitalWrite(RESET, HIGH);
273+
reset_target(false);
258274
pinMode(RESET, INPUT);
259275
pmode = 0;
260276
}

0 commit comments

Comments
 (0)