@@ -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) digitalWrite (LED_PMODE, HIGH);
@@ -238,23 +245,32 @@ void set_parameters() {
238
245
+ buff[18 ] * 0x00000100
239
246
+ buff[19 ];
240
247
248
+ // avr devices have active low reset, at89sx are active high
249
+ rst_active_high = (param.devicecode >= 0xe0 );
241
250
}
242
251
243
252
void start_pmode () {
244
253
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 );
246
261
pinMode (RESET, OUTPUT);
262
+
247
263
digitalWrite (SCK, LOW);
248
264
delay (20 );
249
- digitalWrite (RESET, LOW );
265
+ reset_target ( true );
250
266
delay (50 );
251
267
spi_transaction (0xAC , 0x53 , 0x00 , 0x00 );
252
268
pmode = 1 ;
253
269
}
254
270
255
271
void end_pmode () {
256
272
SPI.end ();
257
- digitalWrite (RESET, HIGH );
273
+ reset_target ( false );
258
274
pinMode (RESET, INPUT);
259
275
pmode = 0 ;
260
276
}
0 commit comments