Skip to content

Commit

Permalink
Replaces the ridiculous #define to set the correct bitorder depending…
Browse files Browse the repository at this point in the history
… on the hardware used

* Instead we're using instantiating SPISettings correctly and passing arguments depending on hardware.
* rolls version
  • Loading branch information
edspark committed Oct 2, 2020
1 parent 91b0ca5 commit 1e1a717
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name= SparkFun AS3935 Lightning Detector Arduino Library
version=1.4.2
version=1.4.3
author=Elias Santistevan
maintainer=SparkFun Electronics <sparkfun.com>
sentence=This is an Arduino Library for the AS3935 Lightning Detector by AMS
Expand Down
8 changes: 4 additions & 4 deletions src/SparkFun_AS3935.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ bool SparkFun_AS3935::beginSPI(uint8_t user_CSPin, uint32_t spiPortSpeed, SPICla

// Bit order is different for ESP32
#ifdef ESP32
#define _bitOrder SPI_MSBFIRST
mySpiSettings = SPISettings(spiPortSpeed, SPI_MSBFIRST, SPI_MODE1);
#else
#define _bitOrder MSBFIRST
mySpiSettings = SPISettings(spiPortSpeed, MSBFIRST, SPI_MODE1);
#endif

return true;
Expand Down Expand Up @@ -464,7 +464,7 @@ void SparkFun_AS3935::_writeRegister(uint8_t _wReg, uint8_t _mask, uint8_t _bits
_spiWrite = _readRegister(_wReg); // Get the current value of the register
_spiWrite &= _mask; // Mask the position we want to write to
_spiWrite |= (_bits << _startPosition); // Write the given bits to the variable
_spiPort->beginTransaction(SPISettings(_spiPortSpeed, _bitOrder, SPI_MODE1));
_spiPort->beginTransaction(mySpiSettings);
digitalWrite(_cs, LOW); // Start communication
_spiPort->transfer(_wReg); // Start write command at given register
_spiPort->transfer(_spiWrite); // Write to register
Expand All @@ -487,7 +487,7 @@ uint8_t SparkFun_AS3935::_readRegister(uint8_t _reg)
{

if(_i2cPort == NULL) {
_spiPort->beginTransaction(SPISettings(_spiPortSpeed, _bitOrder, SPI_MODE1));
_spiPort->beginTransaction(mySpiSettings);
digitalWrite(_cs, LOW); // Start communication.
_spiPort->transfer(_reg |= SPI_READ_M); // Register OR'ed with SPI read command.
_regValue = _spiPort->transfer(0); // Get data from register.
Expand Down
4 changes: 4 additions & 0 deletions src/SparkFun_AS3935.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <SPI.h>
#include <Arduino.h>



typedef uint8_t i2cAddress;

const i2cAddress defAddr = 0x03; // Default ADD0 and ADD1 are HIGH
Expand Down Expand Up @@ -235,6 +237,8 @@ class SparkFun_AS3935
uint8_t _regValue; // Variable for returned register data.
uint8_t _spiWrite; // Variable used for SPI write commands.
uint8_t _i2cWrite; // Variable used for SPI write commands.

SPISettings mySpiSettings;

// Address variable.
i2cAddress _address;
Expand Down

0 comments on commit 1e1a717

Please sign in to comment.