My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MAX31865.h 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. * Based on Adafruit MAX31865 library:
  24. *
  25. * This is a library for the Adafruit PT100/P1000 RTD Sensor w/MAX31865
  26. * Designed specifically to work with the Adafruit RTD Sensor
  27. * https://www.adafruit.com/products/3328
  28. *
  29. * This sensor uses SPI to communicate, 4 pins are required to interface.
  30. *
  31. * Adafruit invests time and resources providing this open source code,
  32. * please support Adafruit and open-source hardware by purchasing
  33. * products from Adafruit!
  34. *
  35. * Written by Limor Fried/Ladyada for Adafruit Industries.
  36. *
  37. * Modifications by JoAnn Manges (@GadgetAngel)
  38. * Copyright (c) 2020, JoAnn Manges
  39. * All rights reserved.
  40. */
  41. #pragma once
  42. #include "../inc/MarlinConfig.h"
  43. #include "../HAL/shared/Delay.h"
  44. #include HAL_PATH(../HAL, MarlinSPI.h)
  45. #define MAX31856_CONFIG_REG 0x00
  46. #define MAX31856_CONFIG_BIAS 0x80
  47. #define MAX31856_CONFIG_MODEAUTO 0x40
  48. #define MAX31856_CONFIG_MODEOFF 0x00
  49. #define MAX31856_CONFIG_1SHOT 0x20
  50. #define MAX31856_CONFIG_3WIRE 0x10
  51. #define MAX31856_CONFIG_24WIRE 0x00
  52. #define MAX31856_CONFIG_FAULTSTAT 0x02
  53. #define MAX31856_CONFIG_FILT50HZ 0x01
  54. #define MAX31856_CONFIG_FILT60HZ 0x00
  55. #define MAX31856_RTDMSB_REG 0x01
  56. #define MAX31856_RTDLSB_REG 0x02
  57. #define MAX31856_HFAULTMSB_REG 0x03
  58. #define MAX31856_HFAULTLSB_REG 0x04
  59. #define MAX31856_LFAULTMSB_REG 0x05
  60. #define MAX31856_LFAULTLSB_REG 0x06
  61. #define MAX31856_FAULTSTAT_REG 0x07
  62. #define MAX31865_FAULT_HIGHTHRESH 0x80 // D7
  63. #define MAX31865_FAULT_LOWTHRESH 0x40 // D6
  64. #define MAX31865_FAULT_REFINLOW 0x20 // D5
  65. #define MAX31865_FAULT_REFINHIGH 0x10 // D4
  66. #define MAX31865_FAULT_RTDINLOW 0x08 // D3
  67. #define MAX31865_FAULT_OVUV 0x04 // D2
  68. // http://www.analog.com/media/en/technical-documentation/application-notes/AN709_0.pdf
  69. // constants for calculating temperature from the measured RTD resistance.
  70. #define RTD_Z1 -0.0039083
  71. #define RTD_Z2 0.00001758480889
  72. #define RTD_Z3 -0.0000000231
  73. #define RTD_Z4 -0.000001155
  74. typedef enum max31865_numwires {
  75. MAX31865_2WIRE = 0,
  76. MAX31865_3WIRE = 1,
  77. MAX31865_4WIRE = 0
  78. } max31865_numwires_t;
  79. /* Interface class for the MAX31865 RTD Sensor reader */
  80. class MAX31865 {
  81. private:
  82. static SPISettings spiConfig;
  83. TERN(LARGE_PINMAP, uint32_t, uint8_t) _sclk, _miso, _mosi, _cs;
  84. #ifdef TARGET_LPC1768
  85. uint8_t _spi_speed;
  86. #else
  87. uint16_t _spi_delay;
  88. #endif
  89. float Rzero, Rref;
  90. void setConfig(uint8_t config, bool enable);
  91. void readRegisterN(uint8_t addr, uint8_t buffer[], uint8_t n);
  92. uint8_t readRegister8(uint8_t addr);
  93. uint16_t readRegister16(uint8_t addr);
  94. void writeRegister8(uint8_t addr, uint8_t reg);
  95. uint8_t spiTransfer(uint8_t addr);
  96. void softSpiBegin(const uint8_t spi_speed);
  97. public:
  98. #ifdef LARGE_PINMAP
  99. MAX31865(uint32_t spi_cs, uint8_t pin_mapping);
  100. MAX31865(uint32_t spi_cs, uint32_t spi_mosi, uint32_t spi_miso,
  101. uint32_t spi_clk, uint8_t pin_mapping);
  102. #else
  103. MAX31865(int8_t spi_cs);
  104. MAX31865(int8_t spi_cs, int8_t spi_mosi, int8_t spi_miso,
  105. int8_t spi_clk);
  106. #endif
  107. void begin(max31865_numwires_t wires, float zero, float ref);
  108. uint8_t readFault();
  109. void clearFault();
  110. void setWires(max31865_numwires_t wires);
  111. void autoConvert(bool b);
  112. void enable50HzFilter(bool b);
  113. void enableBias(bool b);
  114. void oneShot();
  115. uint16_t readRaw();
  116. float readResistance();
  117. float temperature();
  118. float temperature(uint16_t adcVal);
  119. float temperature(float Rrtd);
  120. };