Documentation Home Page ◇ RT-LAB Home Page
Pour la documentation en FRANÇAIS, utilisez l'outil de traduction de votre navigateur Chrome, Edge ou Safari. Voir un exemple.
Aardvark SPI
Block
Mask
Description
This document describes the Total Phase Aardvark SPI Controller block, which allows an external SPI device — either a master or a slave — to read data from the model or write data to the model. Usage of this block requires a Total Phase Aardvark I2C/SPI USB host adapter to be connected to a USB port of the target.
The block can operate as a master or as a slave. As described below, the master mode has additional configuration parameters.
The communication is handled by an asynchronous process that is responsible for the data exchange between the external device and the model. This asynchronous process is an independent executable that is transferred to the target and launched during model initialization. Although this asynchronous process code should cover most typical SPI read/write operations, it is the user's responsibility to adapt it according to the application requirements. The process sources are transferred to the target during model compilation, as explained in the File transfer section.
For more information on the Aardvark adapter or on SPI communication, refer to the Aardvark I2C/SPI Host Adapter User Manual.
Parameters
General Parameters
#Parameter | Description |
|---|---|
Controller ID | Unique integer identifying this block. It must differ from the ID of any other asynchronous block used in the same model. |
Serial number (10-digit) | The 10-digit integer serial number of the Aardvark adapter to control (for example |
SPI mode | Specifies the block operation mode (Master or Slave). |
Number of bytes to transmit/receive | Number of bytes exchanged per SPI transaction. It must match the number of signals connected to the data input and output ports of the block. |
SPI bitrate (kHz) | SPI bus speed in kilohertz, applied during master transactions only (it does not need to be set for slave operation). This directly affects the SCLK frequency. Supported range: 1–8000 kHz (values below 125 kHz are rounded up to 125 kHz by the adapter). |
Clock polarity | Selects the idle state of SCLK: Idle low (CPOL = 0) or Idle high (CPOL = 1). |
Clock phase | Selects the sampling edge: Sample value on rising edge (CPHA = 0) or Sample value on falling edge (CPHA = 1). |
Clock endianness | Selects the bit order: MSB first or LSB first. |
Slave select polarity | Selects the active level of the Slave-Select (SS) line: SS active low or SS active high. This affects master mode only; in slave mode SS is always active low. |
Enable power pins | When checked, the Aardvark adapter supplies power to the downstream device through its power pins (pins 4 and 6, up to 25 mA each). Requires hardware version 2.00 or greater. |
Delay between buffer transmissions (ms) | Pause inserted between consecutive SPI transactions. It can be overridden through environment variables before loading the model (see Environment variables). |
Executable name | Name of the asynchronous-process executable launched on the target. The only precompiled executable currently available for SPI control is |
Finding the serial number
The 10-digit serial number must be entered as a plain integer (no dash). It can be obtained in three ways:
Physical label: printed on the body of the Aardvark adapter in the format
XXXX-YYYYYY. Remove the dash to obtain the 10-digit integer (for example2239-537666→2239537666).RT-LAB console: when the model is loaded, the asynchronous process logs the detected adapters with their serial numbers.
Total Phase Control Center: connect the adapter and open the Control Center Serial software; the serial number appears in the device list.
Physical connector and SPI pinout
The Aardvark adapter exposes a 10-pin (2×5) 0.100 in (2.54 mm) IDC ribbon connector shared by the I2C and SPI buses. The red wire of the ribbon cable marks pin 1. When wiring a single external SPI device to the adapter, connect the following SPI signals and at least one ground:
Pin | Signal | Description |
|---|---|---|
2 | GND | Ground — a common ground with the external device is mandatory. |
5 | MISO | Master In / Slave Out — data from the slave to the master. |
7 | SCLK | Serial clock, driven by the master. |
8 | MOSI | Master Out / Slave In — data from the master to the slave. |
9 | SS | Slave Select. |
10 | GND | Ground (second ground pin). |
Aardvark I2C/SPI 10-pin connector —The Aardvark I2C/SPI Host Adapter in the upright position.
Pin 1 is located in the upper left corner of the connector and Pin 10 is located in the lower right corner of the connector.
Aardvark I2C/SPI 10-pin connector — The Aardvark I2C/SPI Host Adapter in the upside down position.
Pin 1 is located in the lower left corner of the connector and Pin 10 is located in the upper right corner of the connector.
All signals are 3.3 V logic (compatible with 3.3 V TTL/CMOS devices).
Grounds (pins 2 and 10) must be tied to the external device ground; otherwise the signaling is unpredictable.
Pins 4 (I2C) and 6 (SPI) can optionally supply power (up to 25 mA) to the downstream device when Enable power pins is checked.
When the Aardvark acts as an SPI master, it releases MOSI/SCLK/SS to high impedance after each transaction; an external slave should therefore have a pull-up on its SS line (and ideally on MOSI/SCLK).
For full pin details (including the I2C pins 1/3 and the orientation diagrams), refer to section 2.1 Pinouts of the Aardvark I2C/SPI Host Adapter User Manual.
Inputs
Data ready: this input can be used to control the rate at which the data inputs are sampled.
Data to write: data connected to this port is transferred to the external SPI device. The width of this port determines how many bytes are transferred during a single transaction. This input can only transmit data in byte format.
Outputs
Data received: the data sent by the external SPI device is applied to this output bus. Its width is defined by the Number of bytes to transmit/receive parameter; additional bytes received during a single transaction are discarded.
Status: status word from the asynchronous process.
Send Error / Receive Error: transmit and receive error codes from the asynchronous process. Typically these should be 0.
Environment variables
The following environment variables can be set on the target before loading the model to override the corresponding mask values:
Variable | Description |
|---|---|
| Delay between SPI operations in master mode (overrides Delay between buffer transmissions). |
| Delay between SPI operations in slave mode. |
| Polling timeout used in slave mode. |
| CPU core the asynchronous process is bound to. |
File Transfer
As explained in the Description section, the asynchronous-process sources must be transferred to the target and compiled before the model is loaded. On build, RT-LAB transfers the asynchronous-process sources (AsyncSPI.c, AsyncSPI.h, AsyncSPI.mk) together with the Aardvark adapter files (aardvark.h, aardvark.o, aardvark.so) to the target, where the process is compiled and linked against the OPAL asynchronous API. This is configured through the Files pane of the model. If you have any problem with the file transfer, refer to the example model.
Characteristics and Limitations
Inputs: the block can only transmit 8 data bits per input, per single data transfer.
Outputs: if the block receives more bytes than the configured output width during a single transaction, the additional data is discarded.
Transaction size: it is only possible to reliably transfer up to approximately 4 KiB per SPI transaction (master or slave), due to operating-system buffering.
Configuration: the block configuration (SPI mode, bitrate, clock polarity, clock phase, endianness, slave-select polarity) must match the configuration of the external device.
Timing: if the data exchanged between master and slave appears delayed or incorrect, tuning the Delay between buffer transmissions parameter (or the delay environment variables) might be required.
Direct Feedthrough | No |
Discrete sample time | No |
XHP support | No |
Work offline | No |