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

Pin Mapping & Peripheral Config

GPIO assignments, DMA channels, and peripheral settings.

Pin Mapping

PinFunctionPeripheralDescription
PA0ADC+ADC1_IN1Gas sensor positive (differential)
PA1ADC−ADC1_IN2Gas sensor negative
PA2DAC MSBGPIO OutputAD5545 midscale/zero-scale select
PA3DAC RSGPIO OutputAD5545 reset (active low)
PA4DAC LDACGPIO OutputAD5545 latch (pulse low to update)
PA5SPI SCKSPI1DAC clock
PA6SPI CSGPIO OutputDAC chip select (active low)
PA7SPI MOSISPI1DAC data
PA8LEDGPIO OutputHeartbeat (500 ms toggle)
PA9UART TXUSART1Host → sensor commands
PA10UART RXUSART1Sensor → host responses
PB7I2C SDAI2C1SHT45 temperature/humidity sensor
PB8I2C SCLI2C1SHT45 clock

Clock Tree

HSI (16 MHz)
  → PREDIV ÷4  →  4 MHz
  → PLL ×85    →  340 MHz
  → DIVR ÷2    →  SYSCLK = 170 MHz

                      ├── APB1 = 42.5 MHz  (I2C1, USART1)
                      └── APB2 = 85 MHz    (SPI1, ADC1)

Peripheral Configuration

ADC1 — Gas Sensor Input

ParameterValue
ModeDifferential (PA0⁺ / PA1⁻)
Resolution12-bit (0 – 4095 codes)
Sample time6.5 cycles
Oversampling8× hardware (ratio=3, shift=4)
Clock sourceSYSCLK (170 MHz via Adcsel::SYS)
VREFINT cal.On boot — actual VDD calculated

With 8× hardware oversampling the noise floor is effectively reduced by ~√8 ≈ 2.8, giving an effective resolution of ~13.5 bits. The hardware right-shifts the result back to 12-bit output, so ADC_MAX_CODE = 4095.

SPI1 — AD5545 DAC

ParameterValue
Frequency5 MHz
ModeMode 0 (CPOL=0, CPHA=0)
Data orderMSB first
DirectionTX only
Bus sharingRTIC ArbiterDevice

USART1 — Host Communication

ParameterValue
Baud rate115200
Format8N1
DMACH1 RX, CH2 TX

I2C1 — SHT45 Sensor

ParameterValue
Frequency100 kHz
Address0x44 (SHT45)
DMACH4 RX, CH6 TX

DMA Channel Assignments

ChannelPeripheralDirection
DMA1_CH1USART1 RXPeripheral → RAM
DMA1_CH2USART1 TXRAM → Peripheral
DMA1_CH3SPI1 TXRAM → Peripheral
DMA1_CH4I2C1 RXPeripheral → RAM
DMA1_CH5ADC1(Allocated, unused)
DMA1_CH6I2C1 TXRAM → Peripheral

Last updated: February 2026