Revert "changeable spi class and settings"
This reverts commit 9c221e59ee.
This commit is contained in:
@@ -11,6 +11,16 @@
|
||||
// Functions for setting up the Arduino
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* Prepares the output pins.
|
||||
*/
|
||||
MFRC522::MFRC522( byte chipSelectPin, ///< Arduino pin connected to MFRC522's SPI slave select input (Pin 24, NSS, active low)
|
||||
byte resetPowerDownPin ///< Arduino pin connected to MFRC522's reset and power down input (Pin 6, NRSTPD, active low). If there is no connection from the CPU to NRSTPD, set this to constant UNUSED_PIN. In this case, only soft reset will be used in PCD_Init().
|
||||
) {
|
||||
_chipSelectPin = chipSelectPin;
|
||||
_resetPowerDownPin = resetPowerDownPin;
|
||||
} // End constructor
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
// Basic interface functions for communicating with the MFRC522
|
||||
@@ -23,12 +33,12 @@
|
||||
void MFRC522::PCD_WriteRegister( PCD_Register reg, ///< The register to write to. One of the PCD_Register enums.
|
||||
byte value ///< The value to write.
|
||||
) {
|
||||
_spiClass->beginTransaction(_spiSettings); // Set the settings to work with SPI bus
|
||||
SPI.beginTransaction(SPISettings(MFRC522_SPICLOCK, MSBFIRST, SPI_MODE0)); // Set the settings to work with SPI bus
|
||||
digitalWrite(_chipSelectPin, LOW); // Select slave
|
||||
_spiClass->transfer(reg); // MSB == 0 is for writing. LSB is not used in address. Datasheet section 8.1.2.3.
|
||||
_spiClass->transfer(value);
|
||||
SPI.transfer(reg); // MSB == 0 is for writing. LSB is not used in address. Datasheet section 8.1.2.3.
|
||||
SPI.transfer(value);
|
||||
digitalWrite(_chipSelectPin, HIGH); // Release slave again
|
||||
_spiClass->endTransaction(); // Stop using the SPI bus
|
||||
SPI.endTransaction(); // Stop using the SPI bus
|
||||
} // End PCD_WriteRegister()
|
||||
|
||||
/**
|
||||
@@ -39,14 +49,14 @@ void MFRC522::PCD_WriteRegister( PCD_Register reg, ///< The register to write to
|
||||
byte count, ///< The number of bytes to write to the register
|
||||
byte *values ///< The values to write. Byte array.
|
||||
) {
|
||||
_spiClass->beginTransaction(_spiSettings); // Set the settings to work with SPI bus
|
||||
SPI.beginTransaction(SPISettings(MFRC522_SPICLOCK, MSBFIRST, SPI_MODE0)); // Set the settings to work with SPI bus
|
||||
digitalWrite(_chipSelectPin, LOW); // Select slave
|
||||
_spiClass->transfer(reg); // MSB == 0 is for writing. LSB is not used in address. Datasheet section 8.1.2.3.
|
||||
SPI.transfer(reg); // MSB == 0 is for writing. LSB is not used in address. Datasheet section 8.1.2.3.
|
||||
for (byte index = 0; index < count; index++) {
|
||||
_spiClass->transfer(values[index]);
|
||||
SPI.transfer(values[index]);
|
||||
}
|
||||
digitalWrite(_chipSelectPin, HIGH); // Release slave again
|
||||
_spiClass->endTransaction(); // Stop using the SPI bus
|
||||
SPI.endTransaction(); // Stop using the SPI bus
|
||||
} // End PCD_WriteRegister()
|
||||
|
||||
/**
|
||||
@@ -56,12 +66,12 @@ void MFRC522::PCD_WriteRegister( PCD_Register reg, ///< The register to write to
|
||||
byte MFRC522::PCD_ReadRegister( PCD_Register reg ///< The register to read from. One of the PCD_Register enums.
|
||||
) {
|
||||
byte value;
|
||||
_spiClass->beginTransaction(_spiSettings); // Set the settings to work with SPI bus
|
||||
SPI.beginTransaction(SPISettings(MFRC522_SPICLOCK, MSBFIRST, SPI_MODE0)); // Set the settings to work with SPI bus
|
||||
digitalWrite(_chipSelectPin, LOW); // Select slave
|
||||
_spiClass->transfer(0x80 | reg); // MSB == 1 is for reading. LSB is not used in address. Datasheet section 8.1.2.3.
|
||||
value = _spiClass->transfer(0); // Read the value back. Send 0 to stop reading.
|
||||
SPI.transfer(0x80 | reg); // MSB == 1 is for reading. LSB is not used in address. Datasheet section 8.1.2.3.
|
||||
value = SPI.transfer(0); // Read the value back. Send 0 to stop reading.
|
||||
digitalWrite(_chipSelectPin, HIGH); // Release slave again
|
||||
_spiClass->endTransaction(); // Stop using the SPI bus
|
||||
SPI.endTransaction(); // Stop using the SPI bus
|
||||
return value;
|
||||
} // End PCD_ReadRegister()
|
||||
|
||||
@@ -80,26 +90,26 @@ void MFRC522::PCD_ReadRegister( PCD_Register reg, ///< The register to read from
|
||||
//Serial.print(F("Reading ")); Serial.print(count); Serial.println(F(" bytes from register."));
|
||||
byte address = 0x80 | reg; // MSB == 1 is for reading. LSB is not used in address. Datasheet section 8.1.2.3.
|
||||
byte index = 0; // Index in values array.
|
||||
_spiClass->beginTransaction(_spiSettings); // Set the settings to work with SPI bus
|
||||
SPI.beginTransaction(SPISettings(MFRC522_SPICLOCK, MSBFIRST, SPI_MODE0)); // Set the settings to work with SPI bus
|
||||
digitalWrite(_chipSelectPin, LOW); // Select slave
|
||||
count--; // One read is performed outside of the loop
|
||||
_spiClass->transfer(address); // Tell MFRC522 which address we want to read
|
||||
SPI.transfer(address); // Tell MFRC522 which address we want to read
|
||||
if (rxAlign) { // Only update bit positions rxAlign..7 in values[0]
|
||||
// Create bit mask for bit positions rxAlign..7
|
||||
byte mask = (0xFF << rxAlign) & 0xFF;
|
||||
// Read value and tell that we want to read the same address again.
|
||||
byte value = _spiClass->transfer(address);
|
||||
byte value = SPI.transfer(address);
|
||||
// Apply mask to both current value of values[0] and the new data in value.
|
||||
values[0] = (values[0] & ~mask) | (value & mask);
|
||||
index++;
|
||||
}
|
||||
while (index < count) {
|
||||
values[index] = _spiClass->transfer(address); // Read value and tell that we want to read the same address again.
|
||||
values[index] = SPI.transfer(address); // Read value and tell that we want to read the same address again.
|
||||
index++;
|
||||
}
|
||||
values[index] = _spiClass->transfer(0); // Read the final byte. Send 0 to stop reading.
|
||||
values[index] = SPI.transfer(0); // Read the final byte. Send 0 to stop reading.
|
||||
digitalWrite(_chipSelectPin, HIGH); // Release slave again
|
||||
_spiClass->endTransaction(); // Stop using the SPI bus
|
||||
SPI.endTransaction(); // Stop using the SPI bus
|
||||
} // End PCD_ReadRegister()
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user