# Host SPI Configuration

This section describes the SPI parameter requirements for Qwantum ASIC. The SPI interface in the microcontroller should be configured properly to communicate with the ASIC.

* Mode of Operation (Master/Slave)
* Clock Polarity – the inactive state of the Serial Communications Clock (SCLK).
* Clock Phase – which edge of SCLK causes data to change and which edge causes data to be captured.
* Frame Size (8-bit or 16-bit) – the number of bits transferred per frame.
* Byte Transfer Order – specifies whether the LSB or MSB of the frame should be transferred first.
* SPI Serial Clock.
* Baud rate.
* Interrupt between SPI controller and Peripheral.&#x20;
* SPI Peripheral Chip Select

## Mode of Operation <a href="#bookmark4" id="bookmark4"></a>

The Qwantum ASIC has two ways of communicating with a host microcontroller: Data Strobe mode and SPI mode. Two GPIO pins can be used for the data strobe mode. For the Qwantum SPI mode, the SPI module in microcontroller should be initialized and configured to operate as an SPI master.

The operation mode to be used is selected by hardware (the voltage on the MODE pin). When the MODE pin is tied to VDD voltage, the ASIC becomes an SPI slave and communicates via the SPI slave communication interface. When the MODE pin is tied to ground, the ASIC operates in the data strobe mode and communicates via two GPIO pins. The MODE pin is not intended to toggle while the ASIC is operating.

## Clock Polarity and Clock Phase <a href="#bookmark5" id="bookmark5"></a>

SPI is a synchronous communication protocol clocked by SCLK which is driven by the SPI master. Qwantum ASIC requires SCLK to be idle low. So, the master should be configured to be inactive when SCLK is low.

Clock Phase indicates which edge of SCLK causes data to change and which edge causes data to be captured. Qwantum ASIC requires data to be changed on the rising edge of clock and sampled on the negative edge of clock. This corresponds to the common labeling of CKPOL=0 and CKPHA=1.

## Frame Size (SPI Character/Word Length) <a href="#bookmark6" id="bookmark6"></a>

The size of a data packet for Qwantum ASIC is 16-bit. Thus, the frame size of the SPI master should be configured for 16-bit.

## Byte Transfer Order <a href="#bookmark7" id="bookmark7"></a>

Qwantum ASIC transfers MSB of data first. Thus, the SPI master should be configured to support the MSB transfer first during the data transfer. If the SPI master doesn’t support the MSB transfer first option, firmware may need to swap bytes after receiving it from the ASIC.

## SPI Serial Clock and Baud Rate <a href="#bookmark8" id="bookmark8"></a>

The microcontroller master clock and SPI module clock should be enabled. The way the SPI baud rate is computed is different for different microcontroller manufacturers and models.

## Interrupt <a href="#bookmark9" id="bookmark9"></a>

Qwantum ASIC can operate with or without interrupt in SPI mode. When the ASIC uses interrupt, it can generate two separate interrupts in sequence, Card Present Interrupt followed by Card Data Available Interrupt, or Card Data Available Interrupt only depending upon how the ASIC is configured in firmware. The microcontroller and the ASIC (IRQ\_DIS bit in *Configuration Register (address = 0x00)*) should be configured properly to use the interrupt feature of the ASIC.

## SPI Peripheral Chip Select <a href="#bookmark10" id="bookmark10"></a>

The SSELn pin on Qwantum ASIC should be connected to the SPI chip select pin on the microcontroller. The ASIC should be selected only when the microcontroller firmware needs to communicate with the ASIC and released after it finishes reading or writing the ASIC registers.

## SPI Interface Functions <a href="#bookmark11" id="bookmark11"></a>

This section provides examples of common functions required for the microcontroller SPI interface. Each function depends on driver APIs available in the microcontroller firmware.

The examples can be found in the reference code: spi\_app.c and spi\_hal.c.

## Initialization/Configuration of SPI Interface <a href="#bookmark12" id="bookmark12"></a>

This function should configure the SPI related pins and SPI interface parameters in the microcontroller described in Section 2.1 \~ 2.7. The Qwantum ASIC initialization and the microcontroller interrupt enable routine, if interrupt is used, should be invoked in this function.

#### SPI Data Receive

This function reads 16-bit data from an SPI slave device.

#### SPI Data Transmit

This function writes 16-bit data to an SPI slave device.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developer.magtek.com/qwantum-services/qwantum-asic/draft-versions/draft-of-msr-chip-spi-firmware-implementation-guide/host-spi-configuration.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
