Skip to content

Commit d271c1c

Browse files
Peter Van HoyweghenPeter Van Hoyweghen
authored andcommitted
BitBangedSPI::begin(): initialize levels of SCK and MOSI. Correct indentation.
1 parent 8d95899 commit d271c1c

File tree

1 file changed

+26
-27
lines changed

1 file changed

+26
-27
lines changed

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

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -135,38 +135,37 @@ friend class BitBangedSPI;
135135
};
136136

137137
class BitBangedSPI {
138-
public:
139-
140-
void beginTransaction(SPISettings settings) {
141-
pulseWidth = 1000 / (settings.clock / 1000);
142-
if (pulseWidth == 0)
143-
pulseWidth = 1;
144-
}
138+
public:
139+
void begin() {
140+
digitalWrite(SCK, LOW);
141+
digitalWrite(MOSI, LOW);
142+
pinMode(SCK, OUTPUT);
143+
pinMode(MOSI, OUTPUT);
144+
pinMode(MISO, INPUT);
145+
}
145146

146-
void begin() {
147-
148-
pinMode(MISO, INPUT);
149-
pinMode(RESET, OUTPUT);
150-
pinMode(SCK, OUTPUT);
151-
pinMode(MOSI, OUTPUT);
152-
}
147+
void beginTransaction(SPISettings settings) {
148+
pulseWidth = 1000 / (settings.clock / 1000);
149+
if (pulseWidth == 0)
150+
pulseWidth = 1;
151+
}
153152

154-
void end() {}
153+
void end() {}
155154

156-
uint8_t transfer (uint8_t b) {
157-
for (unsigned int i = 0; i < 8; ++i) {
158-
digitalWrite(MOSI, b & 0x80);
159-
digitalWrite(SCK, HIGH);
160-
delayMicroseconds(pulseWidth);
161-
b = (b << 1) | digitalRead(MISO);
162-
digitalWrite(SCK, LOW); // slow pulse
163-
delayMicroseconds(pulseWidth);
164-
}
165-
return b;
155+
uint8_t transfer (uint8_t b) {
156+
for (unsigned int i = 0; i < 8; ++i) {
157+
digitalWrite(MOSI, b & 0x80);
158+
digitalWrite(SCK, HIGH);
159+
delayMicroseconds(pulseWidth);
160+
b = (b << 1) | digitalRead(MISO);
161+
digitalWrite(SCK, LOW); // slow pulse
162+
delayMicroseconds(pulseWidth);
166163
}
164+
return b;
165+
}
167166

168-
private:
169-
unsigned long pulseWidth; // in microseconds
167+
private:
168+
unsigned long pulseWidth; // in microseconds
170169
};
171170

172171
static BitBangedSPI SPI;

0 commit comments

Comments
 (0)