<spanclass="line"><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;">#define</span><spanstyle="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> SPI_SELECT_MODE</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> SPI_SELECT_MODE_PAD</span></span></code></pre></div><p>Then, modify your board's <code>mcuconf.h</code> to enable the peripheral you've chosen, for example:</p><divclass="language-c vp-adaptive-theme"><buttontitle="Copy Code"class="copy"></button><spanclass="lang">c</span><preclass="shiki shiki-themes github-light github-dark vp-code"><code><spanclass="line"><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;">#undef</span><spanstyle="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> STM32_SPI_USE_SPI2</span></span>
<spanclass="line"><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;">#define</span><spanstyle="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> STM32_SPI_USE_SPI2</span><spanstyle="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> TRUE</span></span></code></pre></div><p>Configuration-wise, you'll need to set up the peripheral as per your MCU's datasheet -- the defaults match the pins for a Proton-C, i.e. STM32F303.</p><table><thead><tr><th><code>config.h</code> Override</th><th>Description</th><th>Default</th></tr></thead><tbody><tr><td><code>SPI_DRIVER</code></td><td>SPI peripheral to use - SPI1 -><code>SPID1</code>, SPI2 -><code>SPID2</code> etc.</td><td><code>SPID2</code></td></tr><tr><td><code>SPI_SCK_PIN</code></td><td>The pin to use for SCK</td><td><code>B13</code></td></tr><tr><td><code>SPI_SCK_PAL_MODE</code></td><td>The alternate function mode for SCK</td><td><code>5</code></td></tr><tr><td><code>SPI_MOSI_PIN</code></td><td>The pin to use for MOSI</td><td><code>B15</code></td></tr><tr><td><code>SPI_MOSI_PAL_MODE</code></td><td>The alternate function mode for MOSI</td><td><code>5</code></td></tr><tr><td><code>SPI_MISO_PIN</code></td><td>The pin to use for MISO</td><td><code>B14</code></td></tr><tr><td><code>SPI_MISO_PAL_MODE</code></td><td>The alternate function mode for MISO</td><td><code>5</code></td></tr></tbody></table><p>As per the AVR configuration, you may choose any other standard GPIO as a slave select pin, which should be supplied to <code>spi_start()</code>.</p><p>If a complete SPI interface is not required, then the following can be done to disable certain SPI pins, so they don't occupy a GPIO unnecessarily:</p><ul><li>in <code>config.h</code>: <code>#define SPI_MISO_PIN NO_PIN</code></li><li>in <code>config.h</code>: <code>#define SPI_MOSI_PIN NO_PIN</code></li><li>in <code>mcuconf.h</code>: <code>#define SPI_SELECT_MODE SPI_SELECT_MODE_NONE</code>, in this case the <code>slavePin</code> argument passed to <code>spi_start()</code> may be <code>NO_PIN</code> if the slave select pin is not used.</li></ul><h2id="api"tabindex="-1">API <aclass="header-anchor"href="#api"aria-label="Permalink to "API {#api}""></a></h2><h3id="api-spi-init"tabindex="-1"><code>void spi_init(void)</code><aclass="header-anchor"href="#api-spi-init"aria-label="Permalink to "`void spi_init(void)` {#api-spi-init}""></a></h3><p>Initialize the SPI driver. This function must be called only once, before any of the below functions can be called.</p><hr><h3id="api-spi-start"tabindex="-1"><code>bool spi_start(pin_t slavePin, bool lsbFirst, uint8_t mode, uint16_t divisor)</code><aclass="header-anchor"href="#api-spi-start"aria-label="Permalink to "`bool spi_start(pin_t slavePin, bool lsbFirst, uint8_t mode, uint16_t divisor)` {#api-spi-start}""></a></h3><p>Start an SPI transaction.</p><h4id="api-spi-start-arguments"tabindex="-1">Arguments <aclass="header-anchor"href="#api-spi-start-arguments"aria-label="Permalink to "Arguments {#api-spi-start-arguments}""></a></h4><ul><li><p><code>pin_t slavePin</code><br> The QMK pin to assert as the slave select pin, eg. <code>B4</code>.</p></li><li><p><code>bool lsbFirst</code><br> Determines the endianness of the transmission. If <code>true</code>, the least significant bit of each byte is sent first.</p></li><li><p><code>uint8_t mode</code><br> The SPI mode to use:</p><table><thead><tr><th>Mode</th><th>Clock Polarity</th><th>Clock Phase</th></tr></thead><tbody><tr><td><code>0</code></td><td>Leading edge rising</td><td>Sample on leading edge</td></tr><tr><td><code>1</code></td><td>Leading edge rising</td><td>Sample on trailing edge</td></tr><tr><td><code>2</code></td><td>Leading edge falling</td><td>Sample on leading edge</td></tr><tr><td><code>3</code></td><td>Leading edge falling</td><td>Sample on trailing edge</td></tr></tbody></table></li><li><p><code>uint16_t divisor</code><br> The SPI clock divisor, will be rounded up to the nearest power of two. This number can be calculated by dividing the MCU's