H₂S Gas Sensor
STM32G431KB · Firmware v0.1.0
Hardware

AD5545 DAC

16-bit multiplying DAC — signal conditioning for gain and offset.

Overview

The AD5545 is a 16-bit dual-channel multiplying DAC used to condition the TIA output before it reaches the ADC. It serves two roles:

ChannelRoleDefaultEffect
ChAGain control100%Scales TIA feedback resistance → sensor sensitivity
ChBOffset cancelSet at ZERO calSubtracts sensor baseline in clean air

SPI Frame Format

Byte 0: [ 0  0  0  0  0  A1  A0 ]   — Channel address (ChA=01, ChB=10)
Byte 1: [ D15 D14 D13 D12 D11 D10 D9 D8 ]
Byte 2: [ D7  D6  D5  D4  D3  D2  D1 D0 ]

3 bytes per write, MSB first. CS is held low for the entire transaction. After writing one or both channels, LDAC is pulsed low for ≥1 µs to latch the new value.

Control Pins

PinFunctionIdle StateDescription
CSActive-low chip selectHighMust be held low during SPI frame
LDACLatchHighPulse low (≥1 µs) to update DAC register
MSBReset modeHighHigh = mid-scale (32768), Low = zero-scale (0)
RSResetHighPulse low (≥10 µs) to reset both channels

Percent-to-Code Conversion

// bsp/src/hardware/ad5545.rs
pub fn percent_to_code(percent: f32) -> u16 {
    let pct = percent.clamp(0.0, 100.0);
    (pct * 65535.0 / 100.0 + 0.5) as u16
}
%CodeVoltage (relative)
0%00 V
50%32768½ × VREF
100%65535VREF

DAC Behaviour During Calibration

EventChAChBLDAC pulse
Power-on100%0%Yes
ZERO cmdUnchangedComputed offset %Yes (via bias_task)
SPAN cmdGain %UnchangedYes

Troubleshooting Notes

A previous issue arose from using ExclusiveDevice (wrong SPI timing) instead of ArbiterDevice. The AD5545 requires adequate CS settling — ArbiterDevice with an explicit embassy_time::Delay provides this. See docs/hardware/dac-troubleshooting.md in the firmware repo.

Last updated: February 2026