# Connecting the peripherals

Now that we have initialized the different peripherals that we will use to interface with the outside world (from the point of view of the microcontroller), we are ready to wire everything up! Make sure that the STM32 board is not powered, i.e. unplugged, while connecting the microphone and DAC breakout boards.

For this task, we will have to refer to the card provided with the STM32 board (see below) and the image of the chip on the "Pinout" tab of our CubeMX project (further below).

![](https://1958907383-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lu3g0bb8nPq-K9HlS53%2F-LyEeE-FCneQbFkG3CPY%2F-LyEeGpdpq5qXIazvL8I%2Fstm32f072_extensions.png?generation=1578663247711644\&alt=media)

![](https://1958907383-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lu3g0bb8nPq-K9HlS53%2F-LyEeE-FCneQbFkG3CPY%2F-LyEeGpf4nQbgpMPKCOP%2Fpinout_tab.png?generation=1578663252941043\&alt=media)

## Adafruit I2S MEMS Microphone Breakout <a href="#microphone" id="microphone"></a>

*As previously mentioned, make sure that the STM32 board is powered off!* We can then begin by connecting the microphone's ground pin. In electronics, it is common practice to first ground a component/circuit.

{% hint style="info" %}
TASK 3: Connect the microphone's **GND** pin to one of the STM32 board's **GND** pins, e.g. slot 22 on the **CN7** (left) header.

*Tip: try to keep all the connector cables attached to each other to avoid messy wiring!*
{% endhint %}

We can now connect the supply voltage pin.

{% hint style="info" %}
TASK 4: Connect the microphone's **3V** pin to the STM32 board's **3V3** pin.

*Note: the microphone component accepts voltage levels between 1.6V and 3.6V so **do not** use the STM32 board's **5V** pin!*
{% endhint %}

Previously, we configured I2S2 for the microphone so we will have to connect the following pins (see image of chip from "Pinout" tab for the names on the left side of the arrow) to the corresponding pins on the microphone breakout board (right side of the arrow):

* **I2S2\_SD** $$\leftarrow$$ **DOUT**
* **I2S2\_CK** $$\rightarrow$$ **BCLK**
* **I2S2\_WS** $$\rightarrow$$ **LRCL**

{% hint style="info" %}
TASK 5: From the "Pinout" configuration on CubeMX, determine which pins of the STM32 board are used by I2S2. Using the card provided with the board (see PDF figure above), use the jumper cables to wire the pins from the STM32 board to the appropriate pins on the microphone breakout board.

*Hint: for example, from the "Pinout" tab we can see that **I2S2\_SD** is output on pin **PC3**. From the card provided with the board, we see **PC3** is located in the bottom left corner of the board's pin header extensions. Therefore, we will use a wire to connect this pin to the **DOUT** pin of the microphone breakout board.*
{% endhint %}

Finally, we configured an additional GPIO pin in order to select whether we would like the microphone to be assigned to the left or right channel.

{% hint style="info" %}
TASK 6: Connect the microphone's **SEL** pin to the pin on the STM32 board corresponding to **LR\_SEL**.

BONUS: do we have to connect the microphone's **SEL** pin for the passthrough to work? What would happen if we didn't?
{% endhint %}

## Adafruit I2S Stereo Decoder <a href="#dac" id="dac"></a>

*As previously mentioned, make sure that the STM32 board is powered off!* We can then begin by connecting the DAC's power supply, starting with the ground pin.

{% hint style="info" %}
TASK 7: Connect the DAC's **GND** and **VIN** pins to the STM32 board.

*Note: you can provide 5V to the **VIN** pin and the built-in regulator will produce a 3.3V supply, which is also available on the **3VO** pin.*
{% endhint %}

Previously, we configured I2S1 for the DAC so we will have to connect the following pins to the appropriate pins on the DAC breakout board:

* **I2S1\_SD**
* **I2S1\_CK**
* **I2S1\_WS**

Moreover, we configured an additional GPIO pin in order to mute the output.

* **MUTE**

{% hint style="info" %}
TASK 8: Connect the above four pins from the STM32 board to the appropriate pins on the DAC breakout board.

*Hint: see the* [*DAC chip explanation*](https://hwlab.learndsp.org/audio-peripherals/dac) *and* [*Adafruit's site*](https://learn.adafruit.com/adafruit-i2s-stereo-decoder-uda1334a/pinouts) *for more information on wiring the DAC component.*
{% endhint %}

With everything correctly wired up, we can proceed to [coding](https://hwlab.learndsp.org/audio-peripherals/passthrough/coding) the passthrough on the SW4STM32 software!

## Tasks solutions

Sadly we cannot connect all the wires for you or double check your connections. However we did our best to help you with this wiring by making a step-by-step video accessible at this [address](https://www.coursera.org/learn/dsp4/supplement/efBGc/introduction).

{% tabs %}
{% tab title="Anti-spoiler tab" %}
Are you sure you are ready to see the solution? ;)
{% endtab %}

{% tab title="Task 6" %}
Indeed we have to connect the SEL pin of the microphone, otherwise the microphone might send it's signal randomly on the left or right channel (however it is common practice that these type of input pins have pull-down or pull-up resistors in order to have a *by default* state).
{% endtab %}
{% endtabs %}
