@@ -7,7 +7,7 @@ May 20, 2015
77
88Resources: 
99Uses Wire.h for i2c operation 
10- Uses SPI. h for SPI operation 
10+ Uses _spiPort-> h for SPI operation 
1111
1212Development environment specifics: 
1313Arduino IDE 1.8.5 
@@ -87,7 +87,7 @@ uint8_t BME280::begin()
8787
8888	case  SPI_MODE:
8989		//  start the SPI library:
90- 		SPI. begin ();
90+ 		_spiPort-> begin ();
9191		//  initialize the  data ready and chip select pins:
9292		pinMode (settings.chipSelectPin , OUTPUT);
9393		digitalWrite (settings.chipSelectPin , HIGH);
@@ -138,8 +138,9 @@ uint8_t BME280::begin()
138138}
139139
140140// Begin comm with BME280 over SPI
141- bool  BME280::beginSPI (uint8_t  csPin)
141+ bool  BME280::beginSPI (uint8_t  csPin, SPIClass &spiPort )
142142{
143+ 	_spiPort = &spiPort;
143144	settings.chipSelectPin  = csPin;
144145	settings.commInterface  = SPI_MODE;
145146
@@ -691,21 +692,21 @@ void BME280::readRegisterRegion(uint8_t *outputPointer , uint8_t offset, uint8_t
691692		break ;
692693
693694	case  SPI_MODE:
694- 		SPI. beginTransaction (settings.spiSettings );
695+ 		_spiPort-> beginTransaction (settings.spiSettings );
695696		//  take the chip select low to select the device:
696697		digitalWrite (settings.chipSelectPin , LOW);
697698		//  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
699700		while  ( i < length ) //  slave may send less than requested
700701		{
701- 			c = SPI. transfer (0x00 ); //  receive a byte as character
702+ 			c = _spiPort-> transfer (0x00 ); //  receive a byte as character
702703			*outputPointer = c;
703704			outputPointer++;
704705			i++;
705706		}
706707		//  take the chip select high to de-select:
707708		digitalWrite (settings.chipSelectPin , HIGH);
708- 		SPI. endTransaction ();
709+ 		_spiPort-> endTransaction ();
709710		break ;
710711
711712	default :
@@ -799,17 +800,17 @@ void BME280::writeRegister(uint8_t offset, uint8_t dataToWrite)
799800		break ;
800801
801802	case  SPI_MODE:
802- 		SPI. beginTransaction (settings.spiSettings );
803+ 		_spiPort-> beginTransaction (settings.spiSettings );
803804		//  take the chip select low to select the device:
804805		digitalWrite (settings.chipSelectPin , LOW);
805806		//  send the device the register you want to read:
806- 		SPI. transfer (offset & 0x7F );
807+ 		_spiPort-> transfer (offset & 0x7F );
807808		//  send a value of 0 to read the first byte returned:
808- 		SPI. transfer (dataToWrite);
809+ 		_spiPort-> transfer (dataToWrite);
809810		//  decrement the number of bytes left to read:
810811		//  take the chip select high to de-select:
811812		digitalWrite (settings.chipSelectPin , HIGH);
812- 		SPI. endTransaction ();
813+ 		_spiPort-> endTransaction ();
813814		break ;
814815
815816	default :
0 commit comments