|
ADS7952 Driver
API reference
|
High-level class for initialization, conversion, sequencing, and programming. More...
Files | |
| file | ads7952.ipp |
| Template implementation for the ADS7952 driver. | |
Classes | |
| class | ads7952::ADS7952< SpiType > |
| Main driver class for the ADS7952 ADC. More... | |
Functions | |
| ads7952::ADS7952< SpiType >::ADS7952 (SpiType &spi, float vref=ADS7952_CFG::DEFAULT_VREF, float va=ADS7952_CFG::DEFAULT_VA, Range initial_range=ADS7952_CFG::DEFAULT_RANGE) noexcept | |
| Construct a new ADS7952 driver instance. | |
| void | ads7952::ADS7952< SpiType >::SetVref (float vref) noexcept |
| Update the Vref value for voltage calculations. | |
| void | ads7952::ADS7952< SpiType >::SetVA (float va) noexcept |
| Update the VA supply voltage value. | |
| bool | ads7952::ADS7952< SpiType >::EnsureInitialized (bool force=false) noexcept |
| Ensure the driver is initialized — idempotent, safe to call repeatedly. | |
| ReadResult | ads7952::ADS7952< SpiType >::ReadChannel (uint8_t channel) noexcept |
| Read a single ADC channel (switches to Manual mode). | |
| ChannelReadings | ads7952::ADS7952< SpiType >::ReadAllChannels () noexcept |
| Read all channels in the current Auto-1 sequence. | |
| float | ads7952::ADS7952< SpiType >::CountToVoltage (uint16_t count) const noexcept |
| Convert raw count to voltage using the currently active reference. | |
| uint16_t | ads7952::ADS7952< SpiType >::VoltageToCount (float voltage) const noexcept |
| Convert a voltage to a 12-bit ADC count using the active reference. | |
| bool | ads7952::ADS7952< SpiType >::EnterManualMode (uint8_t channel=0) noexcept |
| Enter Manual mode, selecting the given channel for conversion. | |
| bool | ads7952::ADS7952< SpiType >::EnterAuto1Mode (bool reset_counter=true) noexcept |
| Enter Auto-1 mode (sequences through programmed channel mask). | |
| bool | ads7952::ADS7952< SpiType >::EnterAuto2Mode (bool reset_counter=true) noexcept |
| Enter Auto-2 mode (sequences channels 0 through last_channel). | |
| bool | ads7952::ADS7952< SpiType >::ProgramAuto1Channels (uint16_t channel_mask) noexcept |
| Program the Auto-1 channel sequence. | |
| bool | ads7952::ADS7952< SpiType >::ProgramAuto2LastChannel (uint8_t last_channel) noexcept |
| Program the Auto-2 last channel. | |
| bool | ads7952::ADS7952< SpiType >::ProgramGPIO (const GPIOConfig &config) noexcept |
| Program GPIO pin functions, direction, and alarm routing. | |
| bool | ads7952::ADS7952< SpiType >::ProgramAlarm (uint8_t channel, AlarmBound bound, uint16_t threshold_12bit) noexcept |
| Program an alarm threshold for a single channel (count-based). | |
| bool | ads7952::ADS7952< SpiType >::ProgramAlarmVoltage (uint8_t channel, AlarmBound bound, float voltage) noexcept |
| Program an alarm threshold for a single channel (voltage-based). | |
| bool | ads7952::ADS7952< SpiType >::SetRange (Range range) noexcept |
| Set the input voltage range; in effect on the chip when this returns. | |
| bool | ads7952::ADS7952< SpiType >::SetPowerDown (PowerDown pd) noexcept |
| Set the power-down mode; in effect on the chip when this returns. | |
| bool | ads7952::ADS7952< SpiType >::SetGPIOOutputs (uint8_t gpio_state) noexcept |
| Set GPIO output pin levels (for pins configured as outputs). | |
| uint8_t | ads7952::ADS7952< SpiType >::RawManualFrames (uint8_t channel, uint16_t *out, uint8_t n) noexcept |
| Clock raw 16-bit frames and return every response word unparsed. | |
High-level class for initialization, conversion, sequencing, and programming.
|
explicitnoexcept |
Construct a new ADS7952 driver instance.
Construct a new ADS7952 driver instance.
| spi | Reference to platform-specific SPI interface |
| vref | REFP pin voltage in volts (default 2.5V for REF5025) |
| va | VA supply voltage in volts (default 5.0V) |
| initial_range | Initial input range to apply for conversions |
| spi | Reference to platform-specific SPI interface |
| vref | REFP pin voltage in volts (default 2.5V for REF5025) |
| va | VA supply voltage in volts (default 5.0V) |
| initial_range | Initial input range to apply for conversions |
Definition at line 46 of file ads7952.ipp.
|
noexcept |
Convert raw count to voltage using the currently active reference.
Convert raw count to voltage using the currently active reference.
| count | Raw 12-bit ADC count (0-4095) |
| count | Raw 12-bit ADC count (0-4095) |
Definition at line 244 of file ads7952.ipp.
References ads7952::reg::MAX_COUNT.
|
noexcept |
Ensure the driver is initialized — idempotent, safe to call repeatedly.
Ensure the driver is initialized — idempotent, safe to call repeatedly.
On first call: discards the invalid power-up conversion, programs defaults (Auto-1 channels, Auto-2 last channel), and enters Auto-1 mode. On subsequent calls: returns true immediately without SPI traffic.
| force | If true, re-runs the full initialization sequence even if the driver is already initialized. Use after a device reset or power cycle. |
On first call: discards the invalid power-up conversion, programs defaults (Auto-1 channels, Auto-2 last channel), and enters Auto-1 mode. On subsequent calls: returns true immediately without SPI traffic.
| force | If true, re-runs the full initialization sequence even if the driver is already initialized. Use after a device reset or power cycle. |
Definition at line 77 of file ads7952.ipp.
|
noexcept |
Enter Auto-1 mode (sequences through programmed channel mask).
Enter Auto-1 mode (sequences through programmed channel mask).
| reset_counter | true to reset channel counter to start of sequence |
| reset_counter | true to reset channel counter to start of sequence |
Definition at line 279 of file ads7952.ipp.
References ads7952::Auto1, ads7952::reg::Mode::AUTO_1, ads7952::reg::NO_RESET_COUNTER, ads7952::reg::PROGRAM_ENABLE, and ads7952::reg::RESET_COUNTER.
|
noexcept |
Enter Auto-2 mode (sequences channels 0 through last_channel).
Enter Auto-2 mode (sequences channels 0 through last_channel).
| reset_counter | true to reset channel counter to channel 0 |
| reset_counter | true to reset channel counter to channel 0 |
Definition at line 292 of file ads7952.ipp.
References ads7952::Auto2, ads7952::reg::Mode::AUTO_2, ads7952::reg::NO_RESET_COUNTER, ads7952::reg::PROGRAM_ENABLE, and ads7952::reg::RESET_COUNTER.
|
noexcept |
Enter Manual mode, selecting the given channel for conversion.
Enter Manual mode, selecting the given channel for conversion.
| channel | Channel to select (0-11, default 0) |
| channel | Channel to select (0-11, default 0) |
Definition at line 264 of file ads7952.ipp.
References ads7952::reg::ChannelSelect(), ads7952::reg::Mode::MANUAL, ads7952::Manual, ads7952::reg::NUM_CHANNELS, and ads7952::reg::PROGRAM_ENABLE.
|
noexcept |
Program an alarm threshold for a single channel (count-based).
Program an alarm threshold for a single channel (count-based).
The 12-bit ADC count (0–4095) is internally truncated to 10 bits for the hardware alarm register (only the top 10 bits are stored).
| channel | Channel number (0–11) |
| bound | Low or High alarm threshold |
| threshold_12bit | 12-bit ADC count (0–4095); internally right-shifted by 2 to produce 10-bit hardware threshold |
The 12-bit ADC count (0–4095) is internally truncated to 10 bits for the hardware alarm register (only the top 10 bits are stored).
| channel | Channel number (0–11) |
| bound | Low or High alarm threshold |
| threshold_12bit | 12-bit ADC count (0–4095); internally right-shifted by 2 to produce 10-bit hardware threshold |
Definition at line 397 of file ads7952.ipp.
References ads7952::reg::Mode::ALARM_GROUP_0, ads7952::reg::Mode::ALARM_GROUP_1, ads7952::reg::Mode::ALARM_GROUP_2, ads7952::reg::Alarm::ChannelInGroup(), ads7952::reg::CHANNELS_PER_ALARM_GROUP, ads7952::reg::Mode::CONTINUE, ads7952::reg::Alarm::EXIT_NEXT_FRAME, ads7952::High, ads7952::reg::Alarm::HIGH_REGISTER, ads7952::reg::NUM_CHANNELS, and ads7952::reg::Alarm::Threshold12To10().
|
noexcept |
Program an alarm threshold for a single channel (voltage-based).
Program an alarm threshold for a single channel (voltage-based).
Converts the voltage to a 12-bit count using the currently active reference voltage, then programs the hardware alarm register.
| channel | Channel number (0–11) |
| bound | Low or High alarm threshold |
| voltage | Threshold voltage in volts (clamped to valid range) |
Converts the voltage to a 12-bit count using the currently active reference voltage, then programs the hardware alarm register.
| channel | Channel number (0–11) |
| bound | Low or High alarm threshold |
| voltage | Threshold voltage in volts (clamped to valid range) |
Definition at line 440 of file ads7952.ipp.
References ads7952::VoltageToCount().
|
noexcept |
Program the Auto-1 channel sequence.
Program the Auto-1 channel sequence.
Bit ordering: bit N enables channel N (bit 0 = CH0, bit 11 = CH11, LSB-first). Only bits [11:0] are used; upper bits are masked off.
Use the ads7952::ChannelMask() helper or predefined constants:
| channel_mask | Bitmask where bit N enables channel N (bits [11:0]) |
Bit ordering: bit N enables channel N (bit 0 = CH0, bit 11 = CH11, LSB-first). Only bits [11:0] are used; upper bits are masked off.
Use the ads7952::ChannelMask() helper or predefined constants:
| channel_mask | Bitmask where bit N enables channel N (bits [11:0]) |
Definition at line 309 of file ads7952.ipp.
References ads7952::reg::Mode::AUTO_1_PROG.
|
noexcept |
Program the Auto-2 last channel.
Program the Auto-2 last channel.
| last_channel | Last channel in sequence (0-11) |
| last_channel | Last channel in sequence (0-11) |
Definition at line 331 of file ads7952.ipp.
References ads7952::reg::Auto2LastChannel(), ads7952::reg::Mode::AUTO_2_PROG, and ads7952::reg::NUM_CHANNELS.
|
noexcept |
Program GPIO pin functions, direction, and alarm routing.
Program GPIO pin functions, direction, and alarm routing.
Configures which GPIO pins act as inputs or outputs, assigns alarm signalling roles to GPIO0/GPIO1, optionally assigns GPIO2/GPIO3 as hardware range/power-down inputs, and optionally resets all device registers. Sends a single GPIO_PROG mode frame.
| config | GPIO configuration structure |
Configures which GPIO pins act as inputs or outputs, assigns alarm signalling roles to GPIO0/GPIO1, optionally assigns GPIO2/GPIO3 as hardware range/power-down inputs, and optionally resets all device registers. Sends a single GPIO_PROG mode frame.
| config | GPIO configuration structure |
Definition at line 349 of file ads7952.ipp.
References ads7952::GPIO, ads7952::reg::GPIOProg::GPIO0_HI_ALARM, ads7952::reg::GPIOProg::GPIO0_HI_LO_ALARM, ads7952::GPIO0_HighAlarm, ads7952::GPIO0_HighAndLowAlarm, ads7952::reg::GPIOProg::GPIO1_LO_ALARM, ads7952::reg::GPIOProg::GPIO1_LO_GPIO0_HI_ALARM, ads7952::GPIO1_LowAlarm, ads7952::GPIO1_LowAlarm_GPIO0_HighAlarm, ads7952::reg::GPIOProg::GPIO2_RANGE_IN, ads7952::reg::GPIOProg::GPIO3_PWRDOWN_IN, ads7952::reg::Mode::GPIO_PROG, and ads7952::reg::GPIOProg::RESET_ALL_REGS.
|
noexcept |
Clock raw 16-bit frames and return every response word unparsed.
Clock raw 16-bit frames and return every response word unparsed.
Frame 0 is a MANUAL select of channel with the driver's range / power / GPIO bits; frames 1..n-1 are CONTINUE. Each returned word is the full DO15:0 (channel address in the top nibble, 12-bit result below), so a bench can see whether the address pipeline advances and whether the data field follows it — the two halves of "every channel
reads the same count". Leaves the device in Manual mode.
| channel | Channel to select in frame 0 (0-11). |
| out | Destination for n response words. |
| n | Number of frames (including the select frame). |
n if a transfer failed part-way.Frame 0 is a MANUAL select of channel with the driver's range / power / GPIO bits; frames 1..n-1 are CONTINUE. Each returned word is the full DO15:0 (channel address in the top nibble, 12-bit result below), so a bench can see whether the address pipeline advances and whether the data field follows it — the two halves of "every channel
reads the same count". Leaves the device in Manual mode.
| channel | Channel to select in frame 0 (0-11). |
| out | Destination for n response words. |
| n | Number of frames (including the select frame). |
n if a transfer failed part-way.Definition at line 520 of file ads7952.ipp.
References ads7952::reg::ChannelSelect(), ads7952::reg::Mode::CONTINUE, ads7952::reg::Mode::MANUAL, ads7952::Manual, ads7952::reg::NUM_CHANNELS, and ads7952::reg::PROGRAM_RETAIN.
|
noexcept |
Read all channels in the current Auto-1 sequence.
Read all channels in the current Auto-1 sequence.
Enters Auto-1 mode with channel counter reset and reads until all programmed channels are received or timeout.
Enters Auto-1 mode with channel counter reset and reads until all programmed channels are received or timeout.
Definition at line 175 of file ads7952.ipp.
References ads7952::Auto1, ads7952::reg::Mode::AUTO_1, ads7952::reg::Mode::CONTINUE, ads7952::ChannelReadings::error, ads7952::reg::Response::GetChannel(), ads7952::reg::Response::GetData(), ads7952::ChannelReadings::MAX_CHANNELS, ads7952::NotInitialized, ads7952::Ok, ads7952::reg::PROGRAM_ENABLE, ADS7952_CFG::READ_ALL_MAX_EXTRA_FRAMES, ads7952::reg::RESET_COUNTER, ads7952::SpiError, and ads7952::Timeout.
|
noexcept |
Read a single ADC channel (switches to Manual mode).
Read a single ADC channel (switches to Manual mode).
| channel | Channel number (0-11) |
| channel | Channel number (0-11) |
Definition at line 117 of file ads7952.ipp.
References ads7952::reg::ChannelSelect(), ads7952::reg::Mode::CONTINUE, ads7952::ReadResult::error, ads7952::reg::Response::GetChannel(), ads7952::reg::Response::GetData(), ads7952::InvalidChannel, ads7952::reg::Mode::MANUAL, ads7952::Manual, ADS7952_CFG::MANUAL_READ_MAX_FRAMES, ads7952::NotInitialized, ads7952::reg::NUM_CHANNELS, ads7952::Ok, ads7952::reg::PROGRAM_RETAIN, ads7952::SpiError, and ads7952::Timeout.
|
noexcept |
Set GPIO output pin levels (for pins configured as outputs).
Set GPIO output pin levels (for pins configured as outputs).
Bit ordering: bit N controls GPIO pin N (bit 0 = GPIO0, bit 3 = GPIO3). 1 = high, 0 = low. Use ads7952::gpio:: constants:
The levels are written with the same two frames as SetRange(): a mode frame with DI11 = 1, then a CONTINUE frame, on whose CS falling edge the chip drives the new levels (SLAS605C 8.1: GPO data is refreshed on the CS falling edge from the SDI data of the previous frame). The pins show the new levels when this returns.
| gpio_state | Bits [3:0] — 1 = high, 0 = low per pin |
Bit ordering: bit N controls GPIO pin N (bit 0 = GPIO0, bit 3 = GPIO3). 1 = high, 0 = low. Use ads7952::gpio:: constants:
The levels are written with the same two frames as SetRange(): a mode frame with DI11 = 1, then a CONTINUE frame, on whose CS falling edge the chip drives the new levels (SLAS605C 8.1: GPO data is refreshed on the CS falling edge from the SDI data of the previous frame). The pins show the new levels when this returns.
| gpio_state | Bits [3:0] — 1 = high, 0 = low per pin |
Definition at line 508 of file ads7952.ipp.
|
noexcept |
Set the power-down mode; in effect on the chip when this returns.
Set the power-down mode; in effect on the chip when this returns.
Same two frames as SetRange(). With DI05 = 1 the chip powers down on the 16th SCLK falling edge of the frame after the one that wrote it (SLAS605C 8.3.2), i.e. at the end of the flush frame. With DI05 = 0 it powers up on the next CS falling edge; the conversion of that frame is the one invalid conversion after power-up (7.6) and is discarded.
| pd | Normal or PowerDown |
Same two frames as SetRange(). With DI05 = 1 the chip powers down on the 16th SCLK falling edge of the frame after the one that wrote it (SLAS605C 8.3.2), i.e. at the end of the flush frame. With DI05 = 0 it powers up on the next CS falling edge; the conversion of that frame is the one invalid conversion after power-up (7.6) and is discarded.
| pd | Normal or PowerDown |
Definition at line 496 of file ads7952.ipp.
References ads7952::reg::POWER_DOWN, ads7952::reg::POWER_NORMAL, and ads7952::PowerDown.
|
noexcept |
Set the input voltage range; in effect on the chip when this returns.
Set the input voltage range; in effect on the chip when this returns.
The chip takes DI06 (range), DI05 (power-down) and DI03:00 (GPIO outputs) only from a mode frame with DI11 = 1 (SLAS605C Tables 1, 2 and 5); a CONTINUE frame ignores DI11:00 (Table 7). The call therefore sends a mode frame for the current mode (Manual: the current channel; Auto-1/Auto-2: no counter reset) with DI11 = 1, then one CONTINUE frame. A range written in frame N applies to the input acquired in frame N+1 (Figure 50), so the extra frame flushes the one conversion still made with the old range: every result clocked out after this returns uses the new range, and the driver's active reference (CountToVoltage(), VoltageToCount()) matches it. In Auto-1 / Auto-2 the two frames advance the channel counter by two.
| range | Vref or TwoVref |
The chip takes DI06 (range), DI05 (power-down) and DI03:00 (GPIO outputs) only from a mode frame with DI11 = 1 (SLAS605C Tables 1, 2 and 5); a CONTINUE frame ignores DI11:00 (Table 7). The call therefore sends a mode frame for the current mode (Manual: the current channel; Auto-1/Auto-2: no counter reset) with DI11 = 1, then one CONTINUE frame. A range written in frame N applies to the input acquired in frame N+1 (Figure 50), so the extra frame flushes the one conversion still made with the old range: every result clocked out after this returns uses the new range, and the driver's active reference (CountToVoltage(), VoltageToCount()) matches it. In Auto-1 / Auto-2 the two frames advance the channel counter by two.
| range | Vref or TwoVref |
Definition at line 485 of file ads7952.ipp.
References ads7952::reg::RANGE_2VREF, ads7952::reg::RANGE_VREF, and ads7952::TwoVref.
|
noexcept |
Update the VA supply voltage value.
Use this for runtime calibration when VA is measured (e.g., via resistor divider on an ADC channel). VA is used for validation and ratiometric sensor calculations.
| va | New VA voltage in volts (clamped to 2.7V–5.25V, ADS7952_CFG::MIN_VA..MAX_VA) |
Definition at line 67 of file ads7952.ipp.
References ADS7952_CFG::MAX_VA, and ADS7952_CFG::MIN_VA.
|
noexcept |
Update the Vref value for voltage calculations.
Use this for runtime calibration when Vref is measured externally. Updates both vref_ and two_vref_ (2×Vref) accordingly.
| vref | New Vref voltage in volts (clamped to 2.0V–3.0V, ADS7952_CFG::MIN_VREF..MAX_VREF) |
Definition at line 59 of file ads7952.ipp.
References ADS7952_CFG::MAX_VREF, ADS7952_CFG::MIN_VREF, and ads7952::TwoVref.
|
noexcept |
Convert a voltage to a 12-bit ADC count using the active reference.
Convert a voltage to a 12-bit ADC count using the active reference.
Instance version — uses the currently active reference voltage (affected by the Range setting). Result is clamped to 0–4095.
| voltage | Target voltage in volts |
Instance version — uses the currently active reference voltage (affected by the Range setting). Result is clamped to 0–4095.
| voltage | Target voltage in volts |
Definition at line 251 of file ads7952.ipp.
References ads7952::reg::MAX_COUNT.