File tree 1 file changed +19
-3
lines changed
build/shared/examples/11.ArduinoISP/ArduinoISP 1 file changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -123,6 +123,13 @@ void heartbeat() {
123
123
analogWrite (LED_HB, hbval);
124
124
}
125
125
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
+
126
133
void loop (void ) {
127
134
// is pmode active?
128
135
if (pmode) {
@@ -242,23 +249,32 @@ void set_parameters() {
242
249
+ buff[18 ] * 0x00000100
243
250
+ buff[19 ];
244
251
252
+ // avr devices have active low reset, at89sx are active high
253
+ rst_active_high = (param.devicecode >= 0xe0 );
245
254
}
246
255
247
256
void start_pmode () {
248
257
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 );
250
265
pinMode (RESET, OUTPUT);
266
+
251
267
digitalWrite (SCK, LOW);
252
268
delay (20 );
253
- digitalWrite (RESET, LOW );
269
+ reset_target ( true );
254
270
delay (50 );
255
271
spi_transaction (0xAC , 0x53 , 0x00 , 0x00 );
256
272
pmode = 1 ;
257
273
}
258
274
259
275
void end_pmode () {
260
276
SPI.end ();
261
- digitalWrite (RESET, HIGH );
277
+ reset_target ( false );
262
278
pinMode (RESET, INPUT);
263
279
pmode = 0 ;
264
280
}
You can’t perform that action at this time.
0 commit comments