This is the documentation for the latest (main) development branch. If you are looking for the documentation of previous releases, use the drop-down menu on the left and select the desired version.

SPI Master Command Set

Introduction

SPI (Serial Peripheral Interface) is a common serial communication protocol used primarily for data transmission between microcontrollers and various peripheral devices. It is a full-duplex communication method that allows data to be transmitted simultaneously in both directions. Before starting AT commands, ensure that the SPI master and SPI slave are properly connected.

Function List

  1. AT+DRVSPIMCONFGPIO: Configure SPI GPIO

  2. AT+DRVSPIMINIT: Initialize SPI Master driver

  3. AT+DRVSPIMRD: Read SPI data

  4. AT+DRVSPIMWR: Write SPI data

Function Overview

Note

It needs to be called after SPIM initialization, otherwise the configurations of CLOCK, MISO, and MOSI will be overwritten by the default values during the SPIM initialization process.

AT+DRVSPIMCONFGPIO: Configure SPI GPIO

Set Command

Command:

AT+DRVSPIMCONFGPIO=<mosi>,<miso>,<sclk>,<cs>

Response:

OK

Parameters

  • <mosi>: Data line from master to slave

  • <miso>: Data line from slave to master

  • <sclk>: Clock signal line generated by the master

  • <cs>: Used to select a specific slave device

Example

AT+DRVSPIMCONFGPIO=7,16,17,0 //Configure mosi: GPIO7, miso: GPIO16, sclk: GPIO17, cs: GPIO0

AT+DRVSPIMINIT: Initialize SPI Master driver

Set Command

Command:

AT+DRVSPIMINIT=<clock>,<mode>

Response:

OK

Parameters

  • <clock>: Clock speed, currently supports 10KHz~20MHz

  • <mode>: SPI mode, range: 0 ~ 3

Description

  • The SPI GPIO needs to be configured before SPI initialization.

Example

AT+DRVSPIMINIT=2,0  //Set SPI mode to 0, 2MHz clock

AT+DRVSPIMRD: Read SPI data

Set Command

Command:

AT+DRVSPIMRD=<data_len>

Response:

OK

Parameters

  • <data_len>: Length of data to read

Example

AT+DRVSPIRD=10  // Read 10 bytes of data

AT+DRVSPIMWR: Write SPI data

Set Command

Command:

AT+DRVSPIMWR=<data_len>

Response:

OK

Parameter

  • <data_len>: Length of data to write

Example

AT+DRVSPIMWR=10  // Write 10 bytes of data