I treated myself to some hands-free probes and dug into the PDM mic on my ESP32 board. I was confused that the new I2S PDM API only asks for clock and data—no LRCLK—yet the mic datasheet shows an LR/SEL pin. The trick: in PDM, LR is just a static select. Tie it low and data is valid on the rising edge; tie it high and it’s valid on the falling edge, so two mics can share the same I2S lines by picking opposite polarities. I proved it on the scope and realized I don’t need to burn a GPIO on LR at all—just hard-wire it high or low and save a pin.
So, I decided to treat myself to a
couple of these hands-free probes. These
came from PCB or PC Bite, I think that’s
how you pronounce that. Not a sponsor of
the channel, which is a shame cuz these
were quite expensive. But talking of
sponsors of the channel, PCB Way is a
sponsor of the channel and we’re looking
again at one of their PCBs. So, one of
the things that I wanted to look at is
the microphone on this board and how it
works. So, I was slightly intrigued when
I looked at some code. So, what is it
that got me confused with the code?
Well, here’s the setup for the I squared
S PDM device. And I’m using the new API
for doing this on the ESP32. So, we have
our channel config and we set that up.
And then we have the actual
configuration which has the GPIO pins.
Now, if you look at this, we have the
clock pin and we have the data pin. What
we don’t have is the LR pin. Now if we
look at the actual schematic there is a
clock there’s a MC LR and there’s a data
and if we look at the data sheet these
are definitely the pins there is an LR
channel pin now if we go back to a very
old video back in the day when I was
looking at microphones and audio these
are the signals for a PCM microphone so
we have the serial clock you have the
word select or the LR clock this goes
high and low if it’s high then you want
the left or the right channel. So the LR
clock or the WS clock selects which
channel you’re getting and this lets you
connect two microphones to the same I
squareds line. So this goes through and
you get the serial data coming left and
right channel. But there’s no LR clock
on this PDM setup. So how on earth does
that work? And we can confirm that if we
go to the actual definition of this.
Then you can see here that the RX GPIO
config has a clock and it has some data
in pins. There is no LR clock. So you
can see my confusion here. I put a
comment in saying, “What on earth’s
going on? Where is the LR clock pin? Is
it no longer relevant? Do we tie it high
or low? How do you put two microphones
onto the same I squared S device? We
want stereo microphones. How does that
work?” So I put something on the forums
and then someone sent me straight back
to the data sheet. And if we scroll up,
it all becomes very clear. So you can
see here the IO timing diagram. We have
our clock and then we have the value for
data for the selection pin. So if you
tie the LR selection pin to VDD, then
the data is valid on the downward
transition of the clock and then it’s
high Z. If you connect the selection to
ground, then the data is valid on the up
transition of the clock and it’s high Z
otherwise. So that’s how you connect two
PDM microphones to the same I squared S
peripheral. You tie the selection pin
high for one and low for the other. So
let’s go to the oscilloscope and use our
new probes to actually test this. So
I’ve got the board set up so that we can
change the polarity of the LR pin using
the boot button. So currently we’ve got
a blue LED and that means the LR pin is
held low. So if we look at the
oscilloscope here, just run that. Then
what you can see is when the clock is
high, actually let’s do a single
capture.
What you can see is when the clock is
high, the value starts to be pulled
down. So what I’ve done is I’ve
connected the data pin to a pin on the
ESP32 with a pull down resistor. So when
the um when the microphone data goes
high impedance, it starts to pull the
value down. You can see on the positive
edge of the clock, it starts to get
pulled down. So our data is valid when
the clock is low. So what I’m going to
do is I’m going to click the boot
button. Now the LEDs turned green. That
means the LR pin is high. So if we start
the scope running again,
I’ll do another single capture. And now
you can see that our value starts to be
pulled down when the clock is low. So
that matches up with the data sheet.
Obviously, if you had two microphones,
one with the LR pin held high and one
with the LR pin held low, they basically
interled the values and it would work
nicely. So you’d have stereo microphones
on one I squareds device. So very
different from the PCM microphones, but
um pretty interesting. So, it’s all very
interesting, but is it really important?
Well, one of the big learnings is we
don’t actually need to connect this LR
pin up to a GPIO pin. So, currently I
have my MC LR connected up to this GPIO
here. Now, I could have got away with
not connecting it at all. I could have
just tied it low or high, depending on
which side I wanted it to be on, left or
right. So, I could have saved a pin.
I’ll do that next