MAX98357A I2S amplifier
The MAX98357A breakout: samples in over I2S and up to 3 W out to a speaker, with no DAC in between. Aliases: I2S amp, MAX98357, class D amplifier.
The board is the I2S master. It drives BCLK and LRC and sends the samples on
DIN; the chip plays them into a speaker on its terminal. It takes 16, 24 or 32 bits
a sample (32, 48 or 64 clocks a frame) at 8 to 96 kHz, and needs no MCLK.
Pins
| Pin | What it does |
|---|---|
LRC |
Word select, the frame clock, from the board. Low left, high right. |
BCLK |
The bit clock, from the board. |
DIN |
The samples, from the board. |
GAIN |
Picks the gain by what it is tied to (below). Open is 9 dB. |
SD |
Shutdown and channel select, by its voltage (below). |
GND |
Ground. |
VIN |
Supply, 2.5 V to 5.5 V. |
SPK+, SPK- |
The speaker, 4 ohms or more. Neither side is ground. |
SD and GAIN
SD under 0.16 V shuts the amp down; 0.16 to 0.77 V plays (left + right) / 2; 0.77 to
1.4 V the right channel; over 1.4 V the left. The breakout has a 1 M pull-up to VIN
against the chip's 100 k pull-down, so left open it sits at 0.45 V on 5 V and plays
the mix. Wired to a pin, HIGH plays the left channel and LOW shuts it down.
GAIN: 15 dB through 100 k to GND, 12 dB to GND, 9 dB open, 6 dB to VIN, 3 dB
through 100 k to VIN. The chip reads it as it powers up, so a change takes effect
after the supply goes off and on, as on the real board.
While it runs
The board prints the gain it read and the channel SD picks, and a bar shows how loud
it is playing. A speaker wired to SPK+ and SPK- shows the note it hears.
What the model gets right
The level. The gain is referred to 2.1 dBV: a full-scale sample is
sqrt(2) x 10^((2.1 + gain) / 20) volts peak across the speaker, 5.1 V at 9 dB,
clipped at the supply.
The frame. Samples are read most significant bit first, one clock after LRC
changes, on the rising edge of BCLK. A frame rate outside 8 to 96 kHz, or a frame
that is not 32, 48 or 64 clocks, plays nothing.
The bridge. Both speaker pins sit at half of VIN and move apart by the sample's
voltage. With no frames for 2 ms they return to the middle; shut down, they let go.
What it does not model
The real outputs are a 300 kHz PWM that the speaker coil averages; Mokxi drives that average, updated once a frame. The chip's filters, click and pop suppression, TDM and left-justified modes, and its thermal limits are not modeled. No sound comes out of the page: the speaker shows the note.
Libraries
On the ESP32 boards, the ESP-IDF driver (driver/i2s.h: i2s_write), Arduino-ESP32
3.x's ESP_I2S.h (I2SClass) and 2.x's I2S.h. Mokxi bit-bangs the I2S bus on the
pins you set, at the sample rate you ask for, while the sketch is writing.
Common mistakes
Wiring one speaker pin to ground. It is a bridge output: both pins move.
Changing GAIN while it runs and expecting a change. Power it off and on.
Stopping writes. The amp goes quiet 2 ms after the last frame; keep i2s_write fed.
See it in action
ESP32 I2S sine player plays a 440 Hz sine into a speaker. Open it at /templates.