mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-20 14:54:31 +01:00
BitBangedSPI::begin(): initialize levels of SCK and MOSI. Correct indentation.
This commit is contained in:
parent
8d95899450
commit
d271c1c8a2
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user