ESP32的VSPI和HSPI

说明

SPI共有4根线,MOSI、MISO、CS、CLK,在ESP32中对应规则如下表:
在这里插入图片描述
ESP32共有4个SPI,但是用户能够使用的只有2个SPI,分为VSPI和HSPI。
在这里插入图片描述

引脚接口

在ESP32的数据手册中,说明了VSPI和HSPI对应的引脚:

  • VSPI:
    在这里插入图片描述
  • HSPI:
    在这里插入图片描述
    但是比较麻烦的是,ESP官方不知道犯了什么SB毛病,非弄出来个没有丝毫用途的Strapping 管脚,稍不注意,上电瞬间Strapping管脚电平不对,就没法正常启动,导致但凡是有Strapping管脚功能的引脚,大家都不敢使用
    在SPI中也是这样,VSPI和HSPI默认的引脚中,都有作为Strapping管脚的引脚。我们要格外格外的小心
    在这里插入图片描述
    在这里插入图片描述

结合Strapping管脚,将引脚对应整理如下表

  • VSPI
引脚功能备注
IO23MOSI
IO19MISO
IO18CLK
IO5CSStrapping管脚,上电瞬间必须保证上拉
  • HSPI
引脚功能备注
IO13MOSI
IO12MISOStrapping管脚,上电瞬间必须保证下拉
IO14CLK
IO15CSStrapping管脚,上电瞬间必须保证上拉

更改Auduino框架中SPI默认的引脚

在用arduino框架时,其默认的SPI引脚如下:
在这里插入图片描述

除了使用默认的引脚之外,还可以使用其他方式更改默认引脚。官方给出的示例如下:

/* The ESP32 has four SPi buses, however as of right now only two of
 * them are available to use, HSPI and VSPI. Simply using the SPI API 
 * as illustrated in Arduino examples will use VSPI, leaving HSPI unused.
 * 
 * However if we simply intialise two instance of the SPI class for both
 * of these buses both can be used. However when just using these the Arduino
 * way only will actually be outputting at a time.
 * 
 * Logic analyser capture is in the same folder as this example as
 * "multiple_bus_output.png"
 * 
 * created 30/04/2018 by Alistair Symonds
 */
#include <SPI.h>

// Define ALTERNATE_PINS to use non-standard GPIO pins for SPI bus

#ifdef ALTERNATE_PINS
  #define VSPI_MISO   2
  #define VSPI_MOSI   4
  #define VSPI_SCLK   0
  #define VSPI_SS     33

  #define HSPI_MISO   26
  #define HSPI_MOSI   27
  #define HSPI_SCLK   25
  #define HSPI_SS     32
#else
  #define VSPI_MISO   MISO
  #define VSPI_MOSI   MOSI
  #define VSPI_SCLK   SCK
  #define VSPI_SS     SS

  #define HSPI_MISO   12
  #define HSPI_MOSI   13
  #define HSPI_SCLK   14
  #define HSPI_SS     15
#endif

#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
#define VSPI FSPI
#endif

static const int spiClk = 1000000; // 1 MHz

//uninitalised pointers to SPI objects
SPIClass * vspi = NULL;
SPIClass * hspi = NULL;

void setup() {
  //initialise two instances of the SPIClass attached to VSPI and HSPI respectively
  vspi = new SPIClass(VSPI);
  hspi = new SPIClass(HSPI);
  
  //clock miso mosi ss

#ifndef ALTERNATE_PINS
  //initialise vspi with default pins
  //SCLK = 18, MISO = 19, MOSI = 23, SS = 5
  vspi->begin();
#else
  //alternatively route through GPIO pins of your choice
  vspi->begin(VSPI_SCLK, VSPI_MISO, VSPI_MOSI, VSPI_SS); //SCLK, MISO, MOSI, SS
#endif

#ifndef ALTERNATE_PINS
  //initialise hspi with default pins
  //SCLK = 14, MISO = 12, MOSI = 13, SS = 15
  hspi->begin();
#else
  //alternatively route through GPIO pins
  hspi->begin(HSPI_SCLK, HSPI_MISO, HSPI_MOSI, HSPI_SS); //SCLK, MISO, MOSI, SS
#endif

  //set up slave select pins as outputs as the Arduino API
  //doesn't handle automatically pulling SS low
  pinMode(vspi->pinSS(), OUTPUT); //VSPI SS
  pinMode(hspi->pinSS(), OUTPUT); //HSPI SS

}

// the loop function runs over and over again until power down or reset
void loop() {
  //use the SPI buses
  spiCommand(vspi, 0b01010101); // junk data to illustrate usage
  spiCommand(hspi, 0b11001100);
  delay(100);
}

void spiCommand(SPIClass *spi, byte data) {
  //use it as you would the regular arduino SPI API
  spi->beginTransaction(SPISettings(spiClk, MSBFIRST, SPI_MODE0));
  digitalWrite(spi->pinSS(), LOW); //pull SS slow to prep other end for transfer
  spi->transfer(data);
  digitalWrite(spi->pinSS(), HIGH); //pull ss high to signify end of data transfer
  spi->endTransaction();
}

实际的两块arduino设备进行spi通信代码如下:
arduino进行spi通信

参考:
ESP32官网spi代码
Arduino spi帮助

### starRC、LEF DEF 文件的 EDA 工具使用教程 #### 关于 starRC 的使用说明 starRC 是由 Synopsys 开发的一款用于寄生参数提取 (PEX) 的工具,在 detail routing 完成之后被调用,以提供精确的电阻电容延迟分析数据[^2]。该工具能够处理复杂的多层互连结构并支持多种工艺节点。 对于 starRC 的具体操作指南,通常可以从官方文档获取最权威的信息。访问 Synopsys 官方网站的技术资源页面,可以找到最新的产品手册以及应用笔记等资料。此外,还可以通过在线帮助系统获得交互式的指导支持服务。 #### LEF DEF 文件格式解析及其在 Cadence 中的应用 LEF(Library Exchange Format) DEF(Design Exchange Format)是两种广泛应用于集成电路布局布线阶段的标准文件格式之一[^3]。前者主要用于描述标准单元库中的元件几何形状;后者则记录了整个芯片版图的设计信息,包括但不限于各个模块的位置关系、网络连接情况等重要细节。 当涉及到这些文件类型的编辑或读取时,Cadence 提供了一系列强大的平台级解决方案,比如 Virtuoso Layout Editor 就可以直接打开并修改 LEF/DEF 格式的项目工程。为了更好地理解运用这两种文件格式,建议参阅 Cadence 发布的相关培训材料或是参加其举办的专项课程学习活动。 ```bash # 示例命令:查看 LEF 或 DEF 文件内容 cat my_design.lef cat my_design.def ```
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

天城寺电子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值