You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ESP32-H2间SPI数据传输故障:Slave无法接收数据(Arduino IDE环境)

ESP32-H2 同板双芯片SPI通信问题:Slave始终接收数据为0

我是一名70岁的开发者,正在开发一款复杂仪器,目前几乎所有功能都已正常工作,仅剩同一块电路板上两个ESP32-H2芯片间的SPI通信未解决。这是我第一次在论坛发帖,若有不当之处请告知。我已尝试AI工具、乐鑫官方文档、论坛帖子等方法三天,但均未解决问题。

经示波器验证,Master端工作正常,但Slave端始终无法接收到数据,接收值始终为0。

以下是我尝试的其中一种Slave端代码示例:

#include <SPI.h>

const int MOSI_PIN = 25;
const int MISO_PIN = 26;
const int SCLK_PIN = 27;
const int CS_PIN = 22;

volatile byte receivedData = 0;
volatile bool dataReceived = false;

// Interrupt Service Routine (ISR)
void IRAM_ATTR handleSPInterrupt() {
  receivedData = SPI.transfer(0); // Receive data while sending dummy byte
  dataReceived = true;
}

void setup() {
  Serial.begin(115200);

  // Initialize SPI with custom pins
  SPI.begin(SCLK_PIN, MISO_PIN, MOSI_PIN, CS_PIN);
  SPI.setClockDivider(SPI_CLOCK_DIV16); // Adjust clock divider if needed

  // Configure CS pin as input with pullup
  pinMode(CS_PIN, INPUT_PULLUP);

  // Attach interrupt handler
  attachInterrupt(digitalPinToInterrupt(CS_PIN), handleSPInterrupt, FALLING); 

  Serial.println("SPI Slave Initialized.");
}

void loop() {
  if (dataReceived) {
    Serial.print("Received: ");
    Serial.println(receivedData, HEX);
    dataReceived = false; 
  }
}

使用该代码时会出现明显的总线冲突:SCLK和MOSI信号幅度减半且数据重叠。若将MOSI和SCLK引脚设置为输入,Master端信号恢复正常,但Slave接收的数据仍始终为0。我还尝试了其他未在此列出的方法,恳请各位提供帮助!

内容的提问来源于stack exchange,提问作者Orophilia

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 16:52:40