|
@@ -44,7 +44,7 @@
|
44
|
44
|
//#define MAX31865_DEBUG
|
45
|
45
|
//#define MAX31865_DEBUG_SPI
|
46
|
46
|
|
47
|
|
-//TODO: switch to SPIclass/SoftSPI
|
|
47
|
+#include <SoftwareSPI.h>
|
48
|
48
|
|
49
|
49
|
#include "../inc/MarlinConfig.h"
|
50
|
50
|
|
|
@@ -62,7 +62,7 @@ SPISettings MAX31865::spiConfig = SPISettings(
|
62
|
62
|
500000
|
63
|
63
|
#endif
|
64
|
64
|
, MSBFIRST
|
65
|
|
- , SPI_MODE_1 // CPOL0 CPHA1
|
|
65
|
+ , SPI_MODE1 // CPOL0 CPHA1
|
66
|
66
|
);
|
67
|
67
|
|
68
|
68
|
#ifndef LARGE_PINMAP
|
|
@@ -157,10 +157,9 @@ void MAX31865::begin(max31865_numwires_t wires, float zero, float ref) {
|
157
|
157
|
#ifdef MAX31865_DEBUG
|
158
|
158
|
SERIAL_ECHOLN("Initializing MAX31865 Software SPI");
|
159
|
159
|
#endif
|
160
|
|
-
|
161
|
|
- OUT_WRITE(_sclk, LOW);
|
162
|
|
- SET_OUTPUT(_mosi);
|
163
|
|
- SET_INPUT(_miso);
|
|
160
|
+
|
|
161
|
+ swSpiBegin(_sclk, _miso, _mosi);
|
|
162
|
+
|
164
|
163
|
} else {
|
165
|
164
|
// start and configure hardware SPI
|
166
|
165
|
#ifdef MAX31865_DEBUG
|
|
@@ -170,6 +169,9 @@ void MAX31865::begin(max31865_numwires_t wires, float zero, float ref) {
|
170
|
169
|
SPI.begin();
|
171
|
170
|
}
|
172
|
171
|
|
|
172
|
+ // SPI Begin must be called first, then init
|
|
173
|
+ _spi_speed = swSpiInit(SPI_QUARTER_SPEED, _sclk, _mosi);
|
|
174
|
+
|
173
|
175
|
setWires(wires);
|
174
|
176
|
enableBias(false);
|
175
|
177
|
autoConvert(false);
|
|
@@ -484,17 +486,7 @@ uint8_t MAX31865::spixfer(uint8_t x) {
|
484
|
486
|
if (_sclk == TERN(LARGE_PINMAP, -1UL, -1))
|
485
|
487
|
return SPI.transfer(x);
|
486
|
488
|
|
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;
|
|
489
|
+ return swSpiTransfer(x, _spi_speed, _sclk, _miso, _mosi);
|
498
|
490
|
}
|
499
|
491
|
|
500
|
492
|
#endif // HAS_MAX31865 && !LIB_USR_MAX31865
|