Skip to content

Commit 50f9e53

Browse files
Peter Van HoyweghenPeter Van Hoyweghen
authored andcommitted
Ensure minimum spi pulse width.
1 parent 5a04ab2 commit 50f9e53

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff 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

136145
static BitBangedSPI SPI;

0 commit comments

Comments
 (0)