From 72d02d0474f97105187895cde4f627d18fb7b6ce Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 30 Aug 2021 22:14:26 -0500 Subject: [PATCH] Revert #22618 until solved --- Marlin/src/libs/MAX31865.cpp | 31 ++++++++++++++++++++----------- Marlin/src/libs/MAX31865.h | 1 - 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/Marlin/src/libs/MAX31865.cpp b/Marlin/src/libs/MAX31865.cpp index 8a96e661a79cd..1264c6fbe88ec 100644 --- a/Marlin/src/libs/MAX31865.cpp +++ b/Marlin/src/libs/MAX31865.cpp @@ -48,7 +48,7 @@ #if HAS_MAX31865 && !USE_ADAFRUIT_MAX31865 -#include +//#include // TODO: switch to SPIclass/SoftSPI #include "MAX31865.h" // The maximum speed the MAX31865 can do is 5 MHz @@ -61,7 +61,7 @@ SPISettings MAX31865::spiConfig = SPISettings( 500000 #endif , MSBFIRST - , SPI_MODE1 // CPOL0 CPHA1 + , SPI_MODE_1 // CPOL0 CPHA1 ); #ifndef LARGE_PINMAP @@ -152,15 +152,17 @@ void MAX31865::begin(max31865_numwires_t wires, float zero, float ref) { OUT_WRITE(_cs, HIGH); if (_sclk != TERN(LARGE_PINMAP, -1UL, -1)) { - // define pin modes for Software SPI + // Define pin modes for Software SPI #ifdef MAX31865_DEBUG SERIAL_ECHOLN("Initializing MAX31865 Software SPI"); #endif - swSpiBegin(_sclk, _miso, _mosi); - - } else { - // start and configure hardware SPI + OUT_WRITE(_sclk, LOW); + SET_OUTPUT(_mosi); + SET_INPUT(_miso); + } + else { + // Start and configure hardware SPI #ifdef MAX31865_DEBUG SERIAL_ECHOLN("Initializing MAX31865 Hardware SPI"); #endif @@ -168,9 +170,6 @@ void MAX31865::begin(max31865_numwires_t wires, float zero, float ref) { SPI.begin(); } - // SPI Begin must be called first, then init - _spi_speed = swSpiInit(SPI_QUARTER_SPEED, _sclk, _mosi); - setWires(wires); enableBias(false); autoConvert(false); @@ -485,7 +484,17 @@ uint8_t MAX31865::spixfer(uint8_t x) { if (_sclk == TERN(LARGE_PINMAP, -1UL, -1)) return SPI.transfer(x); - return swSpiTransfer(x, _spi_speed, _sclk, _miso, _mosi); + uint8_t reply = 0; + for (int i = 7; i >= 0; i--) { + reply <<= 1; + WRITE(_sclk, HIGH); + WRITE(_mosi, x & (1 << i)); + WRITE(_sclk, LOW); + if (READ(_miso)) + reply |= 1; + } + + return reply; } #endif // HAS_MAX31865 && !USE_ADAFRUIT_MAX31865 diff --git a/Marlin/src/libs/MAX31865.h b/Marlin/src/libs/MAX31865.h index 13a117447dcab..5d50e870ecd2a 100644 --- a/Marlin/src/libs/MAX31865.h +++ b/Marlin/src/libs/MAX31865.h @@ -90,7 +90,6 @@ class MAX31865 { static SPISettings spiConfig; TERN(LARGE_PINMAP, uint32_t, uint8_t) _sclk, _miso, _mosi, _cs; - uint8_t _spi_speed; float Rzero, Rref; void setConfig(uint8_t config, bool enable);