Skip to content

Commit

Permalink
Add SPI_Transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
LowPowerLab committed Dec 14, 2018
1 parent e543fb1 commit 6b9d0c9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
13 changes: 13 additions & 0 deletions RFM69.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ bool RFM69::initialize(uint8_t freqBand, uint8_t nodeID, uint8_t networkID)
digitalWrite(_slaveSelectPin, HIGH);
pinMode(_slaveSelectPin, OUTPUT);
SPI.begin();

#ifdef SPI_HAS_TRANSACTION
_settings = SPISettings(4000000, MSBFIRST, SPI_MODE0);
#endif

unsigned long start = millis();
uint8_t timeout = 50;
do writeReg(REG_SYNCVALUE1, 0xAA); while (readReg(REG_SYNCVALUE1) != 0xaa && millis()-start < timeout);
Expand Down Expand Up @@ -477,6 +482,11 @@ void RFM69::select() {
_SPCR = SPCR;
_SPSR = SPSR;
#endif

#ifdef SPI_HAS_TRANSACTION
SPI.beginTransaction(_settings);
#endif

// set RFM69 SPI settings
SPI.setDataMode(SPI_MODE0);
SPI.setBitOrder(MSBFIRST);
Expand All @@ -491,6 +501,9 @@ void RFM69::select() {
// unselect the RFM69 transceiver (set CS high, restore SPI settings)
void RFM69::unselect() {
digitalWrite(_slaveSelectPin, HIGH);
#ifdef SPI_HAS_TRANSACTION
SPI.endTransaction();
#endif
// restore SPI settings to what they were before talking to RFM69
#if defined (SPCR) && defined (SPSR)
SPCR = _SPCR;
Expand Down
3 changes: 3 additions & 0 deletions RFM69.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ class RFM69 {
uint8_t _SPCR;
uint8_t _SPSR;
#endif
#ifdef SPI_HAS_TRANSACTION
SPISettings _settings;
#endif

virtual void receiveBegin();
virtual void setMode(uint8_t mode);
Expand Down

0 comments on commit 6b9d0c9

Please sign in to comment.