Monthly Archives: May 2021

PT100 + MAX31865 + SKR 1.4 Turbo + Marlin, revisited

In PT100 + MAX31865 + SKR 1.4 Turbo + Marlin: how to get it all working, I got an RTD sensor working on my printer by sharing its SPI bus connection with the Trinamic motor drivers I’m using. What if you’re using “dumb” drivers like the DRV8825 or A4988, or you’re using some of Trinamic’s other drivers (like the TMC2209) that are configured over a UART connection? This post describes how to use the MicroSD-card SPI connection instead.

One disadvantage is that you can’t use a display that runs on the EXP1/EXP2 headers (such as the ReprapDiscount full-graphic display). (You could, but then you’d need to tap into the SPI bus going to the display’s SD-card slot, which is beyond the scope of this post.) I have one of Bigtreetech’s full-color touchscreens on the way; those plug into a designated connector that uses a UART connection. Until then (and probably after), I have an ESP-01S (running ESP3D) plugged into the 8-pin “WiFi” connector and can control the printer through that.

Hardware Configuration

This is largely similar to my previous post, except that you’ll want to make up your cable with female connectors all around. Connections between the MAX31865 board and the SKR Pro 1.4 Turbo are as follows. The SPI connector is near the MicroSD slot; E1-CLS is the closed-loop motor connector for E1 from which we’re drawing 3.3V. The colored boxes overlaid on the board diagram show visually where everything plugs in.

MAX31865 pincolorsignalSKR connection typeSKR connection pin
2whiteGNDfemaleSPI, pin 6
3blackVDDfemaleE1-CLS, pin 2
4brownSCKfemaleSPI, pin 3
5redSDOfemaleSPI, pin 1
6orangeSDIfemaleSPI, pin 4
7yellowCSfemaleSPI, pin 5

Software Configuration

This varies a bit from the software-SPI config. First, the changes to Configuration.h in the thermal-settings section:

#define TEMP_SENSOR_0 -5
#define MAX6675_SS_PIN P0_26
#define MAX31865_SENSOR_OHMS_0 100
#define MAX31865_CALIBRATION_OHMS_0 430

Make sure SDSUPPORT is enabled:

#define SDSUPPORT

Next, if you’re using a display plugged into EXP1 and EXP2, you’ll need to disable it. Other features you may have enabled that depend on having a working display may need to be disabled as well. A UART-connected display can be left enabled.

// #define REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER

In Configuration_adv.h, make sure the onboard MicroSD slot is selected instead of a display-connected SD slot:

#define SDCARD_CONNECTION LCD

Due to a pullup on the SCK line, we need to use SPI mode 3 instead of mode 0. AFAIK, this doesn’t affect performance; it just changes signaling a little bit. Three changes need to be made to Marlin/src/HAL/LPC1768/HAL_SPI.cpp, which will be presented below as a patch…basically, there are three occurrences of SPI_MODE0 that need to be changed to SPI_MODE3:

diff --git a/Marlin/src/HAL/LPC1768/HAL_SPI.cpp b/Marlin/src/HAL/LPC1768/HAL_SPI.cpp
index 99db15f6e9..ee2bc1fa3d 100644
--- a/Marlin/src/HAL/LPC1768/HAL_SPI.cpp
+++ b/Marlin/src/HAL/LPC1768/HAL_SPI.cpp
@@ -123,7 +123,7 @@
       SPI.setModule(2);
     #endif
     SPI.setDataSize(DATA_SIZE_8BIT);
-    SPI.setDataMode(SPI_MODE0);
+    SPI.setDataMode(SPI_MODE3);
 
     SPI.setClock(SPISettings::spiRate2Clock(spiRate));
     SPI.begin();
@@ -187,7 +187,7 @@ SPIClass::SPIClass(uint8_t device) {
 
   #if BOARD_NR_SPI >= 1
     _settings[0].spi_d = LPC_SSP0;
-    _settings[0].dataMode = SPI_MODE0;
+    _settings[0].dataMode = SPI_MODE3;
     _settings[0].dataSize = DATA_SIZE_8BIT;
     _settings[0].clock = SPI_CLOCK_MAX;
     //_settings[0].clockDivider = determine_baud_rate(_settings[0].spi_d, _settings[0].clock);
@@ -195,7 +195,7 @@ SPIClass::SPIClass(uint8_t device) {
 
   #if BOARD_NR_SPI >= 2
     _settings[1].spi_d = LPC_SSP1;
-    _settings[1].dataMode = SPI_MODE0;
+    _settings[1].dataMode = SPI_MODE3;
     _settings[1].dataSize = DATA_SIZE_8BIT;
     _settings[1].clock = SPI_CLOCK_MAX;
     //_settings[1].clockDivider = determine_baud_rate(_settings[1].spi_d, _settings[1].clock);

If you haven’t previously fixed Adafruit_MAX31865.h (look for it under .pio/libdeps/LPC1769/), find this line near the top:

#if (ARDUINO >= 100)

and change ARDUINO to ARDUINOLPC:

#if (ARDUINOLPC >= 100)

Notes

I had noticed a bit of lag in the printer with the temperature sensor using a soft-SPI connection and thought I’d try switching to a hardware SPI port to see if it’ll lighten the load a bit. If you want to keep using your ReprapDiscount display, you might try using the SPI bus on the EXP2 connector instead. This might require driving the MAX31865 board with 5V instead of 3.3V to match the display’s 5V interface. The easiest way to tap into the signals would likely be a 2×5 female insulation-displacement connector on the EXP2 ribbon cable, into which pins can be stuck in the appropriate places. Set SDCARD_CONNECTION to LCD instead of ONBOARD if you go this route.