MelexisIO SCPI Commands
Loading...
Searching...
No Matches
SPI SCPI Commands

This document describes the SCPI command interface implemented in commands_spi.c for SPI (Serial Peripheral Interface) control on the Melexis IO STM32 platform.

Overview

The commands_spi.c file provides SCPI-like commands for initializing, configuring, and performing data transfers over two SPI peripherals (SPI1 and SPI2). It also supports Vdd control, buffer direction, and chip select (CS) management for flexible SPI communication.

Supported Commands

Vdd Control

Command Pattern Description
:VDD? Return Vdd state
:VDD:OFF Disable Vdd
:VDD:3V3 Set SPI Vdd to 3.3V
:VDD:5V Set SPI Vdd from USB Vbus (5V)

Buffer Direction

Command Pattern Description
:SPI:BUFfer Set buffer controls DIR_0...DIR_5

SPI1 (Connector X2)

Command Pattern Description
:SPI:INFO? Get SPI1 settings
:SPI:Init Initialize SPI1 (0-CS0, 1-CS1, 2-Both, 3-None)
:SPI:DeInit Deinitialize SPI1
:SPI:FRame Set frame format (0-Motorola, 1-TI)
:SPI:DATAsize Set data size (0-8bit, 1-16bit)
:SPI:FirstBit Set first bit (0-MSB, 1-LSB)
:SPI:CPOL Set clock polarity (0-Low, 1-High)
:SPI:CPHA Set clock phase (0-1 edge, 1-2 edge)
:SPI:PRESCaler Set prescaler (2, 4, ..., 256)
:SPI:CS0 Set CS0
:SPI:CS0? Get CS0
:SPI:CS1 Set CS1
:SPI:CS1? Get CS1
:SPI:ReaD Read SPI1 «count 1-256»
:SPI:WRite Write SPI1 «data»[,«data»...256]
:SPI:WriteReaD Write/Read SPI1 «data»[,«data»...256]
:SPI:EXCHange Write/Read SPI1 «count 1-256»,«data»[,«data»...]
:SPI:0:ReaD Read SPI1 slave 0 «count 1-256»
:SPI:0:WRite Write SPI1 slave 0 «data»[,«data»...256]
:SPI:0:WriteReaD Write/Read SPI1 slave 0 «data»[,«data»...256]
:SPI:0:EXChange Write/Read SPI1 slave 0 «count»,«data»[,...]
:SPI:1:ReaD Read SPI1 slave 1 «count 1-256»
:SPI:1:WRite Write SPI1 slave 1 «data»[,«data»...256]
:SPI:1:WriteReaD Write/Read SPI1 slave 1 «data»[,«data»...256]
:SPI:1:EXCHange Write/Read SPI1 slave 1 «count»,«data»[,...]

SPI2 (Header H5)

Command Pattern Description
:SPI2:INFO? Get SPI2 settings
:SPI2:Init Initialize SPI2 (0-CS0, 1-CS1, 2-Both)
:SPI2:DeInit Deinitialize SPI2
:SPI2:FRame Set frame format (0-Motorola, 1-TI)
:SPI2:DATAsize Set data size (0-8bit, 1-16bit)
:SPI2:FirstBit Set first bit (0-MSB, 1-LSB)
:SPI2:CPOL Set clock polarity (0-Low, 1-High)
:SPI2:CPHA Set clock phase (0-1 edge, 1-2 edge)
:SPI2:PRESCaler Set prescaler (2, 4, ..., 256)
:SPI2:CS0 Set CS0
:SPI2:CS0? Get CS0
:SPI2:CS1 Set CS1
:SPI2:CS1? Get CS1
:SPI2:ReaD Read SPI2 «count 1-256»
:SPI2:WRite Write SPI2 «data»[,«data»...256]
:SPI2:WriteReaD Write/Read SPI2 «data»[,«data»...256]
:SPI2:EXCHange Write/Read SPI2 «count 1-256»,«data»[,«data»...]
:SPI2:0:ReaD Read SPI2 slave 0 «count 1-256»
:SPI2:0:WRite Write SPI2 slave 0 «data»[,«data»...256]
:SPI2:0:WriteReaD Write/Read SPI2 slave 0 «count»,«data»[,...]
:SPI2:0:EXCHange Write/Read SPI2 slave 0 «count»,«data»[,...]
:SPI2:1:ReaD Read SPI2 slave 1 «count 1-256»
:SPI2:1:WRite Write SPI2 slave 1 «data»[,«data»...256]
:SPI2:1:WriteReaD Write/Read SPI2 slave 1 «data»[,«data»...256]
:SPI2:1:EXCHange Write/Read SPI2 slave 1 «count»,«data»[,...]

Command Details

  • Vdd Control: Manage SPI Vdd power (OFF, 3.3V, 5V, query state).
  • Buffer: Set direction of buffer pins DIR_1 to DIR_5.
  • Init/DeInit: Initialize or deinitialize SPI peripherals and chip select pins.
  • Frame/DataSize/FirstBit/CPOL/CPHA/Prescaler: Configure SPI frame format, data size, bit order, clock polarity/phase, and baudrate.
  • CS/CS?: Set or query chip select (CS0/CS1) state or mapping.
  • ReaD/WRite/WriteReaD/EXCHange: Perform SPI data transfers (read, write, write/read, exchange) with optional slave selection.

Examples

Initialize SPI1

Command sent:

:SPI:Init 0\n

Response:

(OK)>

Set SPI1 Prescaler

Command sent:

:SPI:PRESCaler 8\n

Response:

(OK)>

Write Data to SPI1

Command sent:

:SPI:WRite 12,34,56\n

Response:

(OK)>

Read Data from SPI1

Command sent:

:SPI:ReaD 3\n

Response:

Data: 12 34 56
(OK)>

Exchange Data with SPI1 Slave 0

Command sent:

:SPI:0:EXChange 2,AB,CD\n

Response:

Data: EF 01
(OK)>

Error Example (Invalid Prescaler)

Command sent:

:SPI:PRESCaler 3\n

Response:

ERR: invalid prescaler value
(Some error)>

Notes

  • Commands are case-insensitive.
  • The command interface is extensible; new features or pins can be added by updating the command table and implementing the corresponding handler logic.
  • Some commands require specific hardware features or configurations.