### MAX31865 Getting Started Source: https://github.com/bolderflight/max31865/blob/main/_autodocs/README.md Quick start guide for installing and using the MAX31865 library, covering basic setup and common tasks. ```APIDOC ## MAX31865 Quick Start Guide This guide provides instructions for getting started with the MAX31865 library, including installation, hardware setup, and basic usage. ### Installation - **Arduino IDE**: Instructions for installing the library using the Arduino IDE. - **CMake**: Instructions for integrating the library into a CMake build system. ### Hardware Setup - **Pinout Diagrams**: Visual diagrams illustrating the necessary hardware connections. ### Basic Examples - **Continuous Measurement**: Example code for performing continuous temperature measurements. - **Single-Shot Measurement**: Example code for taking a single temperature reading. ### Common Tasks Code examples and explanations for performing common operations: - **Change Filter Frequency**: How to modify the digital filter settings. - **Handle Sensor Faults**: Strategies for detecting and responding to sensor faults. - **Use Different RTD Types**: Guidance on configuring the library for various RTD sensor types. - **Robust Reading Patterns**: Techniques for ensuring reliable temperature readings. ### Reference Parameter Tables Tables summarizing key parameters and their typical values. ### Troubleshooting Guide Common issues and their solutions. ### Performance Notes Information regarding the performance characteristics of the library. ### Integration with Other Sensors Guidance on how to integrate the MAX31865 library with other sensors or systems. ``` -------------------------------- ### Add Example Executable and Link Source: https://github.com/bolderflight/max31865/blob/main/CMakeLists.txt Creates an executable for the MAX31865 example and links the MAX31865 library to it. This section is only processed if the project is being built as the main project. ```cmake if (PROJECT_NAME STREQUAL CMAKE_PROJECT_NAME) # Add the example target add_executable(max31865_example examples/cmake/max31865_example.cc) # Add the includes target_include_directories(max31865_example PUBLIC $ $ ) # Link libraries to the example target target_link_libraries(max31865_example PRIVATE max31865 ) # Add hex and upload targets include(${mcu_support_SOURCE_DIR}/cmake/flash_mcu.cmake) FlashMcu(max31865_example ${MCU} ${mcu_support_SOURCE_DIR}) endif() ``` -------------------------------- ### Install Max31865 with CMake Source: https://github.com/bolderflight/max31865/blob/main/_autodocs/getting-started.md Clone the repository and build the library using CMake. Replace MK66FX1M0 with your specific MCU. ```bash git clone https://github.com/bolderflight/max31865.git cd max31865 mkdir build cd build cmake .. -DMCU=MK66FX1M0 # Replace with your MCU make ``` -------------------------------- ### Setup Include Directories for Library Source: https://github.com/bolderflight/max31865/blob/main/CMakeLists.txt Configures include directories for the MAX31865 library. It specifies build-time and install-time include paths. ```cmake target_include_directories(max31865 PUBLIC $ $ ) ``` -------------------------------- ### Single-Shot Measurement Example Source: https://github.com/bolderflight/max31865/blob/main/_autodocs/TABLE_OF_CONTENTS.txt Shows how to perform a single-shot temperature measurement with the MAX31865 sensor. ```cpp MAX31865 sensor(3.3, 5.0, 1000.0, 4096.0, 2, 3, 4, 5); sensor.begin(); float temperature = sensor.readTemperature(); // Process temperature ``` -------------------------------- ### Continuous Measurement Example Source: https://github.com/bolderflight/max31865/blob/main/_autodocs/TABLE_OF_CONTENTS.txt Demonstrates how to perform continuous temperature measurements using the MAX31865 sensor. ```cpp MAX31865 sensor(3.3, 5.0, 1000.0, 4096.0, 2, 3, 4, 5); sensor.begin(); while (true) { float temperature = sensor.readTemperature(); // Process temperature delay(1000); } ``` -------------------------------- ### Project Setup and Dependency Fetching Source: https://github.com/bolderflight/max31865/blob/main/CMakeLists.txt Initializes the CMake version and fetches external dependencies like mcu-support and core using FetchContent. Ensure CMake version 3.14 or higher is used. ```cmake cmake_minimum_required(VERSION 3.14) if (DEFINED MCU) include(FetchContent) FetchContent_Declare( mcu_support GIT_REPOSITORY https://github.com/bolderflight/mcu-support.git GIT_TAG v1.1.0 ) FetchContent_MakeAvailable(mcu_support) # Setting up the toolchain set(CMAKE_TOOLCHAIN_FILE "${mcu_support_SOURCE_DIR}/cmake/cortex.cmake") # Project information project(Max31865 VERSION 1.0.1 DESCRIPTION "MAX31865 RTD front-end driver" LANGUAGES CXX ) # Grab the processor and set up definitions and compile options include(${mcu_support_SOURCE_DIR}/cmake/config_mcu.cmake) configMcu(${MCU} ${mcu_support_SOURCE_DIR}) # Fetch core FetchContent_Declare( core GIT_REPOSITORY https://github.com/bolderflight/core.git GIT_TAG v3.1.3 ) FetchContent_MakeAvailable(core) endif() ``` -------------------------------- ### Multi-Device SPI Setup Source: https://github.com/bolderflight/max31865/blob/main/_autodocs/spi-protocol.md Demonstrates how to initialize multiple devices on the same SPI bus using different chip select pins. Ensure each device has a unique CS pin for proper operation. ```cpp // Device 1 bfs::Max31865 rtd(&SPI1, 29); // Device 2 bfs::OtherDevice device(&SPI1, 31); // Both share SPI1 clock, MOSI, MISO but have different CS pins ``` -------------------------------- ### MAX31865 Configuration Source: https://github.com/bolderflight/max31865/blob/main/_autodocs/README.md Comprehensive reference for all setup and configuration options for the MAX31865 library. ```APIDOC ## MAX31865 Configuration This section covers all configuration options for setting up and customizing the MAX31865 sensor library. ### Constructor Configuration Patterns Details on how to configure the MAX31865 sensor during object instantiation. ### Begin() Method Parameters Documentation for the parameters accepted by the `begin()` method, including their purpose and default values. ### RTD Sensor Parameters - **R0 Values**: Specifies the nominal resistance of the RTD sensor at 0°C, crucial for accurate temperature conversion. ### Reference Resistor Values - **Selection**: Guidance on selecting the appropriate reference resistor value for the specific RTD and desired accuracy. ### Post-Initialization Configuration Methods Methods available for changing configuration settings after the sensor has been initialized. ### Hardcoded SPI Settings Information on any SPI settings that are hardcoded within the library, such as clock speed or mode. ### Chip Select Pin Configuration Instructions on how to configure the chip select (CS) pin for SPI communication. ### Calibration Considerations Guidance on calibration procedures to ensure accurate temperature readings. ### Configuration State Management How the library manages and stores configuration settings. ### Typical Configuration Scenarios Illustrative examples of common configuration setups, each accompanied by code snippets. ``` -------------------------------- ### Continuous Temperature Measurement Example Source: https://github.com/bolderflight/max31865/blob/main/_autodocs/api-reference-max31865.md Demonstrates continuous temperature readings using the MAX31865 sensor. Initializes the sensor and reads temperature in a loop, handling potential faults. ```cpp bfs::Max31865 rtd(&SPI1, 29); void setup() { SPI1.begin(); if (!rtd.Begin(bfs::Max31865::RTD_3WIRE, 100.0f, 402.0f)) { Serial.println("ERROR initializing RTD"); while (1) {} } } void loop() { if (rtd.Read()) { if (!rtd.fault()) { Serial.print("Temperature: "); Serial.println(rtd.temp_c()); } else { uint8_t fault_code; rtd.GetFault(&fault_code); Serial.print("Fault code: 0x"); Serial.println(fault_code, HEX); } } delay(100); } ``` -------------------------------- ### Initialize SPI and Max31865 Source: https://github.com/bolderflight/max31865/blob/main/_autodocs/getting-started.md Ensure SPI is initialized before calling Begin(). Use the correct chip select pin for your hardware setup. ```cpp // Ensure SPI is initialized before Begin() SPI1.begin(); // Use correct CS pin bfs::Max31865 rtd(&SPI1, CORRECT_PIN); ``` -------------------------------- ### SPI Clock Timing Example Source: https://github.com/bolderflight/max31865/blob/main/_autodocs/spi-protocol.md Illustrates the clock period for a 5 MHz SPI clock frequency. ```plaintext 5 MHz = 200 ns per clock period ``` -------------------------------- ### Single-Shot Temperature Measurement Example Source: https://github.com/bolderflight/max31865/blob/main/_autodocs/api-reference-max31865.md Shows how to perform a single-shot temperature measurement to minimize self-heating. This involves manually enabling bias, triggering conversion, reading, and disabling bias. ```cpp bfs::Max31865 rtd(&SPI1, 29); void setup() { SPI1.begin(); if (!rtd.Begin(bfs::Max31865::RTD_3WIRE, 100.0f, 402.0f)) { Serial.println("ERROR initializing RTD"); while (1) {} } if (!rtd.DisableAutoConversion()) { Serial.println("Failed to disable auto-conversion"); while (1) {} } } void loop() { // Enable bias voltage if (!rtd.EnableBiasVoltage()) { Serial.println("Failed to enable bias voltage"); return; } // Wait for bias to settle: 10x input time constant + 1ms delay(105); // Trigger single-shot measurement if (!rtd.Trigger1Shot()) { Serial.println("Failed to trigger measurement"); return; } // Wait for conversion to complete delay(65); // Read data if (rtd.Read()) { Serial.print("Temperature: "); Serial.println(rtd.temp_c()); } // Disable bias voltage to prevent self-heating if (!rtd.DisableBiasVoltage()) { Serial.println("Failed to disable bias voltage"); } // Wait before next measurement delay(1000); } ``` -------------------------------- ### MAX31865 Multi-Byte Read Example (RTD Value) Source: https://github.com/bolderflight/max31865/blob/main/_autodocs/spi-protocol.md Example demonstrating how to read the 2-byte RTD resistance value from registers 0x01 and 0x02, and extract the 15-bit raw value and fault bit. ```cpp uint8_t rtd_data[2]; if (ReadRegisters(0x01, 2, rtd_data)) { uint8_t rtd_msb = rtd_data[0]; uint8_t rtd_lsb = rtd_data[1]; // Extract 15-bit RTD value uint16_t rtd_raw = (static_cast(rtd_msb) << 8 | rtd_lsb) >> 1; // Extract fault bit (LSB bit 0) bool fault = rtd_lsb & 0x01; } ``` -------------------------------- ### Include MAX31865 Library Source: https://github.com/bolderflight/max31865/blob/main/_autodocs/README.md Include the library in your Arduino sketch. Installation can be done via the Library Manager or by cloning the repository. ```cpp // Arduino: Sketch ← Include Library ← Manage Libraries ← search "Max31865" // Or: Clone to Arduino/libraries folder #include "max31865.h" ``` -------------------------------- ### Basic MAX31865 Sensor Setup and Reading Source: https://github.com/bolderflight/max31865/blob/main/_autodocs/README.md Initialize the MAX31865 sensor with SPI and chip select pin, then read temperature in Celsius within the loop. Ensure proper initialization parameters for RTD type, resistance, and reference resistor. ```cpp // Create sensor object with SPI1 and CS pin 29 bfs::Max31865 rtd(&SPI1, 29); void setup() { Serial.begin(115200); SPI1.begin(); // Initialize: 3-wire RTD, Pt100 (100Ω), reference resistor (402Ω) if (!rtd.Begin(bfs::Max31865::RTD_3WIRE, 100.0f, 402.0f)) { Serial.println("ERROR initializing RTD"); while (1) {} } } void loop() { if (rtd.Read()) { if (!rtd.fault()) { Serial.println(rtd.temp_c()); // Print temperature in Celsius } } delay(100); } ``` -------------------------------- ### SPI Write Transaction Example Source: https://github.com/bolderflight/max31865/blob/main/_autodocs/TABLE_OF_CONTENTS.txt Demonstrates a low-level SPI write transaction for sending data to the MAX31865 registers. ```c uint8_t writeRegister(uint8_t address, uint8_t value) { // SPI transaction logic here // ... return 0; // Success } ``` -------------------------------- ### Compile Max31865 Library with CMake Source: https://github.com/bolderflight/max31865/blob/main/README.md Build the Max31865 library and example executables using CMake. Specify the target microcontroller using the -DMCU flag. This command is typically run from a 'build' directory. ```bash cmake .. -DMCU=MK66FX1M0 make ``` -------------------------------- ### SPI Read Transaction Example Source: https://github.com/bolderflight/max31865/blob/main/_autodocs/TABLE_OF_CONTENTS.txt Illustrates a low-level SPI read transaction for retrieving data from the MAX31865 registers. ```c uint8_t readRegisters(uint8_t address, uint8_t* data, uint16_t length) { // SPI transaction logic here // ... return 0; // Success } ``` -------------------------------- ### Include Max31865 Library for Arduino Source: https://github.com/bolderflight/max31865/blob/main/README.md Include this header file to use the Max31865 library in your Arduino projects. Ensure the library is installed via the Arduino Library Manager or manually. ```cpp #include "max31865.h" ``` -------------------------------- ### MAX31865 Data Flow Source: https://github.com/bolderflight/max31865/blob/main/_autodocs/architecture.md Illustrates the sequence of operations for reading temperature data from the MAX31865. The process starts with the application calling a Read() method, which internally calls ReadRtd() to get resistance, converts it to temperature using the Callendar-Van Dusen equation, stores it, and makes it available via the temp_c() method. ```text Application Code ↓ Read() method ↓ ReadRtd() - Read RTD resistance value ↓ Convert Resistance to Temperature (Callendar-Van Dusen equation) ↓ Store in temp_c_ member variable ↓ Application retrieves via temp_c() ``` -------------------------------- ### Initialize Max31865 Sensor with Begin() Source: https://github.com/bolderflight/max31865/blob/main/_autodocs/api-reference-max31865.md Initialize communication with the MAX31865 sensor and configure its settings. The SPI bus must be initialized first. Check the return value for successful initialization. ```cpp SPI1.begin(); if (!rtd.Begin(bfs::Max31865::RTD_3WIRE, 100.0f, 402.0f)) { Serial.println("ERROR initializing RTD"); while (1) {} } ``` -------------------------------- ### MAX31865 Error Handling Source: https://github.com/bolderflight/max31865/blob/main/_autodocs/README.md Guide to error and fault handling mechanisms within the MAX31865 library. ```APIDOC ## MAX31865 Error Handling and Fault Management This document details the error handling model and fault management capabilities of the MAX31865 library. ### Return-Value-Based Error Model Explains the library's approach to error reporting, primarily through method return values. ### Method Error Conditions Details the specific error conditions associated with each method in the library. ### Sensor Fault Conditions - **Detection**: How the library detects and reports fault conditions originating from the MAX31865 sensor itself. ### Initialization Failure Scenarios Common reasons for initialization failures and how they are reported. ### Common Operation Failure Patterns Patterns of failures that may occur during normal operation of the sensor. ### Fault Code Interpretation Explanation of the meaning behind different fault codes returned by the library. ### Error Recovery Strategies Provides strategies and code examples for recovering from detected errors and faults. ### SPI Communication Error Sources Identifies potential sources of errors during SPI communication. ### State After Failed Operations Describes the library's state and behavior following an operation that results in an error or fault. ### No Exception Support Explanation Clarification on why the library does not utilize C++ exceptions for error handling. ``` -------------------------------- ### Changing Configuration After Begin() Source: https://github.com/bolderflight/max31865/blob/main/_autodocs/configuration.md Demonstrates how to modify filter settings and measurement modes after the initial `Begin()` call. ```cpp // After Begin() with defaults rtd.Begin(bfs::Max31865::RTD_3WIRE, 100.0f, 402.0f); // Later, switch to 60 Hz filter rtd.ConfigFilter(bfs::Max31865::FILTER_60HZ); // Later, switch to single-shot measurement rtd.DisableAutoConversion(); // ... perform single-shot sequence ... // Later, switch back to continuous rtd.EnableAutoConversion(); ``` -------------------------------- ### Resource Initialization with Constructor Source: https://github.com/bolderflight/max31865/blob/main/_autodocs/architecture.md Initialize the MAX31865 resource directly through the constructor, followed by Begin(). Handle potential errors during the Begin() call. ```cpp bfs::Max31865 rtd(&SPI1, 29); if (!rtd.Begin(bfs::Max31865::RTD_3WIRE, 100.0f, 402.0f)) { // Handle error } ``` -------------------------------- ### Resource Initialization with Default Constructor Source: https://github.com/bolderflight/max31865/blob/main/_autodocs/architecture.md Initialize the MAX31865 resource using the default constructor, followed by Config() and Begin(). Handle potential errors during the Begin() call. ```cpp bfs::Max31865 rtd; rtd.Config(&SPI1, 29); if (!rtd.Begin(bfs::Max31865::RTD_3WIRE, 100.0f, 402.0f)) { // Handle error } ``` -------------------------------- ### Begin(const RtdWire wires, const float r0, const float resist) Source: https://github.com/bolderflight/max31865/blob/main/README.md Initializes communication and configures the MAX31865 sensor. The communication bus must be initialized separately. ```APIDOC ## Begin(const RtdWire wires, const float r0, const float resist) ### Description Initializes communication and configures the MAX31865. The communication bus is not initialized within this library and must be initialized separately. Takes an enum for the number of RTD sensor wires, the RTD resistance at 0C, and the reference resistor resistance. Returns true if communication is able to be established and the sensor successfully configured, otherwise false is returned. ### Method bool ### Parameters * **wires** (RtdWire) - Enum for the number of RTD sensor wires (RTD_4WIRE, RTD_3WIRE, RTD_2WIRE). * **r0** (float) - The RTD resistance at 0C (e.g., 100.0f, 500.0f, 1000.0f). * **resist** (float) - The reference resistor resistance. ### Returns `true` if communication and configuration are successful, `false` otherwise. ``` -------------------------------- ### Initialize Sensor with Begin() Method Source: https://github.com/bolderflight/max31865/blob/main/_autodocs/configuration.md Initialize the RTD sensor using the Begin() method, specifying the RTD wire configuration, resistance at 0°C (r0), and the reference resistor value. This method applies default settings for filtering, measurement mode, and bias voltage. ```cpp if (!rtd.Begin(bfs::Max31865::RTD_3WIRE, 100.0f, 402.0f)) { Serial.println("ERROR initializing RTD"); while (1) {} } ``` -------------------------------- ### Using Default Constructor Source: https://github.com/bolderflight/max31865/blob/main/_autodocs/TABLE_OF_CONTENTS.txt Initializes the MAX31865 sensor using the default constructor, which assumes common settings. ```cpp MAX31865 sensor; sensor.begin(); float temperature = sensor.readTemperature(); // Process temperature ``` -------------------------------- ### Get Latest Temperature Measurement Source: https://github.com/bolderflight/max31865/blob/main/_autodocs/api-reference-max31865.md Returns the most recent temperature measurement in Celsius. This returns a cached value and does not perform a new read. ```cpp float temperature = rtd.temp_c(); Serial.println(temperature); ``` -------------------------------- ### Config(SPIClass &spi, const uint8_t cs) Source: https://github.com/bolderflight/max31865/blob/main/README.md Sets up the SPI bus and chip select pin, required when using the default constructor. ```APIDOC ## Config(SPIClass &spi, const uint8_t cs) ### Description This method is required when using the default constructor and sets up the SPI bus and chip select pin. ### Method void ### Parameters * **spi** (SPIClass &) - A pointer to the SPI bus object. * **cs** (uint8_t) - The chip select pin of the sensor. ``` -------------------------------- ### Read Temperature Measurement (C++) Source: https://github.com/bolderflight/max31865/blob/main/_autodocs/spi-protocol.md Reads the RTD value and fault flag from the device registers. Requires prior setup of SPI communication. ```cpp bool Max31865::ReadRtd() { if (!ReadRegisters(RTD_MSB_ADDR_, 2, buf_)) { return false; } // Extract fault bit from LSB (bit 0) fault_ = buf_[1] & 0x01; // Extract RTD value (shift right by 1 to align 15-bit value) rtd_val_ = (static_cast(buf_[0]) << 8 | buf_[1]) >> 1; return true; } ``` -------------------------------- ### RTD Initialization with Validation and Recovery Source: https://github.com/bolderflight/max31865/blob/main/_autodocs/errors.md Shows how to initialize the MAX31865 sensor with validation checks for Begin(), filter configuration, and auto-conversion mode. Includes a recovery mechanism if initial Begin() fails. ```cpp bfs::Max31865 rtd(&SPI1, 29); if (!rtd.Begin(bfs::Max31865::RTD_3WIRE, 100.0f, 402.0f)) { Serial.println("Begin() failed - checking preconditions..."); while (1) { // Could try to diagnose: // - Check if SPI bus is responding // - Verify chip select pin is correct // - Check sensor power supply } } // Verify filter configuration if (!rtd.ConfigFilter(bfs::Max31865::FILTER_50HZ)) { Serial.println("Filter configuration failed"); // Continue anyway - filter may already be set correctly } // Verify measurement mode if (!rtd.EnableAutoConversion()) { Serial.println("Failed to enable auto-conversion"); // Attempt recovery if (!rtd.Begin(bfs::Max31865::RTD_3WIRE, 100.0f, 402.0f)) { while (1) {} } } ``` -------------------------------- ### Write Register Source: https://github.com/bolderflight/max31865/blob/main/_autodocs/spi-protocol.md Writes a byte of data to a specified register on the MAX31865. This function handles SPI transaction setup, data transmission, and cleanup. ```APIDOC ## WriteRegister ### Description Writes a byte of data to a specified register on the MAX31865. This function handles SPI transaction setup, data transmission, and cleanup. ### Method ``` bool Max31865::WriteRegister(const uint8_t addr, const uint8_t data) ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```cpp // Example of writing to the Configuration Register WriteRegister(CONFIG_ADDR_, new_config_value); ``` ### Response #### Success Response - **bool** - Returns true if the write operation was successful. #### Response Example ``` true ``` ### Error Handling This function returns `true` on successful completion. Error handling for SPI communication is managed internally by the `spi_` object. ``` -------------------------------- ### MAX31865 Temperature Reading and Fault Check Source: https://github.com/bolderflight/max31865/blob/main/_autodocs/README.md Read the latest temperature data from the sensor. Use `temp_c()` to get the cached temperature in Celsius and `fault()` to check for any sensor faults. ```cpp bool Read() // Read sensor data float temp_c() const // Get cached temperature in Celsius bool fault() const // Check for fault condition ``` -------------------------------- ### MAX31865 Initialization Method Source: https://github.com/bolderflight/max31865/blob/main/_autodocs/README.md Initialize the sensor with the specified RTD wiring configuration, nominal resistance at 0°C (R0), and reference resistor value. Returns true on success. ```cpp bool Begin(RtdWire wires, float r0, float resist) ``` -------------------------------- ### Standard Continuous Measurement (Default) Source: https://github.com/bolderflight/max31865/blob/main/_autodocs/configuration.md Sets up the sensor for continuous temperature readings using default settings, suitable for most applications. ```cpp bfs::Max31865 rtd(&SPI1, 29); void setup() { SPI1.begin(); if (!rtd.Begin(bfs::Max31865::RTD_3WIRE, 100.0f, 402.0f)) { while (1) {} } // Uses all defaults: // - FILTER_50HZ // - Auto-conversion enabled // - Bias voltage enabled } void loop() { if (rtd.Read()) { Serial.println(rtd.temp_c()); } delay(100); } ``` -------------------------------- ### Initialize MAX31865 with Default Constructor Source: https://github.com/bolderflight/max31865/blob/main/_autodocs/getting-started.md Initialize the MAX31865 sensor using the default constructor, configuring SPI and the chip select pin before calling Begin. Ensure SPI is initialized and the correct CS pin is specified. ```cpp bfs::Max31865 rtd; void setup() { SPI1.begin(); // Configure SPI and CS pin rtd.Config(&SPI1, 29); // Initialize sensor if (!rtd.Begin(bfs::Max31865::RTD_3WIRE, 100.0f, 402.0f)) { while (1) {} } } ``` -------------------------------- ### Initialize Max31865 with Default Constructor Source: https://github.com/bolderflight/max31865/blob/main/_autodocs/configuration.md Use the default constructor for the Max31865 sensor. You must subsequently call Config() to set the SPI bus and chip select pin, and Begin() to initialize the sensor with RTD parameters. ```cpp bfs::Max31865 rtd; ``` -------------------------------- ### MAX31865 Library API Reference Source: https://github.com/bolderflight/max31865/blob/main/_autodocs/COMPLETION_REPORT.txt This section details the public methods, enumerations, constructors, and return types of the MAX31865 library, providing signatures, parameter descriptions, return value documentation, and usage examples for each. ```APIDOC ## MAX31865 Library API This library provides a comprehensive set of functions and classes to interact with the MAX31865 temperature sensor. ### Public Methods - **`MAX31865(int spi_cs_pin, int spi_clk_pin, int spi_mosi_pin, int spi_miso_pin)`** - Constructor for initializing the MAX31865 sensor with specified SPI pins. - **`begin(MAX31865_Configuration config)`** - Initializes the sensor with the given configuration. - **`readRTD(MAX31865_Units units)`** - Reads the RTD temperature in the specified units. - **`readFault()`** - Reads the fault status of the sensor. - **`clearFault()`** - Clears any existing faults. ### Enumerations - **`MAX31865_Units`** - Represents the units for temperature readings (e.g., CELSIUS, FAHRENHEIT). - **`MAX31865_Configuration`** - Represents various configuration settings for the sensor (e.g., resistance, filter, power). ### Examples ```cpp // Example usage of the MAX31865 library #include "MAX31865.h" // Define SPI pins const int SPI_CS = 10; const int SPI_CLK = 13; const int SPI_MOSI = 11; const int SPI_MISO = 12; // Initialize the MAX31865 sensor MAX31865 sensor(SPI_CS, SPI_CLK, SPI_MOSI, SPI_MISO); void setup() { Serial.begin(9600); // Configure the sensor for 4-wire RTD, 430C range, 50Hz filter MAX31865_Configuration config; config.wires = MAX31865_WIRES_4; config.range = MAX31865_RANGE_430; config.filter = MAX31865_FILTER_50HZ; config.power = MAX31865_POWER_ON; if (sensor.begin(config)) { Serial.println("MAX31865 sensor initialized successfully."); } else { Serial.println("Error initializing MAX31865 sensor."); while (1); } } void loop() { // Read temperature in Celsius float temperatureC = sensor.readRTD(MAX31865_UNITS_CELSIUS); Serial.print("Temperature: "); Serial.print(temperatureC); Serial.println(" C"); // Read fault status uint8_t fault = sensor.readFault(); if (fault != 0) { Serial.print("Fault detected: 0x"); Serial.println(fault, HEX); // Clear fault if necessary // sensor.clearFault(); } delay(1000); } ``` ``` -------------------------------- ### Null Pointer Handling in GetFault() Source: https://github.com/bolderflight/max31865/blob/main/_autodocs/errors.md Demonstrates how the GetFault() method validates its pointer parameter, returning false for a NULL pointer and true for a valid pointer. ```cpp rtd.GetFault(nullptr); // Returns false - pointer is NULL uint8_t code; rtd.GetFault(&code); // Returns true - valid pointer ``` -------------------------------- ### Check MAX31865 Initialization Failure Source: https://github.com/bolderflight/max31865/blob/main/_autodocs/errors.md Verify the return value of Begin() to detect initialization failures. Common causes include SPI communication errors, chip select pin issues, or configuration write/verify failures. ```cpp if (!rtd.Begin(bfs::Max31865::RTD_3WIRE, 100.0f, 402.0f)) { // One of the following occurred: // 1. SPI communication failed // 2. Chip select pin setup failed // 3. Configuration write/verify cycle failed // 4. Register read/write failed } ``` -------------------------------- ### Configure Filter for Noise Rejection Source: https://github.com/bolderflight/max31865/blob/main/_autodocs/api-reference-max31865.md Configures the MAX31865 sensor's digital filter to reject noise from specific AC power frequencies. This example sets the filter to 60 Hz for North American regions. ```cpp // Set 60 Hz filter for North American power regions if (!rtd.ConfigFilter(bfs::Max31865::FILTER_60HZ)) { Serial.println("Failed to configure filter"); } ``` -------------------------------- ### Configure SPI and Chip Select for Max31865 Source: https://github.com/bolderflight/max31865/blob/main/_autodocs/api-reference-max31865.md Call this method after using the default constructor to set the SPI bus and chip select pin. It must be called before Begin(). ```cpp bfs::Max31865 rtd; rtd.Config(&SPI1, 29); ``` -------------------------------- ### Initialize Max31865 with Different RTD Wire Configurations Source: https://github.com/bolderflight/max31865/blob/main/_autodocs/types.md Demonstrates how to initialize the Max31865 sensor with different RTD wire configurations. Ensure the correct RtdWire enum value is passed to the Begin() method based on your RTD probe. ```cpp // Typical 3-wire RTD sensor (Pt100) if (!rtd.Begin(bfs::Max31865::RTD_3WIRE, 100.0f, 402.0f)) { // Initialization failed } ``` ```cpp // Precision 4-wire configuration if (!rtd.Begin(bfs::Max31865::RTD_4WIRE, 100.0f, 402.0f)) { // Initialization failed } ``` ```cpp // Budget-conscious 2-wire configuration if (!rtd.Begin(bfs::Max31865::RTD_2WIRE, 100.0f, 402.0f)) { // Initialization failed } ``` -------------------------------- ### Configuration Methods Source: https://github.com/bolderflight/max31865/blob/main/_autodocs/INDEX.md Methods for configuring the sensor's SPI interface, wiring, resistance, and filter settings. ```APIDOC ## Configuration Methods ### `Config(SPIClass *spi, const uint8_t cs)` **Description:** Configures the SPI interface and chip select pin for the sensor. ### `Begin(const RtdWire wires, const float r0, const float resist)` **Description:** Initializes the sensor with specified RTD wiring configuration, nominal resistance at 0°C, and resistance value. **Parameters:** - `wires` (RtdWire): The wiring configuration (e.g., `RTD_4WIRE`, `RTD_3WIRE`, `RTD_2WIRE`). - `r0` (float): The nominal resistance of the RTD sensor at 0°C (e.g., 100.0 for Pt100). - `resist` (float): The resistance value of the RTD sensor. **Returns:** `true` if initialization is successful, `false` otherwise. ### `ConfigFilter(const Filter filter)` **Description:** Sets the noise filter frequency for the sensor. **Parameters:** - `filter` (Filter): The desired filter setting (`FILTER_50HZ` or `FILTER_60HZ`). **Returns:** `true` if configuration is successful, `false` otherwise. ``` -------------------------------- ### void Config(SPIClass *spi, const uint8_t cs) Source: https://github.com/bolderflight/max31865/blob/main/_autodocs/api-reference-max31865.md Configures the SPI bus and chip select pin for the Max31865. This method is required when using the default constructor. ```APIDOC ## void Config(SPIClass *spi, const uint8_t cs) ### Description Configures the SPI bus and chip select pin. Required when using the default constructor. ### Parameters #### Path Parameters - **spi** (SPIClass*) - Required - Pointer to the SPI bus object - **cs** (uint8_t) - Required - Chip select pin number ### Return Type `void` ### Throws None ### Notes Must be called before `Begin()` when using the default constructor. ``` -------------------------------- ### Initialize MAX31865 with SPI and Chip Select Source: https://github.com/bolderflight/max31865/blob/main/README.md Instantiates a Max31865 object using a provided SPI bus object and chip select pin. ```C++ /* MAX31865 on SPI1 CS pin 29 */ bfs::Max31865 rtd(&SPI1, 29); ``` -------------------------------- ### Constructors Source: https://github.com/bolderflight/max31865/blob/main/_autodocs/INDEX.md Initialize the MAX31865 sensor object. You can use a default constructor or provide specific SPI and chip select pins. ```APIDOC ## Constructors ### Default Constructor ```cpp bfs::Max31865 rtd; ``` ### Parameterized Constructor ```cpp bfs::Max31865 rtd(&SPI1, 29); ``` **Description:** - The default constructor initializes the sensor with default SPI settings and chip select pin. - The parameterized constructor allows you to specify the SPI interface (`SPIClass *spi`) and the chip select pin (`const uint8_t cs`) to use. ``` -------------------------------- ### Integrate Max31865 with Other Sensors on SPI Bus Source: https://github.com/bolderflight/max31865/blob/main/_autodocs/getting-started.md Demonstrates how to use the Max31865 library alongside other SPI devices. Ensure SPI is initialized before beginning sensor operations. ```cpp bfs::Max31865 rtd(&SPI1, 29); // RTD on CS 29 bfs::SomethingElse device(&SPI1, 31); // Other device on CS 31 void setup() { SPI1.begin(); rtd.Begin(bfs::Max31865::RTD_3WIRE, 100.0f, 402.0f); device.begin(); // Initialize other device } void loop() { if (rtd.Read()) { Serial.println(rtd.temp_c()); } if (device.read()) { // Process other sensor } } ``` -------------------------------- ### Initialize Max31865 with Parameterized Constructor Source: https://github.com/bolderflight/max31865/blob/main/_autodocs/configuration.md Initialize the Max31865 sensor using the parameterized constructor, providing a pointer to the SPI bus object and the chip select pin number. This is a common way to set up the sensor with specific hardware connections. ```cpp bfs::Max31865 rtd(&SPI1, 29); ``` -------------------------------- ### Configuration Modification Post-Initialization Source: https://github.com/bolderflight/max31865/blob/main/_autodocs/architecture.md Modify configuration settings like the filter after the resource has been initialized with Begin(). Check the return value of ConfigFilter() for errors. ```cpp if (!rtd.ConfigFilter(bfs::Max31865::FILTER_60HZ)) { // Handle error } ``` -------------------------------- ### Configure Chip Select Pin Source: https://github.com/bolderflight/max31865/blob/main/_autodocs/configuration.md Instantiate the Max31865 object, passing the SPI interface and the chip select pin number. The library automatically configures the pin as an output, sets it HIGH initially, pulls it LOW during transactions, and restores it to HIGH afterward. ```cpp Max31865 rtd(&SPI1, 29); // CS pin is 29 ``` -------------------------------- ### Max31865(SPIClass *spi, const uint8_t cs) Constructor Source: https://github.com/bolderflight/max31865/blob/main/_autodocs/api-reference-max31865.md Constructor that initializes the Max31865 with a specified SPI bus and chip select pin. ```APIDOC ## Max31865(SPIClass *spi, const uint8_t cs) ### Description Constructor that initializes the Max31865 with SPI bus and chip select pin. ### Parameters #### Path Parameters - **spi** (SPIClass*) - Required - Pointer to the SPI bus object (e.g., &SPI1, &SPI) - **cs** (uint8_t) - Required - Chip select pin number; any digital I/O pin supported ### Throws None ### Notes SPI bus object must be initialized separately (e.g., `SPI1.begin()`) before calling `Begin()`. ``` -------------------------------- ### Max31865() Constructor Source: https://github.com/bolderflight/max31865/blob/main/README.md Default constructor for the Max31865 class. Requires calling the Config method to set up the SPI bus and chip select pin. ```APIDOC ## Max31865() ### Description Default constructor. Requires calling the *Config* method to setup the SPI bus and chip select pin. ### Method Constructor ### Parameters None ``` -------------------------------- ### Initialize SPI and Configure MAX31865 Sensor Source: https://github.com/bolderflight/max31865/blob/main/README.md Initializes the SPI communication bus and then configures the MAX31865 sensor with RTD wire configuration, resistance at 0C, and reference resistor resistance. Ensure the SPI bus is initialized separately before calling this method. ```C++ /* Init SPI and MAX31865 */ SPI1.begin(); if (!rtd.Begin(bfs::Max31865::RTD_3WIRE, 100.0f, 402.0f)) { Serial.println("ERROR initializing RTD"); while (1) {} } ``` -------------------------------- ### SPI Debugging and Verification Source: https://github.com/bolderflight/max31865/blob/main/_autodocs/spi-protocol.md Provides steps to verify SPI bus initialization, chip select pin configuration, and test read/write operations. Includes error handling for read failures and printing register values. ```cpp // 1. Verify SPI bus initialized SPI1.begin(); // 2. Verify CS pin configured pinMode(29, OUTPUT); // 3. Test read operation uint8_t config = 0; if (!rtd.ReadRegisters(0x00, 1, &config)) { Serial.println("Read failed"); } else { Serial.print("Config register: 0x"); Serial.println(config, HEX); } // 4. Test write operation uint8_t test_val = 0xA0; if (!rtd.WriteRegister(0x00, test_val)) { Serial.println("Write failed"); } ``` -------------------------------- ### Perform Single-Shot Measurement with Error Checks Source: https://github.com/bolderflight/max31865/blob/main/_autodocs/errors.md Execute a single-shot temperature conversion, including checks for failures during auto-conversion disabling, bias voltage enabling, triggering the conversion, and reading the result. Ensure proper delays are observed. ```cpp if (!rtd.DisableAutoConversion()) { // Could not disable auto-conversion return; } if (!rtd.EnableBiasVoltage()) { // Could not enable bias voltage return; } delay(105); // Wait for bias to settle if (!rtd.Trigger1Shot()) { // Single-shot trigger failed // Likely causes: // - SPI communication error // - Auto-conversion was not properly disabled // - Sensor not responding return; } delay(65); // Wait for conversion if (!rtd.Read()) { // Read failed return; } if (!rtd.DisableBiasVoltage()) { // Could not disable bias voltage // Should still attempt to disable for next cycle } ``` -------------------------------- ### Max31865 Constructors Source: https://github.com/bolderflight/max31865/blob/main/_autodocs/TABLE_OF_CONTENTS.txt Provides details on how to instantiate the Max31865 class. ```APIDOC ## Max31865 Constructors ### Description Instantiates the Max31865 class. ### Constructors - **Max31865()** - Default constructor. - **Max31865(SPIClass *spi, const uint8_t cs)** - Parameterized constructor. - **Parameters**: - **spi** (SPIClass *) - Pointer to the SPI communication object. - **cs** (uint8_t) - Chip select pin number. ``` -------------------------------- ### Handle Sensor Faults Source: https://github.com/bolderflight/max31865/blob/main/_autodocs/TABLE_OF_CONTENTS.txt Demonstrates how to check for and handle sensor faults reported by the MAX31865. ```cpp MAX31865 sensor(3.3, 5.0, 1000.0, 4096.0, 2, 3, 4, 5); sensor.begin(); if (sensor.faultDetected()) { // Handle fault uint8_t fault = sensor.readFault(); // Process fault code } else { float temperature = sensor.readTemperature(); // Process temperature } ``` -------------------------------- ### SPI Transaction Format Source: https://github.com/bolderflight/max31865/blob/main/_autodocs/spi-protocol.md Demonstrates the standard Arduino SPI transaction pattern including beginTransaction, transfer, and endTransaction. ```cpp spi_->beginTransaction(SPISettings(SPI_CLOCK_, MSBFIRST, SPI_MODE1)); digitalWrite(cs_, LOW); // Assert CS low spi_->transfer(...); // Send/receive data digitalWrite(cs_, HIGH); // Release CS high spi_->endTransaction(); // Release SPI bus ``` -------------------------------- ### Initialize SPI Bus Source: https://github.com/bolderflight/max31865/blob/main/_autodocs/configuration.md The SPI bus must be initialized before calling the library's Begin() function. Use SPI1.begin() for specific SPI peripherals or SPI.begin() for the standard Arduino SPI interface. ```cpp // Must initialize SPI bus before calling Begin() SPI1.begin(); ``` ```cpp // Or for standard Arduino SPI: SPI.begin(); ``` -------------------------------- ### Max31865 Constructor Overloads Source: https://github.com/bolderflight/max31865/blob/main/_autodocs/TABLE_OF_CONTENTS.txt Demonstrates the two available constructors for the Max31865 class: a default constructor and a parameterized constructor that accepts SPIClass and chip select pin. ```cpp Max31865() Max31865(SPIClass *spi, const uint8_t cs) ``` -------------------------------- ### Tracking Configuration State Source: https://github.com/bolderflight/max31865/blob/main/_autodocs/configuration.md The library does not expose methods to read current configuration. User code must track these values if needed. ```cpp // No getter methods available // Configuration must be tracked in user code if needed bool is_continuous = true; // Track in application float current_r0 = 100.0f; // Track in application uint8_t current_cs = 29; // Track in application ``` -------------------------------- ### Max31865 Public Methods Overview Source: https://github.com/bolderflight/max31865/blob/main/_autodocs/TABLE_OF_CONTENTS.txt Lists the public methods available in the Max31865 class, including configuration, measurement, and fault reading functions. ```cpp void Config(SPIClass *spi, const uint8_t cs) bool Begin(const RtdWire wires, const float r0, const float resist) bool ConfigFilter(const Filter filter) bool EnableBiasVoltage() bool DisableBiasVoltage() bool EnableAutoConversion() bool DisableAutoConversion() bool Trigger1Shot() bool Read() float temp_c() const bool fault() const bool GetFault(uint8_t * const fault) ``` -------------------------------- ### MAX31865 Configuration Methods Source: https://github.com/bolderflight/max31865/blob/main/_autodocs/INDEX.md Configure the MAX31865 sensor. Specify the SPI interface and chip select pin, or initialize with RTD wire configuration, reference resistance, and sensor resistance. ```cpp void Config(SPIClass *spi, const uint8_t cs); bool Begin(const RtdWire wires, const float r0, const float resist); bool ConfigFilter(const Filter filter); ```