File tree Expand file tree Collapse file tree 1 file changed +9
-0
lines changed
examples/11.ArduinoISP/ArduinoISP Expand file tree Collapse file tree 1 file changed +9
-0
lines changed Original file line number Diff line number Diff line change @@ -114,6 +114,10 @@ class BitBangedSPI {
114114 }
115115
116116 void begin () {
117+ // slow enough for an attiny85 @ 1MHz
118+ // (pulseWidth should be > 2 cpu cycles, so take 3 cycles:)
119+ pulseWidth = 3 ;
120+
117121 pinMode (MISO, INPUT);
118122 pinMode (RESET, OUTPUT);
119123 pinMode (SCK, OUTPUT);
@@ -126,11 +130,16 @@ class BitBangedSPI {
126130 for (unsigned int i = 0 ; i < 8 ; ++i) {
127131 digitalWrite (MOSI, b & 0x80 );
128132 digitalWrite (SCK, HIGH);
133+ delayMicroseconds (pulseWidth);
129134 b = (b << 1 ) | digitalRead (MISO);
130135 digitalWrite (SCK, LOW); // slow pulse
136+ delayMicroseconds (pulseWidth);
131137 }
132138 return b;
133139 }
140+
141+ private:
142+ unsigned long pulseWidth; // in microseconds
134143};
135144
136145static BitBangedSPI SPI;
You can’t perform that action at this time.
0 commit comments