Merge pull request #3 from PaulStoffregen/master

SPI transactions
This commit is contained in:
LowPowerLab 2014-07-29 16:45:13 -04:00
commit 43e0150b1b
2 changed files with 13 additions and 3 deletions

View File

@ -32,24 +32,36 @@ SPIFlash::SPIFlash(uint8_t slaveSelectPin, uint16_t jedecID) {
/// Select the flash chip /// Select the flash chip
void SPIFlash::select() { void SPIFlash::select() {
#ifdef SPI_HAS_TRANSACTION
SPI.beginTransaction(SPISettings(33000000, MSBFIRST, SPI_MODE0));
#else
noInterrupts(); noInterrupts();
#endif
digitalWrite(_slaveSelectPin, LOW); digitalWrite(_slaveSelectPin, LOW);
} }
/// UNselect the flash chip /// UNselect the flash chip
void SPIFlash::unselect() { void SPIFlash::unselect() {
digitalWrite(_slaveSelectPin, HIGH); digitalWrite(_slaveSelectPin, HIGH);
#ifdef SPI_HAS_TRANSACTION
SPI.endTransaction();
#else
interrupts(); interrupts();
#endif
} }
/// setup SPI, read device ID etc... /// setup SPI, read device ID etc...
boolean SPIFlash::initialize() boolean SPIFlash::initialize()
{ {
pinMode(_slaveSelectPin, OUTPUT); pinMode(_slaveSelectPin, OUTPUT);
#ifdef SPI_HAS_TRANSACTION
digitalWrite(_slaveSelectPin, HIGH);
#else
unselect(); unselect();
SPI.setDataMode(SPI_MODE0); SPI.setDataMode(SPI_MODE0);
SPI.setBitOrder(MSBFIRST); SPI.setBitOrder(MSBFIRST);
SPI.setClockDivider(SPI_CLOCK_DIV2); //max speed, except on Due which can run at system clock speed SPI.setClockDivider(SPI_CLOCK_DIV2); //max speed, except on Due which can run at system clock speed
#endif
SPI.begin(); SPI.begin();
if (_jedecID == 0 || readDeviceId() == _jedecID) { if (_jedecID == 0 || readDeviceId() == _jedecID) {

View File

@ -17,9 +17,7 @@
// Get the SPIFlash library from here: https://github.com/LowPowerLab/SPIFlash // Get the SPIFlash library from here: https://github.com/LowPowerLab/SPIFlash
#include <SPIFlash.h> #include <SPIFlash.h>
#include <RFM12B.h>
#include <SPI.h> #include <SPI.h>
#include <avr/wdt.h>
#define SERIAL_BAUD 115200 #define SERIAL_BAUD 115200
char input = 0; char input = 0;