@@ -7,7 +7,7 @@ May 20, 2015
7
7
8
8
Resources:
9
9
Uses Wire.h for i2c operation
10
- Uses SPI. h for SPI operation
10
+ Uses _spiPort-> h for SPI operation
11
11
12
12
Development environment specifics:
13
13
Arduino IDE 1.8.5
@@ -87,7 +87,7 @@ uint8_t BME280::begin()
87
87
88
88
case SPI_MODE:
89
89
// start the SPI library:
90
- SPI. begin ();
90
+ _spiPort-> begin ();
91
91
// initialize the data ready and chip select pins:
92
92
pinMode (settings.chipSelectPin , OUTPUT);
93
93
digitalWrite (settings.chipSelectPin , HIGH);
@@ -138,8 +138,9 @@ uint8_t BME280::begin()
138
138
}
139
139
140
140
// Begin comm with BME280 over SPI
141
- bool BME280::beginSPI (uint8_t csPin)
141
+ bool BME280::beginSPI (uint8_t csPin, SPIClass &spiPort )
142
142
{
143
+ _spiPort = &spiPort;
143
144
settings.chipSelectPin = csPin;
144
145
settings.commInterface = SPI_MODE;
145
146
@@ -691,21 +692,21 @@ void BME280::readRegisterRegion(uint8_t *outputPointer , uint8_t offset, uint8_t
691
692
break ;
692
693
693
694
case SPI_MODE:
694
- SPI. beginTransaction (settings.spiSettings );
695
+ _spiPort-> beginTransaction (settings.spiSettings );
695
696
// take the chip select low to select the device:
696
697
digitalWrite (settings.chipSelectPin , LOW);
697
698
// send the device the register you want to read:
698
- SPI. transfer (offset | 0x80 ); // Ored with "read request" bit
699
+ _spiPort-> transfer (offset | 0x80 ); // Ored with "read request" bit
699
700
while ( i < length ) // slave may send less than requested
700
701
{
701
- c = SPI. transfer (0x00 ); // receive a byte as character
702
+ c = _spiPort-> transfer (0x00 ); // receive a byte as character
702
703
*outputPointer = c;
703
704
outputPointer++;
704
705
i++;
705
706
}
706
707
// take the chip select high to de-select:
707
708
digitalWrite (settings.chipSelectPin , HIGH);
708
- SPI. endTransaction ();
709
+ _spiPort-> endTransaction ();
709
710
break ;
710
711
711
712
default :
@@ -799,17 +800,17 @@ void BME280::writeRegister(uint8_t offset, uint8_t dataToWrite)
799
800
break ;
800
801
801
802
case SPI_MODE:
802
- SPI. beginTransaction (settings.spiSettings );
803
+ _spiPort-> beginTransaction (settings.spiSettings );
803
804
// take the chip select low to select the device:
804
805
digitalWrite (settings.chipSelectPin , LOW);
805
806
// send the device the register you want to read:
806
- SPI. transfer (offset & 0x7F );
807
+ _spiPort-> transfer (offset & 0x7F );
807
808
// send a value of 0 to read the first byte returned:
808
- SPI. transfer (dataToWrite);
809
+ _spiPort-> transfer (dataToWrite);
809
810
// decrement the number of bytes left to read:
810
811
// take the chip select high to de-select:
811
812
digitalWrite (settings.chipSelectPin , HIGH);
812
- SPI. endTransaction ();
813
+ _spiPort-> endTransaction ();
813
814
break ;
814
815
815
816
default :
0 commit comments