@@ -86,24 +86,6 @@ uint8_t BME280::begin()
86
86
case SPI_MODE:
87
87
// start the SPI library:
88
88
SPI.begin ();
89
- #ifdef ARDUINO_ARCH_ESP32
90
- SPI.setFrequency (1000000 );
91
- // Data is read and written MSb first.
92
- SPI.setBitOrder (SPI_MSBFIRST);
93
- // Like the standard arduino/teensy comment below, mode0 seems wrong according to standards
94
- // but conforms to the timing diagrams when used for the ESP32
95
- SPI.setDataMode (SPI_MODE0);
96
- #else
97
- // Maximum SPI frequency is 10MHz, could divide by 2 here:
98
- SPI.setClockDivider (SPI_CLOCK_DIV32);
99
- // Data is read and written MSb first.
100
- SPI.setBitOrder (MSBFIRST);
101
- // Data is captured on rising edge of clock (CPHA = 0)
102
- // Base value of the clock is HIGH (CPOL = 1)
103
- // This was SPI_MODE3 for RedBoard, but I had to change to
104
- // MODE0 for Teensy 3.1 operation
105
- SPI.setDataMode (SPI_MODE3);
106
- #endif
107
89
// initialize the data ready and chip select pins:
108
90
pinMode (settings.chipSelectPin , OUTPUT);
109
91
digitalWrite (settings.chipSelectPin , HIGH);
@@ -586,6 +568,7 @@ void BME280::readRegisterRegion(uint8_t *outputPointer , uint8_t offset, uint8_t
586
568
break ;
587
569
588
570
case SPI_MODE:
571
+ SPI.beginTransaction (settings.spiSettings );
589
572
// take the chip select low to select the device:
590
573
digitalWrite (settings.chipSelectPin , LOW);
591
574
// send the device the register you want to read:
@@ -599,6 +582,7 @@ void BME280::readRegisterRegion(uint8_t *outputPointer , uint8_t offset, uint8_t
599
582
}
600
583
// take the chip select high to de-select:
601
584
digitalWrite (settings.chipSelectPin , HIGH);
585
+ SPI.endTransaction ();
602
586
break ;
603
587
604
588
default :
@@ -647,14 +631,7 @@ uint8_t BME280::readRegister(uint8_t offset)
647
631
break ;
648
632
649
633
case SPI_MODE:
650
- // take the chip select low to select the device:
651
- digitalWrite (settings.chipSelectPin , LOW);
652
- // send the device the register you want to read:
653
- SPI.transfer (offset | 0x80 ); // Ored with "read request" bit
654
- // send a value of 0 to read the first byte returned:
655
- result = SPI.transfer (0x00 );
656
- // take the chip select high to de-select:
657
- digitalWrite (settings.chipSelectPin , HIGH);
634
+ readRegisterRegion (&result, offset, 1 );
658
635
break ;
659
636
660
637
default :
@@ -699,6 +676,7 @@ void BME280::writeRegister(uint8_t offset, uint8_t dataToWrite)
699
676
break ;
700
677
701
678
case SPI_MODE:
679
+ SPI.beginTransaction (settings.spiSettings );
702
680
// take the chip select low to select the device:
703
681
digitalWrite (settings.chipSelectPin , LOW);
704
682
// send the device the register you want to read:
@@ -708,6 +686,7 @@ void BME280::writeRegister(uint8_t offset, uint8_t dataToWrite)
708
686
// decrement the number of bytes left to read:
709
687
// take the chip select high to de-select:
710
688
digitalWrite (settings.chipSelectPin , HIGH);
689
+ SPI.endTransaction ();
711
690
break ;
712
691
713
692
default :
0 commit comments