### Configure and Run Calibration Calculation Source: https://github.com/texasinstruments/precision-adc-examples/blob/main/devices/pga3xx/README.md Example demonstrating how to initialize the PGACoeffCalculator class with temperature, pressure, and DAC matrices, then perform regression and compute DAC output values. ```python tadc = [[0x3243B3, 0x324991, 0x324B34, 0x3247F2], [0x38C14B, 0x38CD8B, 0x38D8ED, 0x38D326], [0x53A5DC, 0x53C289, 0x53E7A3, 0x5408B2], [0x619158, 0x619E32, 0x61A6D2, 0x61AD6D]] padc = [[0xF585B6, 0x1146C8, 0x397173, 0x574F0C], [0xF8434C, 0x125217, 0x38020D, 0x5411B3], [0xFE9E3E, 0x1328D1, 0x30FDB3, 0x474B08], [0xFFF43F, 0x125D8A, 0x2D2411, 0x4134DA]] dac = [[0x666, 0x1FFF, 0x3998, 0x3FFF], [0x666, 0x1FFF, 0x3998, 0x3FFF], [0x666, 0x1FFF, 0x3998, 0x3FFF], [0x666, 0x1FFF, 0x3998, 0x3FFF]] cc = PGACoeffCalculator(cal_point=(4, 4), adc_resolution=24, tad_matrix=tadc, pad_matrix=padc, dac_matrix=dac) cc.recommend_calibration(offset_enabled=False) cc.normalize_data() cc.calculate_regression() cc.summarize_results() dac_output = cc.compute_dac_value(tadc_value=0x3243B3, padc_value=0xF585B6) print(f"DAC output: {dac_output} (Hex: 0x{cc.signed_int_to_hex(dac_output)})") ``` -------------------------------- ### ADS125P08 Example Code Overview Source: https://github.com/texasinstruments/precision-adc-examples/blob/main/devices/ads125p08/MSPM0 Launchpad/README.md This section provides an overview of the example code project for the ADS125P08, designed to run on a TI MSPM0L1306 Launchpad. It highlights the use of a Hardware Abstraction Layer (HAL) for portability. ```APIDOC ## ADS125P08 Example Code The following example code project is intended to run on a TI MSPM0L1306 Launchpad. This project utilizes a Hardware Abstraction Layer (HAL) and can be ported to other processors by making use of the HAL.c / HAL.h files. ### Peripherals & Pin Assignments Visit [LP_MSPM0L1306](https://www.ti.com/tool/LP-MSPM0L1306) for LaunchPad information, including user guide and hardware files. | Peripheral | Pin | Function | | --- | --- | --- | | SPI0 | PA6 | SPI SCLK (Clock) | | SPI0 | PA5 | SPI PICO (Peripheral In, Controller Out) | | SPI0 | PA4 | SPI POCI (Peripheral Out, Controller In) | | SPI0 | PA23 | SPI CS1 (Chip Select 1) | | GPIO | PA22 | DRDYn ( Data Ready |) The included example applications executes a few simple data collection routines. The main file **main_nortos.c** contains 3 example collection routines. Each routine configures the ADC with unique settings and collects a number of samples in a constantly running loop. ```c simpleADC(); // A simple, single channel data converter example sequencerExample(); // Channel scanning example using the sequencer FIFOexample(); // Data retreival using the FIFO ``` ``` -------------------------------- ### Interface with I2C ADCs Source: https://context7.com/texasinstruments/precision-adc-examples/llms.txt Provides a comprehensive guide to initializing, configuring, and reading from I2C-based ADCs such as the ADS1115. It covers single-shot conversion, differential measurements, and continuous conversion modes. ```c #include "ads1115.h" /* Initialize I2C and ADC */ adcStartup(); /* Configure the ADC: * - Single-ended input on AIN0 (referenced to GND) * - PGA full-scale range: ±4.096V * - Single-shot conversion mode * - 128 SPS data rate * - Comparator disabled */ uint16_t config = CONFIG_MUX_AIN0_GND | /* AIN0 vs GND */ CONFIG_PGA_4p096V | /* ±4.096V range */ CONFIG_MODE_SS | /* Single-shot mode */ CONFIG_DR_128SPS | /* 128 samples/second */ CONFIG_COMP_QUE_DISABLE; /* Disable comparator */ /* Write configuration */ bool writeError = writeSingleRegister(CONFIG_ADDRESS, config); if (writeError) { printf("Configuration write failed!\n"); return; } /* Read conversion data (starts conversion and waits for result) */ int16_t rawData = readData(); /* Convert to voltage (4.096V FSR, 16-bit signed) */ double voltage = ((double)rawData / 32768.0) * 4.096; printf("AIN0 Voltage: %.4f V (raw: %d)\n", voltage, rawData); /* Change to differential measurement: AIN0 - AIN1 */ config = (config & ~CONFIG_MUX_MASK) | CONFIG_MUX_AIN0_AIN1; writeSingleRegister(CONFIG_ADDRESS, config); rawData = readData(); voltage = ((double)rawData / 32768.0) * 4.096; printf("Differential (AIN0-AIN1): %.4f V\n", voltage); /* Read using continuous conversion mode */ config = (config & ~CONFIG_MODE_MASK) | CONFIG_MODE_CONT; startAdcConversion(); for (int i = 0; i < 10; i++) { delay_ms(10); /* Wait for new data */ int32_t data = readConversionRegister(); printf("Sample %d: %ld\n", i, data); } /* Stop continuous conversion */ stopAdcConversion(); ``` -------------------------------- ### MSP432E4 HAL Implementation for Precision ADCs Source: https://context7.com/texasinstruments/precision-adc-examples/llms.txt Provides an example implementation of the HAL functions for the MSP432E4 microcontroller, including delay functions, SPI transaction handling, and DRDY interrupt-based waiting. ```c /* MSP432E4 delay implementation */ void delay_us(const uint32_t delay_time_us) { /* Use SysTick or timer for precise delays */ SysCtlDelay((SysCtlClockGet() / 3000000) * delay_time_us); } void delay_ms(const uint32_t delay_time_ms) { delay_us(delay_time_ms * 1000); } /* SPI transaction implementation */ void spiSendReceiveArrays(SPI_Handle spiHdl, uint8_t DataTx[], uint8_t DataRx[], uint8_t byteLength) { SPI_Transaction transaction; transaction.count = byteLength; transaction.txBuf = DataTx; transaction.rxBuf = DataRx; setCS(LOW); /* Assert chip select */ SPI_transfer(spiHdl, &transaction); setCS(HIGH); /* Deassert chip select */ } /* DRDY interrupt-based waiting */ static volatile bool drdyFlag = false; void DRDY_ISR(void) { drdyFlag = true; GPIO_clearInt(DRDY_PIN); } bool waitForDRDYHtoL(uint32_t timeout_ms) { drdyFlag = false; uint32_t startTime = getTickCount(); while (!drdyFlag) { if ((getTickCount() - startTime) > timeout_ms) { return false; /* Timeout */ } } return true; } ``` -------------------------------- ### Implement HAL Millisecond Delay Function Source: https://github.com/texasinstruments/precision-adc-examples/blob/main/devices/ads125h02/README.md This function provides a template for implementing a millisecond delay within the HAL. It uses the TivaWare SysCtlDelay function as an example, which must be adapted to the specific timing requirements of the target hardware. ```c /** * \fn void delay_ms(uint32_t time_ms) * \brief Delays for a number of milliseconds, specified by argument * \param time_ms number of milliseconds to delay */ void delay_ms(uint32_t time_ms) { /* --- INSERT YOUR CODE HERE --- * Delay for a number of milliseconds, as specified by "time_ms". * * The following code shows an example using TivaWare™... * NOTE: In this example 40,000 system ticks is 1 ms. */ uint32_t ticks = 40000 * time_ms; SysCtlDelay(ticks); } ``` -------------------------------- ### Control ADC Conversions Source: https://context7.com/texasinstruments/precision-adc-examples/llms.txt Shows how to start and stop ADC conversions using either hardware pin control or software commands. Hardware control is recommended for precise timing, while software commands offer flexibility. ```c #include "ads124s08.h" /* Method 1: Hardware pin control (recommended for precise timing) */ #ifdef START_PIN_CONTROLLED /* Start continuous conversions by setting START pin high */ startConversions(spiHandle); /* Wait for data ready */ while (!waitForDRDYHtoL(1000)) { /* Timeout or error handling */ } /* Stop conversions by setting START pin low */ stopConversions(spiHandle); #endif /* Method 2: Software command control */ #ifndef START_PIN_CONTROLLED /* Wake device from power-down mode */ sendWakeup(spiHandle); /* Start conversion via command */ sendCommand(spiHandle, OPCODE_START); /* Poll for DRDY or use interrupt */ while (!waitForDRDYHtoL(1000)) { /* Handle timeout */ } /* Stop conversions */ sendCommand(spiHandle, OPCODE_STOP); #endif ``` -------------------------------- ### ADC Configuration Code Generation Tool Source: https://github.com/texasinstruments/precision-adc-examples/blob/main/devices/ads125p08/MSPM0 Launchpad/README.md This section details the use of the PADC Design Calculator tool for generating ADC sequencer configurations. It includes an example of the generated C code for register configuration. ```APIDOC ## ADC Configuration Code Generation Tool Visit [PADC Design Calculator](https://dev.ti.com/gallery/view/PADC/PADC_Design_Calculator_Tool/?device=ADS125P08) to use the Sequence Configuration tool **Example:** ```c // Generated by the ADS125P08 Sequencer Configuration Tool on 1/8/2026, 3:55:30 PM #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) #define EXT_CLK_FREQ_MHZ (25.6) // Define a value between 0.5 and 26.2 /* Type definitions */ typedef struct { const uint8_t addr; const uint8_t value; } RegisterConfig; typedef struct { const uint8_t pageNumber; const RegisterConfig *configPointer; const int registerCount; } PageConfig; /* Global page */ RegisterConfig global_page_config[] = { { .addr = 0x13, .value = 0x00 }, // REFERENCE_CFG }; RegisterConfig step0_config[] = { { .addr = 0x03, .value = 0x0B }, // STEP0_FLTR1_CFG, { .addr = 0x0B, .value = 0x01 }, // STEP0_OW_SYSMON_CFG }; PageConfig ADS125P08_sequencer_config[] = { { .pageNumber = 0x00, .configPointer = global_page_config, .registerCount = ARRAY_SIZE(global_page_config) }, { .pageNumber = 0x01, .configPointer = step0_config, .registerCount = ARRAY_SIZE(step0_config)} }; #define SEQUENCE_SIZE (ARRAY_SIZE(ADS125P08_sequencer_config)) ``` These register configurations are loaded into the ADC by using the ``` initADC(); ``` function. ``` -------------------------------- ### ADS125P08 Example Code Functions Source: https://github.com/texasinstruments/precision-adc-examples/blob/main/devices/ads125p08/MSPM0 Launchpad/README.md This section lists and describes the available C functions for interacting with the ADS125P08 ADC, including functions for initialization, power management, conversion control, and data reading. ```APIDOC ## Example Code Functions ```c uint8_t getRegisterValue(uint8_t page, uint8_t address); void initADC(void); void powerDownMode(void); void activeMode(void); bool resetDevice(void); void startAdcConversion(void); void stopAdcConversion(void); REG_IO readSingleRegister(uint8_t page, uint8_t address); REG_IO writeSingleRegister(uint8_t page, uint8_t address, uint8_t data); STATUS_IO checkStatus(void); ADC_IO readData(void); ADC_IO readFIFO(void); int32_t signExtend(const uint8_t dataBytes[]); void enableRegisterMapCrc(bool enable); bool isValidCrcOut(void); ``` ``` -------------------------------- ### Custom ADC Driver Template (C) Source: https://github.com/texasinstruments/precision-adc-examples/blob/main/applications/Field transmitter/readme.md An empty template for developing custom ADC drivers. It provides function stubs that return STATUS_OK, serving as a starting point for interfacing with different ADC hardware or creating custom acquisition logic. This template is ideal when beginning a new ADC driver project. ```c // Template structure for implementing new drivers // Example function stub: // status_t custom_adc_init(void) { // return STATUS_OK; // } ``` -------------------------------- ### ADC Startup Routine Source: https://context7.com/texasinstruments/precision-adc-examples/llms.txt Initializes the ADC device by performing power-up sequences, hardware resets, and register validation to ensure the device is ready for operation. ```APIDOC ## FUNCTION adcStartupRoutine ### Description Performs the mandatory power-up sequence, hardware reset via nRESET pin, and register map synchronization for SPI-based ADCs. ### Method Internal C Function (SPI-based) ### Parameters - **spiHandle** (SPI_Handle) - Required - Handle to the initialized SPI peripheral. ### Request Example ```c bool adcReady = adcStartupRoutine(spiHandle); ``` ### Response #### Success Response (bool) - **Returns** (boolean) - True if initialization and register verification succeeded, false otherwise. ``` -------------------------------- ### Implement UART Command Interface (C) Source: https://github.com/texasinstruments/precision-adc-examples/blob/main/applications/Field transmitter/readme.md Initializes the UART peripheral, provides printf-style output, and handles command parsing and routing. It includes functions to initialize the command table and defines a command routing structure. Modifications are needed when adding new command categories or changing UART settings. ```c void uart_init(void); void uart_printf(const char *fmt, ...); void uart_handle_cmd(void); void uart_cmd_init(void); struct command { const char *name; void (*handler)(int argc, char *argv[]); }; extern struct command commands[]; ``` -------------------------------- ### Initialize M0 & ADC using C Source: https://github.com/texasinstruments/precision-adc-examples/blob/main/devices/ads122c14/README.md Initializes the microcontroller (M0) and the Analog-to-Digital Converter (ADC). This is a foundational step for any ADC operation. ```c 1) Initalize M0 & ADC ``` -------------------------------- ### Provide System Utilities and Commands (C) Source: https://github.com/texasinstruments/precision-adc-examples/blob/main/applications/Field transmitter/readme.md Offers system-level utilities including a cyclic function for the main loop, handling of system commands, and a 1ms system tick interrupt. It manages a global millisecond counter and a flag to trigger main loop execution. Modifications involve adding new system commands or altering main loop timing. ```c void system_cyclic(void); void system_cmd(int argc, char *argv[]); void SysTick_Handler(void); extern volatile uint32_t gSysTick; extern volatile uint8_t gMainLoop; ``` -------------------------------- ### ADC Initialization API Source: https://github.com/texasinstruments/precision-adc-examples/blob/main/devices/ads131m08/README.md Initializes the MCU peripherals and the ADS131M0x ADC device for communication. ```APIDOC ## void InitADC(void) ### Description Initializes the MCU peripherals connected to the ADC, including SPI configuration, and prepares the device for operation. ### Method Function Call ### Parameters None ### Request Example InitADC(); ### Response #### Success Response - **void** - Returns nothing, initializes internal state and hardware pins. ``` -------------------------------- ### HAL Interface Definition for Precision ADCs Source: https://context7.com/texasinstruments/precision-adc-examples/llms.txt Defines the processor-agnostic interface for SPI/I2C communication and GPIO control required by the Precision ADC examples. Users must implement these functions for their specific microcontroller platform. ```c #include #include /* Timing functions - implement for your MCU */ void delay_ms(const uint32_t delay_time_ms); void delay_us(const uint32_t delay_time_us); /* GPIO control for ADC signals */ void setSTART(bool state); /* Control START/SYNC pin */ bool getSTART(void); /* Read START pin state */ void setCS(bool state); /* Control chip select */ bool getCS(void); void setRESET(bool state); /* Control nRESET pin */ void toggleRESET(void); /* Pulse reset pin */ /* SPI communication functions */ void spiSendReceiveArrays(SPI_Handle spiHdl, uint8_t DataTx[], uint8_t DataRx[], uint8_t byteLength); uint8_t spiSendReceiveByte(SPI_Handle spiHdl, uint8_t dataTx); /* Data ready monitoring */ bool waitForDRDYHtoL(uint32_t timeout_ms); /* Wait for DRDY falling edge */ bool getDRDYinterruptStatus(void); void setDRDYinterruptStatus(const bool value); void enableDRDYinterrupt(const bool intEnable); /* Software command alternatives to pin control */ void sendSTART(SPI_Handle spiHdl); void sendSTOP(SPI_Handle spiHdl); void sendRESET(SPI_Handle spiHdl); void sendWakeup(SPI_Handle spiHdl); void sendPowerDown(SPI_Handle spiHdl); ``` -------------------------------- ### Execute Calibration Calculator via CLI Source: https://github.com/texasinstruments/precision-adc-examples/blob/main/devices/pga3xx/README.md Commands to run the calibration script using modern package managers like uv or pipx, which handle dependency management automatically. ```bash uv run pga_coefficient_calculator.py pipx run pga_coefficient_calculator.py ``` -------------------------------- ### Configure System Clock Speeds and Delays (C) Source: https://github.com/texasinstruments/precision-adc-examples/blob/main/applications/Field transmitter/readme.md Provides functions for initializing the system clock to different frequencies (80MHz, 32MHz, 4MHz) and implementing high-resolution and low-power microsecond delays. It also exposes a global variable for the current system clock frequency. Modifications are needed for custom clock speeds or delay function adjustments. ```c void cpu_clock_init_80m(void); void cpu_clock_init_32m(void); void cpu_clock_init_4m(void); void delay_high_res_us(uint32_t us); void delay_us_standby(uint32_t us); extern uint32_t g_system_clk_frequency_mhz; ``` -------------------------------- ### Validate Data with CRC Source: https://context7.com/texasinstruments/precision-adc-examples/llms.txt Implements CRC validation for ADC communications to ensure data integrity. Includes examples for calculating CRC for outgoing commands and verifying incoming data packets using lookup tables or calculation methods. ```c #include "crc.h" /* Initialize CRC module (creates lookup table if using lookup method) */ initCRC(); /* Example 1: Calculate CRC for outgoing command bytes */ uint8_t txData[] = {0x20, 0x00}; /* RREG command for register 0 */ CRCWORD crc = getCRC(txData, 2, CRC_INITIAL_SEED); printf("Calculated CRC: 0x%02X\n", crc); /* Append CRC to command */ uint8_t txWithCRC[] = {0x20, 0x00, crc}; /* Example 2: Validate received data with CRC * If CRC calculation returns 0, data is valid */ uint8_t rxData[] = {0xAB, 0xCD, 0xEF, 0x5A}; /* 3 data bytes + CRC */ bool crcError = (bool)getCRC(rxData, 4, CRC_INITIAL_SEED); if (crcError) { printf("CRC Error: Data corruption detected!\n"); } else { printf("CRC Valid: Data integrity confirmed\n"); } /* Example 3: CRC validation for ADC data read (ADS1235 style) * When STATUS and CRC are enabled */ uint8_t adcResponse[] = { 0xFF, /* Byte 1: Always 0xFF */ 0x12, /* Byte 2: Echoed command */ 0x00, /* Byte 3: Don't care echo */ 0x45, /* Byte 4: CRC-2 echo */ 0x01, /* Byte 5: STATUS byte */ 0x7F, /* Byte 6: Data MSB */ 0xFF, /* Byte 7: Data MID */ 0x80, /* Byte 8: Data LSB */ 0xA5 /* Byte 9: CRC-4 of STATUS+DATA */ }; /* Validate CRC of status + data bytes */ CRCWORD calculatedCRC = getCRC(&adcResponse[4], 4, CRC_INITIAL_SEED); if (calculatedCRC != adcResponse[8]) { printf("Data CRC mismatch!\n"); } ``` -------------------------------- ### ADS125H18 ADC Data Collection Routines (C) Source: https://github.com/texasinstruments/precision-adc-examples/blob/main/devices/ads125h18/MSPM0 Launchpad/README.md This snippet contains three example data collection routines for the ADS125H18 ADC: simpleADC for single-channel conversion, sequencerExample for channel scanning, and FIFOexample for data retrieval using the FIFO buffer. These functions are intended to be called from the main_nortos.c file. ```C simpleADC(); // A simple, single channel data converter example sequencerExample(); // Channel scanning example using the sequencer FIFOexample(); // Data retreival using the FIFO ``` -------------------------------- ### Initialize ADC Peripherals Source: https://github.com/texasinstruments/precision-adc-examples/blob/main/devices/ads124s08/README.md Initializes the MCU peripherals required for communication with the ADS124S08 ADC. ```APIDOC ## void initADCperhiperhals() ### Description Initializes the microcontroller peripherals (SPI, GPIO) connected to the ADS124S08 device. This function must be implemented within the Hardware Abstraction Layer (HAL) to match the specific processor being used. ### Method N/A (C Function Call) ### Endpoint N/A ### Parameters None ### Request Example initADCperhiperhals(); ### Response #### Success Response (void) - **status** (void) - Initializes hardware state for ADC communication. ``` -------------------------------- ### ADS1235 Advanced Features: CRC, Locking, and Calibration Source: https://context7.com/texasinstruments/precision-adc-examples/llms.txt This C code snippet demonstrates advanced features of the ADS1235 ADC, including setting up for bridge sensor measurements, enabling CRC for data integrity, locking registers, and reading the internal temperature. It utilizes functions for startup, register writes, conversion start, and status checks. ```c #include "ads1235.h" /* Perform startup sequence */ adcStartupRoutine(); /* Configure for bridge sensor measurement: * - Differential input: AIN0 (positive), AIN1 (negative) * - PGA gain: 128 * - Data rate: 7.5 SPS (lowest noise) * - External reference on REFP/REFN pins */ /* Set input multiplexer */ writeSingleRegister(REG_ADDR_INPMUX, INPMUX_MUXP_AIN0 | INPMUX_MUXN_AIN1); /* Configure PGA */ writeSingleRegister(REG_ADDR_PGA, PGA_GAIN_128); /* Set data rate */ writeSingleRegister(REG_ADDR_MODE0, MODE0_DR_7p5SPS); /* Configure reference */ writeSingleRegister(REG_ADDR_REF, REF_REFSEL_EXT | REF_REFCON_OFF); /* Enable STATUS byte and CRC for data integrity */ writeSingleRegister(REG_ADDR_MODE3, MODE3_STATEN_ENABLED | MODE3_CRCEN_ENABLED); /* Start conversions and read data */ ads1235_startConversions(); pollForDRDY(100); uint8_t status, data[3], crc; int32_t rawResult = readData(&status, data, &crc); printf("Raw ADC result: %ld\n", rawResult); printf("Status: 0x%02X, CRC: 0x%02X\n", status, crc); /* Check status for alarms */ checkStatus(status); /* Lock registers to prevent accidental modification */ lockRegisters(); /* Verify lock */ if (REGISTER_LOCK) { printf("Registers are now locked\n"); } /* Unlock when configuration changes needed */ unlockRegisters(); /* Read internal temperature */ float tempC = ads1235_measure_internal_temperature_example(); printf("Die temperature: %.2f °C\n", tempC); ``` -------------------------------- ### ADS125P08 ADC Data Collection Routines (C) Source: https://github.com/texasinstruments/precision-adc-examples/blob/main/devices/ads125p08/MSPM0 Launchpad/README.md This snippet demonstrates three distinct data collection routines for the ADS125P08 ADC: a simple single-channel conversion, a channel scanning example using the sequencer, and data retrieval using the FIFO buffer. These routines are intended to be called from the main_nortos.c file and configure the ADC with specific settings for each operation. ```C simpleADC(); // A simple, single channel data converter example sequencerExample(); // Channel scanning example using the sequencer FIFOexample(); // Data retreival using the FIFO ``` -------------------------------- ### ADS125P08 ADC Control Functions (C) Source: https://github.com/texasinstruments/precision-adc-examples/blob/main/devices/ads125p08/MSPM0 Launchpad/README.md This set of C functions provides the interface for controlling the ADS125P08 ADC. It includes functions for initializing the ADC, managing power modes, starting and stopping conversions, reading and writing registers, checking status, reading data from the ADC and FIFO, and performing sign extension and CRC validation. These functions abstract the low-level communication with the ADC. ```C uint8_t getRegisterValue(uint8_t page, uint8_t address); void initADC(void); void powerDownMode(void); void activeMode(void); bool resetDevice(void); void startAdcConversion(void); void stopAdcConversion(void); REG_IO readSingleRegister(uint8_t page, uint8_t address); REG_IO writeSingleRegister(uint8_t page, uint8_t address, uint8_t data); STATUS_IO checkStatus(void); ADC_IO readData(void); ADC_IO readFIFO(void); int32_t signExtend(const uint8_t dataBytes[]); void enableRegisterMapCrc(bool enable); bool isValidCrcOut(void); ``` -------------------------------- ### Configure HAL Processor-Specific Headers Source: https://github.com/texasinstruments/precision-adc-examples/blob/main/devices/ads1115/README.md This snippet shows where to include the processor-specific header files within the HAL module. Users must replace the placeholder with their actual MCU driver library header. ```c #include "ti/devices/msp432e4/driverlib/driverlib.h" ``` -------------------------------- ### Linear Output Scaling with Offset and Slope (C) Source: https://github.com/texasinstruments/precision-adc-examples/blob/main/applications/Field transmitter/readme.md Applies linear scaling (output = input × slope + offset) to the output signal, clamping the result to a 16-bit range (0-65535). Configuration for offset and slope can be stored in flash and modified via commands. This module is commonly modified for changing output ranges, implementing non-linear scaling, or performing unit conversions. ```c #include "out_condition_offset_slope_uint16.h" // Example: Applying scaling // int32_t input_value = 5000; // int32_t slope = 10; // int32_t offset = 100; // int32_t output_value = (input_value * slope) + offset; // // Clamp to 16-bit range... ``` -------------------------------- ### Configure HAL Processor-Specific Includes Source: https://github.com/texasinstruments/precision-adc-examples/blob/main/devices/ads125h02/README.md This snippet demonstrates where to include processor-specific driver headers within the HAL module. Users must replace the placeholder includes with the specific library headers for their target microcontroller. ```c //**************************************************************************** // // Insert processor specific header file(s) here // //**************************************************************************** /* --- TODO: INSERT YOUR CODE HERE --- */ #include "driverlib/sysctl.h" #include "driverlib/gpio.h" #include "driverlib/ssi.h" ``` -------------------------------- ### Initialize MCU SPI for ADC Communication (C) Source: https://github.com/texasinstruments/precision-adc-examples/blob/main/devices/ads1118/README.md This C code snippet demonstrates the initialization of the MCU's SPI peripheral for interfacing with the ADC. It requires modification to include processor-specific header files and implement the SPI configuration according to the ADSxxxx's requirements (SPI mode 1). ```c //**************************************************************************** // // Insert processor specific header file(s) here // //****************************************************************************" /* --- TODO: INSERT YOUR CODE HERE --- */ #include "ti/devices/msp432e4/driverlib/driverlib.h" ``` ```c //***************************************************************************** // //! Configures the MCU's SPI peripheral, for interfacing with the ADC. //! //! \fn void InitSPI(void) //! //! \return None. // //***************************************************************************** void InitSPI(void) { /* --- INSERT YOUR CODE HERE * NOTE: The ADSxxxx operates in SPI mode 1 (CPOL = 0, CPHA = 1) */ ``` -------------------------------- ### ADC Simulation Driver (C) Source: https://github.com/texasinstruments/precision-adc-examples/blob/main/applications/Field transmitter/readme.md A simulation driver for testing ADC software without requiring hardware. It can provide static values or generate counting sequences, making it useful for software development and testing. New simulation modes like ramp, sine wave, or noise can be added, along with custom test sequences and sensor behavior simulation. ```c #include "adc_example.h" // Example of setting a static simulated value: // adc_sim_static(1024); // Example of setting a counting sequence: // adc_sim_up(0, 10, 100); // start=0, step=10, interval=100ms ``` -------------------------------- ### Execute SPI ADC Commands Source: https://context7.com/texasinstruments/precision-adc-examples/llms.txt Demonstrates how to send single-byte SPI commands to an ADC for operations such as reset and various calibration routines (system offset, gain, and self-offset). It includes logic for post-command delays and reading back calibration registers. ```c #include "ads124s08.h" /* Perform a software reset (returns device to default state) */ sendCommand(spiHandle, OPCODE_RESET); /* Note: 4096 tCLK delay is handled internally */ /* Internal register map is automatically restored to defaults */ /* Start system offset calibration * Short inputs before running this command */ sendCommand(spiHandle, OPCODE_SYOCAL); /* Wait for calibration to complete */ delay_ms(100); /* Start system gain calibration * Apply full-scale input before running this command */ sendCommand(spiHandle, OPCODE_SYGCAL); delay_ms(100); /* Start self-offset calibration (internal reference) */ sendCommand(spiHandle, OPCODE_SFOCAL); delay_ms(100); /* Read calibration results */ readMultipleRegisters(spiHandle, REG_ADDR_OFCAL0, 6); printf("Offset Cal: 0x%02X%02X%02X\n", getRegisterValue(REG_ADDR_OFCAL2), getRegisterValue(REG_ADDR_OFCAL1), getRegisterValue(REG_ADDR_OFCAL0)); printf("Gain Cal: 0x%02X%02X%02X\n", getRegisterValue(REG_ADDR_FSCAL2), getRegisterValue(REG_ADDR_FSCAL1), getRegisterValue(REG_ADDR_FSCAL0)); ``` -------------------------------- ### HAL Header File Placeholder (C) Source: https://github.com/texasinstruments/precision-adc-examples/blob/main/devices/ads1258/README.md This C header file snippet is a placeholder for including processor-specific library files. It is part of the Hardware Abstraction Layer (HAL) and needs to be updated with the correct includes for your specific MCU to enable the ADS1258 module to function correctly. ```c //**************************************************************************** // // Insert processor specific header file(s) here // //**************************************************************************** /* --- TODO: INSERT YOUR CODE HERE --- */ #include "ti/devices/msp432e4/driverlib/driverlib.h" ``` -------------------------------- ### Initialize I2C Peripheral in HAL Source: https://github.com/texasinstruments/precision-adc-examples/blob/main/devices/ads1115/README.md This function template provides the structure for initializing the I2C peripheral. Developers must fill in the specific register configurations and pin muxing for their target hardware. ```c void InitI2C(void) { // Enabling I2C2 peripheral. // Configuring the pin muxing for I2C2 functions. // Enabling and initializing the I2C2 master module. } ``` -------------------------------- ### Map Hardware IDs to ADC Drivers (C) Source: https://github.com/texasinstruments/precision-adc-examples/blob/main/applications/Field transmitter/readme.md Defines the active ADC and output drivers based on hardware IDs and provides driver name strings for the version command. This file is modified when adding new ADC or output drivers, or when changing the compiled firmware's driver configuration. ```c typedef struct { const char *name; void (*init)(void); // ... other driver function pointers } AdcDriver; extern AdcDriver AdcDrivers[]; extern uint8_t AdcDriverCnt; // Similar structure for Output drivers ``` -------------------------------- ### Initialize I2C Peripheral for ADS122C04 Source: https://github.com/texasinstruments/precision-adc-examples/blob/main/devices/ads122c04/README.md This function serves as a template for configuring the microcontroller's I2C peripheral. It must be implemented in the hal.c file to match the specific hardware requirements of the target MCU. ```c /** * \fn void InitSPI(void) * \brief Configures the MCU's SPI peripheral for interfacing with the ADS122C04 */ void InitI2C(void) { /* TODO: INSERT YOUR CODE HERE */ } ``` -------------------------------- ### Output Pass-Through Conditioning (C) Source: https://github.com/texasinstruments/precision-adc-examples/blob/main/applications/Field transmitter/readme.md A pass-through output conditioning module that converts a float input to an int32_t without applying any scaling or offset. This is useful when the input conditioning module provides the final value, for testing the output chain, or when no additional scaling is required. ```c #include "out_condition.h" // Example: Convert float to int32_t // int32_t out_condition_process(float value) { // return (int32_t)value; // } ``` -------------------------------- ### I2C Controller Initialization in C Source: https://github.com/texasinstruments/precision-adc-examples/blob/main/devices/ads122c14/README.md Initializes the I2C peripheral in controller mode with Fast mode+ speed. This configuration is used for communication between the MSPM0 Launchpad and the ADS122C14. ```c // I2C Controller // Fast mode + ``` -------------------------------- ### Initialize ADC Device (SPI) Source: https://context7.com/texasinstruments/precision-adc-examples/llms.txt Initializes the ADC device via SPI, including power-up sequence, hardware reset, and register validation. This function is crucial before any communication and ensures the device is ready for conversions. ```c #include "ads124s08.h" #include "hal.h" /* Initialize ADC peripherals and start communication */ SPI_Handle spiHandle; bool initSuccess; /* Initialize SPI and GPIO peripherals first */ initSuccess = InitADCPeripherals(&spiHandle); if (!initSuccess) { /* Handle initialization error */ return; } /* Run the ADC startup routine */ /* This performs: * - 2.2ms power supply settling delay * - Hardware reset via nRESET pin toggle * - 4096 tCLK delay after reset * - STATUS register check for device ready * - Register map initialization * - Configuration verification via read-back */ bool adcReady = adcStartupRoutine(spiHandle); if (adcReady) { /* ADC is initialized and ready for conversions */ printf("ADS124S08 initialized successfully\n"); } else { /* Initialization failed - device not ready or register mismatch */ printf("ADC initialization failed\n"); } ``` -------------------------------- ### Pressure/Temperature Compensation Algorithm (C) Source: https://context7.com/texasinstruments/precision-adc-examples/llms.txt This C function implements a 3rd-order polynomial algorithm for sensor compensation, calculating pressure based on temperature-dependent coefficients. It normalizes input counts, computes temperature-dependent polynomial coefficients (h, g, n, m), and applies them to the pressure and temperature counts to derive engineering units (PSI and °C). ```c /* Pressure/temperature compensation algorithm */ /* Uses 3rd-order polynomial: Output = h(T) + g(T)·P + n(T)·P² + m(T)·P³ */ void condition_adc_cyclic(int32_t pCounts, int32_t tCounts, float *pressure, float *temp) { /* Normalize inputs (coefficients scaled to 2^30) */ int64_t P = (int64_t)(pCounts - P_offset); int64_t T = (int64_t)(tCounts - T_offset); /* Calculate temperature-dependent coefficients */ int64_t h_T = h0 + (h1*T >> 30) + (h2*T*T >> 60) + (h3*T*T*T >> 90); int64_t g_T = g0 + (g1*T >> 30) + (g2*T*T >> 60) + (g3*T*T*T >> 90); int64_t n_T = n0 + (n1*T >> 30) + (n2*T*T >> 60); int64_t m_T = m0 + (m1*T >> 30); /* Apply polynomial */ int64_t result = h_T + (g_T*P >> 30) + (n_T*P*P >> 60) + (m_T*P*P*P >> 90); *pressure = (float)result / 1073741824.0f; /* Scale back from 2^30 */ *temp = (float)tCounts * TEMP_SCALE_FACTOR; } ``` -------------------------------- ### Manage Non-Volatile Configuration Storage (C) Source: https://github.com/texasinstruments/precision-adc-examples/blob/main/applications/Field transmitter/readme.md Handles the loading, saving, resetting, and dumping of non-volatile configuration data stored in flash memory. It includes functions for configuration initialization, saving to flash, resetting to defaults, and displaying the configuration via UART. A CRC8 function is used for integrity validation. Modifications are typically for changing configuration size or adding new sections. ```c void config_init(void); void config_save(void); void config_reset(void); void config_dump(void); uint8_t crc8(const uint8_t *data, size_t len); extern char gAdcConfigRam[256]; extern char aAdcCondConfigRam[256]; extern char gOutCondConfigRam[256]; extern char gOutputConfigRam[256]; ``` -------------------------------- ### Initialize SPI Peripheral Source: https://github.com/texasinstruments/precision-adc-examples/blob/main/devices/ads131m08/README.md Template function for configuring the MCU SPI peripheral. The ADS131M0x requires SPI mode 1 (CPOL=0, CPHA=1). ```c void InitSPI(void) { /* --- INSERT YOUR CODE HERE --- * NOTE: The ADS131M0x operates in SPI mode 1 (CPOL = 0, CPHA = 1). */ } ```