@@ -65,7 +65,6 @@ uint8_t BME280::begin()
65
65
{
66
66
// Check the settings structure values to determine how to setup the device
67
67
uint8_t dataToWrite = 0 ; // Temporary variable
68
-
69
68
switch (settings.commInterface )
70
69
{
71
70
@@ -76,6 +75,14 @@ uint8_t BME280::begin()
76
75
case SPI_MODE:
77
76
// start the SPI library:
78
77
SPI.begin ();
78
+ #ifdef ARDUINO_ARCH_ESP32
79
+ SPI.setFrequency (1000000 );
80
+ // Data is read and written MSb first.
81
+ SPI.setBitOrder (SPI_MSBFIRST);
82
+ // Like the standard arduino/teensy comment below, mode0 seems wrong according to standards
83
+ // but conforms to the timing diagrams when used for the ESP32
84
+ SPI.setDataMode (SPI_MODE0);
85
+ #else
79
86
// Maximum SPI frequency is 10MHz, could divide by 2 here:
80
87
SPI.setClockDivider (SPI_CLOCK_DIV32);
81
88
// Data is read and written MSb first.
@@ -85,6 +92,7 @@ uint8_t BME280::begin()
85
92
// This was SPI_MODE3 for RedBoard, but I had to change to
86
93
// MODE0 for Teensy 3.1 operation
87
94
SPI.setDataMode (SPI_MODE3);
95
+ #endif
88
96
// initalize the data ready and chip select pins:
89
97
pinMode (settings.chipSelectPin , OUTPUT);
90
98
digitalWrite (settings.chipSelectPin , HIGH);
0 commit comments