bigtreetech / BIGTREETECH-OCTOPUS-Pro

This is OCTOPUS Pro open source material
272 stars 58 forks source link

Stepper Driver SPI (MAX31865 module) does not work when LCD SD is connected on EXP2 #31

Open ansonl opened 1 year ago

ansonl commented 1 year ago

Hi,

I am trying to use a PT1000 with the MAX31865 module plugged into Motor7 slot on the Octopus Pro 1.0.1. The printer reports a MINTEMP error for the temperature when I have the LCD controller EXP2 is connected to the Octopus Pro EXP2.

The printer can successfully read the temperature ONLY if I disconnect the EXP2. I am using the ULTICONTROLLER LCD with my board and it's EXP2 pin out is the same as the standard LCD EXP2.

My pins configs is below. I commented out the MAX31865_CS_PIN listed in the BTT MAX31865 manual because it seems that TEMP_1_CS_PIN is now used in the latest Marlin instead of MAX6675_SS_PIN. Is my configuration correct and is there a solution to use the LCD mounted SD SPI and stepper motor SPI at the same time?

//Define E3 or TEMP_SENSOR_1 on MOTOR 7
#if TEMP_SENSOR_1 == -5
  #define TEMP_1_CS_PIN                     PD3   // Max31865 CS MOTOR 7
  #define TEMP_1_SCK_PIN                    PA5
  #define TEMP_1_MISO_PIN                   PA6
  #define TEMP_1_MOSI_PIN                   PA7
  #define SOFTWARE_SPI                            // Max31865 and LCD SD share a set of SPIs, Set SD to softwareSPI for Max31865
  #define FORCE_SOFT_SPI

  /*
  #ifndef MAX31865_CS_PIN
    #define MAX31865_MISO_PIN PA6
    #define MAX31865_SCK_PIN PA5
    #define MAX31865_MOSI_PIN PA7
    #define MAX6675_SS_PIN PD3
    //#define MAX31865_CS_PIN PD3
  #endif
  */
#else
  #define TEMP_1_PIN                        PF5   // TH1

  //Define E3 if MOTOR 7 not used for TEMP_SENSOR_1 MAX module
  #define E3_STEP_PIN                         PE6   // MOTOR 7
  #define E3_DIR_PIN                          PA14
  #define E3_ENABLE_PIN                       PE0
  #ifndef E3_CS_PIN
    #define E3_CS_PIN                         PD3
  #endif
#endif

Based on the other issues reported, I assume that this is related to https://github.com/bigtreetech/BIGTREETECH-OCTOPUS-Pro/issues/23

ansonl commented 1 year ago

I read https://github.com/MarlinFirmware/Marlin/issues/25774 and used some clues with TEMP_SENSOR_FORCE_HW_SPI to get SPI MAX31865 on motor driver to work correctly when EXP2 (LCD SD SPI) is connected to the EXP2 on the board.

SOFTWARE_SPI for both temp sensors must be commented out. If it is not disabled, the SPI connection for MAX31865 fails when the SD card is used. As soon as the card is inserted into the LCD SD slot and the SD is read from, the MAX31865 SPI fails with a temp error even though it worked fine before any SD was inserted. I have 2 2 wire PT1000s connected to both the onboard MAX31865 and stepper driver MAX31865. The temp error is first thrown on the onboard MAX31865 so I assume that SPI to both MAX31865 is failing. The onboard MAX31865 used to work fine with the LCD SD SPI in the past so there is an issue where the onboard MAX31865 works with SOFTWARE_SPI and fails with HW_SPI while the stepper driver SPI works with HW_SPI and fails with SOFTWARE_SPI.

It's not clear why there are separate defines for SOFTWARE_SPI and TEMP_SENSOR_FORCE_HW_SPI when it comes to temp sensors. Since they can be enabled and disabled independent of each other, it is not self explanatory whether soft or hard SPI take precedence for temp sensor without viewing the code.

@bigtreetech Hopefully the below config helps with the immediate SPI issue but I don't know why software spi does not work for stepper driver SPI and EXP2 (LCD SD) SPI at the same time.

#if TEMP_SENSOR_0 == -5
  #define TEMP_0_CS_PIN                     PF8   // Max31865 CS
  #define TEMP_0_SCK_PIN                    PA5
  #define TEMP_0_MISO_PIN                   PA6
  #define TEMP_0_MOSI_PIN                   PA7
  //#define SOFTWARE_SPI                            // Max31865 and LCD SD share a set of SPIs, Set SD to softwareSPI for Max31865
  #define FORCE_SOFT_SPI
#else
  #define TEMP_0_PIN                        PF4   // TH0
#endif

//Define E3 or TEMP_SENSOR_1 on MOTOR 7
#if TEMP_SENSOR_1 == -5
  #define TEMP_1_CS_PIN                     PD3   // Max31865 CS MOTOR 7
  #define TEMP_1_SCK_PIN                    PA5
  #define TEMP_1_MISO_PIN                   PA6
  #define TEMP_1_MOSI_PIN                   PA7
  //#define SOFTWARE_SPI                            // Max31865 and LCD SD share a set of SPIs, Set SD to softwareSPI for Max31865
  #define FORCE_SOFT_SPI

  /*
  #ifndef MAX31865_CS_PIN
    #define MAX31865_MISO_PIN PA6
    #define MAX31865_SCK_PIN PA5
    #define MAX31865_MOSI_PIN PA7
    #define MAX6675_SS_PIN PD3
    //#define MAX31865_CS_PIN PD3
  #endif
  */
#else
  #define TEMP_1_PIN                        PF5   // TH1

  //Define E3 if MOTOR 7 not used for TEMP_SENSOR_1 MAX module
  #define E3_STEP_PIN                         PE6   // MOTOR 7
  #define E3_DIR_PIN                          PA14
  #define E3_ENABLE_PIN                       PE0
  #ifndef E3_CS_PIN
    #define E3_CS_PIN                         PD3
  #endif
#endif

/**
 * Thermocouple Options — for MAX6675 (-2), MAX31855 (-3), and MAX31865 (-5).
 */
#define TEMP_SENSOR_FORCE_HW_SPI                // Ignore SCK/MOSI/MISO pins; use CS and the default SPI bus.
#define MAX31865_SENSOR_WIRES_0 2               // (2-4) Number of wires for the probe connected to a MAX31865 board.
#define MAX31865_SENSOR_WIRES_1 2
//#define MAX31865_SENSOR_WIRES_2 2
ansonl commented 1 year ago

Update: The printer fails to read temp via SPI from both the onboard and stepper module MAX31865 when SD card is inserted into the LCD SD reader that uses SPI. This happens randomly so it's basically not possible to use the LCD SD slot right now.