File tree Expand file tree Collapse file tree 1 file changed +19
-3
lines changed
build/shared/examples/11.ArduinoISP/ArduinoISP Expand file tree Collapse file tree 1 file changed +19
-3
lines changed Original file line number Diff line number Diff 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+
126133void 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
247256void 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
259275void end_pmode () {
260276 SPI.end ();
261- digitalWrite (RESET, HIGH );
277+ reset_target ( false );
262278 pinMode (RESET, INPUT);
263279 pmode = 0 ;
264280}
You can’t perform that action at this time.
0 commit comments