mirror of
https://github.com/arduino/Arduino.git
synced 2025-03-14 11:29:26 +01:00
Moving SPI pin initialization from constructor to begin() function. That way, the SPI library won't alter any pin states unless / until you call begin().
This commit is contained in:
parent
08feacbb40
commit
b89d8a9c11
@ -60,6 +60,9 @@ long pressure = 0;
|
|||||||
long lastReadingTime = 0;
|
long lastReadingTime = 0;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
// start the SPI library:
|
||||||
|
SPI.begin();
|
||||||
|
|
||||||
// start the Ethernet connection and the server:
|
// start the Ethernet connection and the server:
|
||||||
Ethernet.begin(mac, ip);
|
Ethernet.begin(mac, ip);
|
||||||
server.begin();
|
server.begin();
|
||||||
@ -68,8 +71,6 @@ void setup() {
|
|||||||
pinMode(dataReadyPin, INPUT);
|
pinMode(dataReadyPin, INPUT);
|
||||||
pinMode(chipSelectPin, OUTPUT);
|
pinMode(chipSelectPin, OUTPUT);
|
||||||
|
|
||||||
// start the SPI library:
|
|
||||||
SPI.begin();
|
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
|
|
||||||
//Configure SCP1000 for low noise configuration:
|
//Configure SCP1000 for low noise configuration:
|
||||||
|
@ -25,8 +25,11 @@ W5100Class W5100;
|
|||||||
|
|
||||||
void W5100Class::init(void)
|
void W5100Class::init(void)
|
||||||
{
|
{
|
||||||
initSS();
|
delay(300);
|
||||||
|
|
||||||
|
SPI.begin();
|
||||||
|
initSS();
|
||||||
|
|
||||||
writeMR(1<<RST);
|
writeMR(1<<RST);
|
||||||
writeTMSR(0x55);
|
writeTMSR(0x55);
|
||||||
writeRMSR(0x55);
|
writeRMSR(0x55);
|
||||||
|
@ -13,8 +13,7 @@
|
|||||||
|
|
||||||
SPIClass SPI;
|
SPIClass SPI;
|
||||||
|
|
||||||
SPIClass::SPIClass()
|
void SPIClass::begin() {
|
||||||
{
|
|
||||||
// Set direction register for SCK and MOSI pin.
|
// Set direction register for SCK and MOSI pin.
|
||||||
// MISO pin automatically overrides to INPUT.
|
// MISO pin automatically overrides to INPUT.
|
||||||
// When the SS pin is set as OUTPUT, it can be used as
|
// When the SS pin is set as OUTPUT, it can be used as
|
||||||
@ -29,12 +28,15 @@ SPIClass::SPIClass()
|
|||||||
digitalWrite(MOSI, LOW);
|
digitalWrite(MOSI, LOW);
|
||||||
digitalWrite(SS, HIGH);
|
digitalWrite(SS, HIGH);
|
||||||
|
|
||||||
SPCR = _BV(SPE) | _BV(MSTR);
|
|
||||||
|
|
||||||
// Warning: if the SS pin ever becomes a LOW INPUT then SPI
|
// Warning: if the SS pin ever becomes a LOW INPUT then SPI
|
||||||
// automatically switches to Slave, so the data direction of
|
// automatically switches to Slave, so the data direction of
|
||||||
// the SS pin MUST be kept as OUTPUT.
|
// the SS pin MUST be kept as OUTPUT.
|
||||||
SPCR = _BV(SPE) | _BV(MSTR);
|
SPCR |= _BV(MSTR);
|
||||||
|
SPCR |= _BV(SPE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SPIClass::end() {
|
||||||
|
SPCR &= ~_BV(SPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SPIClass::setBitOrder(uint8_t bitOrder)
|
void SPIClass::setBitOrder(uint8_t bitOrder)
|
||||||
|
@ -35,8 +35,6 @@
|
|||||||
|
|
||||||
class SPIClass {
|
class SPIClass {
|
||||||
public:
|
public:
|
||||||
SPIClass();
|
|
||||||
|
|
||||||
inline static byte transfer(byte _data);
|
inline static byte transfer(byte _data);
|
||||||
|
|
||||||
// SPI Configuration methods
|
// SPI Configuration methods
|
||||||
@ -44,8 +42,8 @@ public:
|
|||||||
inline static void attachInterrupt();
|
inline static void attachInterrupt();
|
||||||
inline static void detachInterrupt(); // Default
|
inline static void detachInterrupt(); // Default
|
||||||
|
|
||||||
inline static void begin(); // Default
|
static void begin(); // Default
|
||||||
inline static void end();
|
static void end();
|
||||||
|
|
||||||
static void setBitOrder(uint8_t);
|
static void setBitOrder(uint8_t);
|
||||||
static void setDataMode(uint8_t);
|
static void setDataMode(uint8_t);
|
||||||
@ -69,12 +67,4 @@ void SPIClass::detachInterrupt() {
|
|||||||
SPCR &= ~_BV(SPIE);
|
SPCR &= ~_BV(SPIE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SPIClass::begin() {
|
|
||||||
SPCR |= _BV(SPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SPIClass::end() {
|
|
||||||
SPCR &= ~_BV(SPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -36,13 +36,14 @@ const int chipSelectPin = 7;
|
|||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
// initalize the data ready and chip select pins:
|
|
||||||
pinMode(dataReadyPin, INPUT);
|
|
||||||
pinMode(chipSelectPin, OUTPUT);
|
|
||||||
|
|
||||||
// start the SPI library:
|
// start the SPI library:
|
||||||
SPI.begin();
|
SPI.begin();
|
||||||
|
|
||||||
|
// initalize the data ready and chip select pins:
|
||||||
|
pinMode(dataReadyPin, INPUT);
|
||||||
|
pinMode(chipSelectPin, OUTPUT);
|
||||||
|
|
||||||
//Configure SCP1000 for low noise configuration:
|
//Configure SCP1000 for low noise configuration:
|
||||||
writeRegister(0x02, 0x2D);
|
writeRegister(0x02, 0x2D);
|
||||||
writeRegister(0x01, 0x03);
|
writeRegister(0x01, 0x03);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user