|
@@ -44,12 +44,11 @@
|
44
|
44
|
//#define MAX31865_DEBUG
|
45
|
45
|
//#define MAX31865_DEBUG_SPI
|
46
|
46
|
|
47
|
|
-#include <SoftwareSPI.h>
|
48
|
|
-
|
49
|
47
|
#include "../inc/MarlinConfig.h"
|
50
|
48
|
|
51
|
|
-#if HAS_MAX31865 && !LIB_USR_MAX31865
|
|
49
|
+#if HAS_MAX31865 && !USE_ADAFRUIT_MAX31865
|
52
|
50
|
|
|
51
|
+//#include <SoftwareSPI.h> // TODO: switch to SPIclass/SoftSPI
|
53
|
52
|
#include "MAX31865.h"
|
54
|
53
|
|
55
|
54
|
// The maximum speed the MAX31865 can do is 5 MHz
|
|
@@ -62,7 +61,7 @@ SPISettings MAX31865::spiConfig = SPISettings(
|
62
|
61
|
500000
|
63
|
62
|
#endif
|
64
|
63
|
, MSBFIRST
|
65
|
|
- , SPI_MODE1 // CPOL0 CPHA1
|
|
64
|
+ , SPI_MODE_1 // CPOL0 CPHA1
|
66
|
65
|
);
|
67
|
66
|
|
68
|
67
|
#ifndef LARGE_PINMAP
|
|
@@ -153,15 +152,17 @@ void MAX31865::begin(max31865_numwires_t wires, float zero, float ref) {
|
153
|
152
|
OUT_WRITE(_cs, HIGH);
|
154
|
153
|
|
155
|
154
|
if (_sclk != TERN(LARGE_PINMAP, -1UL, -1)) {
|
156
|
|
- // define pin modes for Software SPI
|
|
155
|
+ // Define pin modes for Software SPI
|
157
|
156
|
#ifdef MAX31865_DEBUG
|
158
|
157
|
SERIAL_ECHOLN("Initializing MAX31865 Software SPI");
|
159
|
158
|
#endif
|
160
|
|
-
|
161
|
|
- swSpiBegin(_sclk, _miso, _mosi);
|
162
|
|
-
|
163
|
|
- } else {
|
164
|
|
- // start and configure hardware SPI
|
|
159
|
+
|
|
160
|
+ OUT_WRITE(_sclk, LOW);
|
|
161
|
+ SET_OUTPUT(_mosi);
|
|
162
|
+ SET_INPUT(_miso);
|
|
163
|
+ }
|
|
164
|
+ else {
|
|
165
|
+ // Start and configure hardware SPI
|
165
|
166
|
#ifdef MAX31865_DEBUG
|
166
|
167
|
SERIAL_ECHOLN("Initializing MAX31865 Hardware SPI");
|
167
|
168
|
#endif
|
|
@@ -169,9 +170,6 @@ void MAX31865::begin(max31865_numwires_t wires, float zero, float ref) {
|
169
|
170
|
SPI.begin();
|
170
|
171
|
}
|
171
|
172
|
|
172
|
|
- // SPI Begin must be called first, then init
|
173
|
|
- _spi_speed = swSpiInit(SPI_QUARTER_SPEED, _sclk, _mosi);
|
174
|
|
-
|
175
|
173
|
setWires(wires);
|
176
|
174
|
enableBias(false);
|
177
|
175
|
autoConvert(false);
|
|
@@ -486,7 +484,17 @@ uint8_t MAX31865::spixfer(uint8_t x) {
|
486
|
484
|
if (_sclk == TERN(LARGE_PINMAP, -1UL, -1))
|
487
|
485
|
return SPI.transfer(x);
|
488
|
486
|
|
489
|
|
- return swSpiTransfer(x, _spi_speed, _sclk, _miso, _mosi);
|
|
487
|
+ uint8_t reply = 0;
|
|
488
|
+ for (int i = 7; i >= 0; i--) {
|
|
489
|
+ reply <<= 1;
|
|
490
|
+ WRITE(_sclk, HIGH);
|
|
491
|
+ WRITE(_mosi, x & (1 << i));
|
|
492
|
+ WRITE(_sclk, LOW);
|
|
493
|
+ if (READ(_miso))
|
|
494
|
+ reply |= 1;
|
|
495
|
+ }
|
|
496
|
+
|
|
497
|
+ return reply;
|
490
|
498
|
}
|
491
|
499
|
|
492
|
|
-#endif // HAS_MAX31865 && !LIB_USR_MAX31865
|
|
500
|
+#endif // HAS_MAX31865 && !USE_ADAFRUIT_MAX31865
|