I2S amplifier/Three wires and a switch/03. Three wires, one channel
Three wires and a switch · 03 of 9

Three wires, one channel

I2S carries sound on three wires: BCLK ticks once per bit, DIN carries the bits, and LRCLK says whether they belong to the left sample or the right. The NS4168 is mono, so it plays one of the two and ignores the other, which is why every sketch here writes the same sample into both.

Three wires

  • BCLK, the bit clock, ticks once for every bit. The ESP32-S3 makes it.
  • DIN carries the bits, one per BCLK tick, most significant first. Each sample is a signed 16-bit number.
  • LRCLK is LOW while a left sample goes by and HIGH while a right one does. It changes once per sample, so at 16 kHz it runs at 16 kHz.

The chip is always the listener: all three are inputs on the TK100, and all three clocks come from the ESP32-S3. A wrong pin does no harm; it just makes no sound.

Every frame has two samples

Two samples go by, one is played
plays the right
The sketch writes
The chip plays
Bits per frame
32
BCLK at 16 kHz
512 kHz
The chip hears
6000
Plays either way. With the same number in both halves it does not matter which one the chip picks. That is why every sketch in this book writes each sample twice.

One frame is a left sample and a right sample: 32 bits at 16-bit stereo, so at 16 kHz the bit clock runs at 16000 × 32 = 512 kHz, worked out. The NS4168 takes any rate from 8 to 96 kHz and a bit clock of 16, 24, 32, 48 or 64 ticks per frame, so 16-bit stereo fits.

A mono chip picks one

The NS4168 has one output, so it plays one half of each frame and throws the other away. As shipped it plays the right half; bridging the L/R jumper makes it play the left.

That choice can silence a sketch that did everything else right. A program that puts sound in the left half and zeros in the right is silent on a TK100 as shipped. So the sketches in this book write each sample twice:

frame[0] = frame[1] = clip[i];      // same sample, both channels

Then it does not matter which half the chip takes.

Stereo from two boards

A stereo song on one TK100 plays one channel only, the right as shipped. Two TK100s on the same three wires make stereo: bridge the jumper on one so it plays the left, and give each its own speaker. Each still needs CTRL driven HIGH.

When it does not work

My sketch plays silence but the ESP32 says it is playing.

If CTRL is HIGH, check which channel the sound is in. A sketch that fills only the left sample and leaves the right at 0 is silent on a TK100 as shipped, which plays the right. Write every sample into both.

I swapped BCLK and LRCLK by mistake.

Nothing is damaged: all three pins are inputs on the TK100. The chip cannot find its frames, and you hear nothing or noise. Put BCLK on GPIO 15 and LRCLK on GPIO 16, as the sketch names them.

What sample rate can I use?

The NS4168 takes 8 to 96 kHz. The book's sketches use 16 kHz, which is plenty for speech and simple tones. An MP3 is usually 44.1 kHz, which is also fine.

Does it take 24-bit or 32-bit samples?

It locks to a bit clock of 16, 24, 32, 48 or 64 ticks per frame. The sketches send 16-bit stereo, which is 32 ticks per frame, and that is the simplest thing to get right.

Alongside this page
Where this goes next

The fourth wire, and the jumper that chooses the channel.

CTRL: on, off, left or right

Edit this page — content/books/i2s-amplifier/three-wires-one-channel.mdx

Community

Questions about this product

See what other owners have asked, and read their solutions.

Ask a question ↗

I2S Amplifier

Loading discussions…

Discuss this article

Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.

Browse Modules and blocks on the forum