|
HF-ADS7952 Driver 0.1.0-dev
HF-ADS7952 C++ Driver
|
layout: default title: "HardFOC ADS7952 Driver" description: "Portable C++20 driver for the Texas Instruments ADS7952 12-channel 12-bit SAR ADC with SPI interface, auto-sequencing, GPIO, and alarm thresholds" nav_order: 1
Portable C++20 driver for the Texas Instruments ADS7952 12-channel, 12-bit SAR ADC with SPI interface
π ππ Live Complete Documentation β Interactive guides, examples, and step-by-step tutorials
HF-ADS7952 is a portable C++20 driver for the ADS7952 12-channel, 12-bit SAR ADC from Texas Instruments. It delivers up to 1 MSPS conversion rates over a 16-bit full-duplex SPI interface with support for manual channel selection, two auto-sequencing modes, configurable input range (Vref / 2ΓVref), per-channel alarm thresholds, 4 GPIO pins with alarm routing, and power-down control.
Designed for the HardFOC-V1 motor controller, it is equally suitable for any application requiring fast multi-channel ADC sampling β motor current sensing, temperature monitoring, battery management, or general-purpose data acquisition.
The driver uses a CRTP-based SpiInterface for hardware abstraction, allowing it to run on any platform (ESP32, STM32, Arduino, Linux spidev, etc.) with zero runtime overhead. All SPI frame sequences are datasheet-verified against TI ADS79xx SLAS605C Rev C.
ReadResult and ChannelReadings with built-in error checkingFor detailed setup, see Installation and Quick Start Guide.
For detailed installation instructions, see docs/installation.md.
| Method | Description |
|---|---|
EnsureInitialized() | Idempotent init β programs defaults on first call, no-op after |
ReadChannel(ch) | Read a single ADC channel β ReadResult with count, voltage, error |
ReadAllChannels() | Read all Auto-1 channels β ChannelReadings with per-channel data |
CountToVoltage(count) | Convert raw count using current active reference |
CountToVoltage(count, vref) | Static conversion with explicit reference voltage |
| Method | Description |
|---|---|
EnterManualMode(ch) | Switch to manual mode, selecting a channel |
EnterAuto1Mode(reset) | Switch to Auto-1 sequencing mode |
EnterAuto2Mode(reset) | Switch to Auto-2 sequencing mode |
GetMode() | Get current operating mode |
| Method | Description |
|---|---|
ProgramAuto1Channels(mask) | Set which channels Auto-1 sequences through |
ProgramAuto2LastChannel(ch) | Set the last channel for Auto-2 sequential scan |
ProgramGPIO(config) | Configure GPIO direction, alarm routing, special functions |
ProgramAlarm(ch, bound, threshold) | Set a per-channel alarm threshold (high or low) |
| Method | Description |
|---|---|
SetRange(range) | Set Vref or 2ΓVref input range |
SetPowerDown(pd) | Enter or exit power-down mode |
SetGPIOOutputs(state) | Drive GPIO output pin levels |
GetVref() / GetActiveVref() | Read reference voltages |
GetAuto1ChannelMask() | Read programmed Auto-1 channel mask |
GetAuto2LastChannel() | Read programmed Auto-2 last channel |
For complete API documentation, see docs/api_reference.md.
| Example | Description |
|---|---|
| Basic ADC Reading | Initialize, manual reads, batch reads, voltage conversion |
| Multi-Mode | Manual, Auto-1, Auto-2 modes with channel masks and range comparison |
| Alarm & GPIO | GPIO outputs, alarm thresholds, alarm-as-output configuration |
| Integration Tests | 30+ test cases across 9 sections with automatic pass/fail reporting |
For ESP32-S3 build instructions, see the examples/esp32 directory.
Detailed example walkthroughs are available in docs/examples.md.
Complete documentation is available in the docs directory:
| Guide | Description |
|---|---|
| π οΈ Installation | Prerequisites, submodule setup, CMake integration |
| β‘ Quick Start | Minimal working example in under 20 lines |
| π Hardware Setup | ADS7952 wiring, SPI config, power supply, decoupling |
| π§ Platform Integration | CRTP SPI interface for ESP32, STM32, Linux |
| βοΈ Configuration | Kconfig, CMake defines, voltage references, channel masks |
| π API Reference | Complete method signatures, enums, structs, error codes |
| π‘ Examples | Walkthrough of all 4 example applications |
| π Troubleshooting | Error codes, SPI debugging, common hardware issues |
| π© CMake Integration | Build system setup, ESP-IDF component, FetchContent |
| Resource | Link |
|---|---|
| TI ADS7952 product page | https://www.ti.com/product/ADS7952 |
| TI ADS79xx datasheet (SLAS605C Rev C) | https://www.ti.com/lit/ds/symlink/ads7952.pdf |
| ESP-IDF SPI master | https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/peripherals/spi_master.html |
| Linux spidev (Kernel docs) | https://www.kernel.org/doc/html/latest/spi/spidev.html |
| C++20 language reference | https://en.cppreference.com/w/cpp/20 |
Pull requests and suggestions are welcome! Please follow the existing code style and include tests for new features.
This project is licensed under the GNU General Public License v3.0. See the [LICENSE](LICENSE) file for details.