 Hello and welcome to this introduction to microphones. In this video, I am going to cover the details of PDM microphone acquisition using I2S and SPI. Let's start with some details about those peripherals in general. I2S standard is originally used to transmit stereo PCM data. The standard and the bus is composed of three signals. A clock line, which defines the timing of the bit transmission on the bus. A control signal, word select, which is used to determine if the word being sent is the right or the left of the stereo flow. A data line, on which the actual data bits are transmitted synchronously with the clock. For the purpose of PDM microphone acquisition, only two lines are used. The clock line to provide the timing signal to the microphone and the data line to acquire the data. SPI allows synchronous full-duplex communication between a master and several slave devices. The communication is based on four lines. A clock signal generated by the master, which defines the timing of the bit transmission on the bus. A MOSI line carrying data from the master to the slave. A MISO line for data in the opposite direction. And an NSS line used by the master to select the device to communicate with in the scenario of a multislave bus. For the purpose of PDM microphone acquisition, the SPI is used in master mode and only two lines are adopted. The clock line to provide the timing signal to the microphone and the MISO line to read the PDM data. Please note that in STM32, SPI and I2S standards are both implemented within the SPI block peripheral, which can be then configured either in SPI or I2S mode. Let's start with the case in which a single digital microphone is connected to the SPI block. The SPI block can be configured either in SPI or I2S mode. In both cases is configured in master receiver mode. In this way, the peripherals provides the clock to the digital microphone, while the audio samples are acquired through the serial data pin. If the I2S protocol is used, it's recommended to set the left-right pin of the microphone to ground. Since by default the I2S protocol samples the incoming data using the rising edge of the clock. If the SPI protocol is used, the left-right pin of the microphone can be connected either to PDT or to ground. The SPI clock polarity configuration shall be aligned with the configuration of the left-right pin. Data acquired in this way can be converted to the PCM format using the PDM-to-PCM library for STM32. Please note that depending on the peripheral block version, some constraints on the generated clock should be considered. For more information on this aspect, you can refer to the fifth chapter of this video series, STM32 peripherals for MEMS digital microphone. We can also exploit SPI or I2S peripheral to acquire two digital microphones. The two main aspects of the configuration are the microphones are configured with opposite left-right pins and they share a common data line. The SPI peripheral operates at twice the microphone frequency in order to be able to read the data provided by both microphones, which share the same data line. Given a target frequency for the microphones equal to the PDM clock, the SPI block will generate a frequency equal to PDM clock times 2. This clock signal is then given as input to an STM32 timer, which divides it by two to deliver the target PDM clock to the microphones. In this way, the SPI or I2S peripheral working at PDM clock times 2 will be able to read both the right microphone data provided on the rising edge of the PDM clock and the left microphone data on the folding edge. When this kind of stereo-quisition is used, data in the output buffer will be arranged with alternating bits from the two microphones. At this point, we must arrange data as the PDM to PCM software library is expecting it, which is byte-to-byte relived. A software stage of bit interleaving to byte interleaving must be used. Here's how the bits of the first microphone are moved and here is the same for the second microphone. An efficient way to do so by means of bit mask and shift is offered in our examples. Here are some useful references you can find on ST.com. More videos in this video series can be found on the ST Microelectronics YouTube channel.