> Complete documentation index: [llms.txt](/llms.txt). Markdown versions of all pages are available by appending `.md` to page URLs.

# SPI

> Use the SPI command panel in Mission Control 2: set and measure the bus voltage, configure the SPI settings and run transfers.

:::caution
**Mission Control 2: legacy, for the Binho Nova.** For the Binho Supernova, the Binho Pulsar and the Binho Atira, use [Mission Control 3](/software/legacy/mission-control-2/).

:::

SPI, short for _Serial Peripheral Interface_, is a widely-used communication protocol in the realm of electronics. Binho Mission Control optimizes the user's interaction with the SPI protocol, presenting an intuitive approach to its functionalities. When the SPI communication protocol is selected and activated, the Command Panel gets segmented into three distinct sections, each dedicated to a specific facet of the SPI communication: settings, chip selection, and transaction execution.

<figure><img src="/files/SPI_panel%20(1).png" alt="" width="563"><figcaption><p>SPI command panel for Supernova and Pulsar</p></figcaption></figure>

The Bus Voltage section allows the user to initialize and set the bus voltage. Additionally, in the case of Supernova and Pulsar, users can measure the bus voltage and choose to use an external power source. Using an external source is equivalent to measuring the voltage and setting it to match the external supply.

## Settings

<figure><img src="/files/image%20(13).png" alt=""><figcaption><p>Operation Settings for Nova</p></figcaption></figure>

The Settings segment allows users to adjust the following parameters:

<table><thead><tr><th width="156">Parameter</th><th width="142">Nova values</th><th width="248">Supernova and Pulsar values</th><th>Comment</th></tr></thead><tbody><tr><td><strong>Clock Freq</strong> </td><td>0.8 to 12 MHz</td><td>10 kHz to 50 MHz</td><td>Discrete values.</td></tr><tr><td><strong>Bit Order</strong></td><td>MSB, LSB.</td><td>MSB, LSB.</td><td>Most/Least Significant Bit first.</td></tr><tr><td><strong>Bits / Transfer</strong></td><td>8, 16.</td><td>-</td><td>Bits per transfer.</td></tr><tr><td><strong>Mode</strong></td><td>0, 1, 2, 3.</td><td>0, 1, 2, 3.</td><td>(CPOL, CPHA) ∈ {(0,0); (0,1); (1,0); (1,1)}</td></tr></tbody></table>

CPOL and CPHA refer to the clock's polarity and phase. In tandem, they designate the precise timing and edge (be it rising or falling) at which data is sampled.

## Chip Selection

<figure><img src="/files/image%20(15).png" alt=""><figcaption><p>Chip Select for Nova</p></figcaption></figure>

<table><thead><tr><th width="207">Parameter</th><th width="177">Admited values</th><th>Comment</th></tr></thead><tbody><tr><td>Pin Select</td><td>CS0, CS1.</td><td>CS = Chip Select</td></tr><tr><td>Polarity</td><td>Low, High.</td><td>Active Low/High polarity for CS.</td></tr><tr><td>Pre-Delay</td><td><em>Numeric</em></td><td>Only positive integer numbers. Unit: μs.</td></tr><tr><td>Post-Delay</td><td><em>Numeric</em></td><td>Only positive integer numbers. Unit: μs.</td></tr></tbody></table>

Pre/Post Delays pertain to the time gap between the inactive-to-active transition of the CS (Chip Select) signal and the sampling of the initial payload bit.

## Transactions

<figure><img src="/files/SPI_transactions.png" alt="" width="563"><figcaption><p>Transactions sub-panel.</p></figcaption></figure>

This segment comprises two text fields and a dedicated TRANSFER button, simplifying SPI transaction processes.

1. **Write Buffer**: Enter the data payload for the target device in hexadecimal, grouped in byte packets. For instance, inputs like '00' or 'FF' (contingent on the chosen polarity) symbolize a read-only operation.
2. **Read Size**: This field allows users to determine the quantity of bytes they wish to retrieve from the target device. Initiating an SPI transaction is as simple as hitting the TRANSFER button.

## Real-world Examples

Outlined below are hands-on tests with tangible devices, offering a glimpse into the SPI protocol in action.

**Flash memory test with a Winbond W25Q128FV**: the datasheet defines an instruction that returns the JEDEC manufacturer ID, memory type and capacity together. Send the byte '0x9F' to the flash to run it. Winbond's manufacturer ID is '0xEF'. The part accepts clocks up to 50 MHz and SPI modes 0 and 2, and this test ran at 12 MHz in mode 0. The JEDEC ID returned was the expected one.

<figure><img src="/files/image%20(10).png" alt=""><figcaption><p>Write operation to a SPI flash memory</p></figcaption></figure>

**Pressure Sensor Test with BMP280**: This example delves deeper, showcasing the capabilities of the SPI protocol using the BMP280 pressure sensor.

<figure><img src="/files/image%20(12).png" alt=""><figcaption></figcaption></figure>