From d271c1c8a2fe06fd86dcf826c1ce044a69e80741 Mon Sep 17 00:00:00 2001 From: Peter Van Hoyweghen Date: Tue, 28 Jul 2015 22:31:34 +0200 Subject: [PATCH] BitBangedSPI::begin(): initialize levels of SCK and MOSI. Correct indentation. --- .../11.ArduinoISP/ArduinoISP/ArduinoISP.ino | 57 +++++++++---------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino b/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino index 6d1b74633..a4d3d4dfb 100644 --- a/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino +++ b/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino @@ -135,38 +135,37 @@ friend class BitBangedSPI; }; class BitBangedSPI { - public: +public: + void begin() { + digitalWrite(SCK, LOW); + digitalWrite(MOSI, LOW); + pinMode(SCK, OUTPUT); + pinMode(MOSI, OUTPUT); + pinMode(MISO, INPUT); + } - void beginTransaction(SPISettings settings) { - pulseWidth = 1000 / (settings.clock / 1000); - if (pulseWidth == 0) - pulseWidth = 1; + void beginTransaction(SPISettings settings) { + pulseWidth = 1000 / (settings.clock / 1000); + if (pulseWidth == 0) + pulseWidth = 1; + } + + void end() {} + + uint8_t transfer (uint8_t b) { + for (unsigned int i = 0; i < 8; ++i) { + digitalWrite(MOSI, b & 0x80); + digitalWrite(SCK, HIGH); + delayMicroseconds(pulseWidth); + b = (b << 1) | digitalRead(MISO); + digitalWrite(SCK, LOW); // slow pulse + delayMicroseconds(pulseWidth); } + return b; + } - void begin() { - - pinMode(MISO, INPUT); - pinMode(RESET, OUTPUT); - pinMode(SCK, OUTPUT); - pinMode(MOSI, OUTPUT); - } - - void end() {} - - uint8_t transfer (uint8_t b) { - for (unsigned int i = 0; i < 8; ++i) { - digitalWrite(MOSI, b & 0x80); - digitalWrite(SCK, HIGH); - delayMicroseconds(pulseWidth); - b = (b << 1) | digitalRead(MISO); - digitalWrite(SCK, LOW); // slow pulse - delayMicroseconds(pulseWidth); - } - return b; - } - - private: - unsigned long pulseWidth; // in microseconds +private: + unsigned long pulseWidth; // in microseconds }; static BitBangedSPI SPI;