SPI Master
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
AT+DRVSPIMCONFGPIO: Configure SPI GPIO
AT+DRVSPIMINIT: Initialize SPI Master driver
AT+DRVSPIMRD: Read SPI data
AT+DRVSPIMWR: Write SPI data
Function Overview
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 1MHz, 2MHz, 3MHz, 4MHz, 5MHz, 6MHz, 10MHz, 20MHz
<mode>: SPI mode, range: 0 ~ 3
Description
SPI GPIO must be configured before initializing SPI.
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
Parameters
<data_len>: Length of data to write
Example
AT+DRVSPIMWR=10 // Write 10 bytes of data