简体   繁体   English

ESP32 如何让 SPI 传输更快

[英]ESP32 how to make SPI transfer faster

Im using a ESP32 to transfer the chip contents of a 32MB NOR Flash Chip however the transfer takes over 1 hour to transfer the whole 32MBs i was hoping theres a way to speed it up here my current code我使用 ESP32 传输 32MB NOR Flash 芯片的芯片内容,但是传输需要 1 个多小时才能传输整个 32MB 我希望有一种方法可以加快速度

uint8_t sector_buffer [512];

Serial.print("Writing NOR Dump to SD\n");
vspi->beginTransaction(SPISettings(30000000, MSBFIRST, SPI_MODE0));
digitalWrite(VSPI_SS, LOW); //pull SS low to prep other end for transfer
vspi->transfer(WB_READ_DATA);
vspi->transfer(0x00); // Address (three bytes, A23 bit first).
vspi->transfer(0x00);
vspi->transfer(0x00);

//open sd file here

for (int i=0;i<0x10000;i++) { // 32Mbytes / 512.
  for (int s=0;s<512;s++) sector_buffer[s] = vspi->transfer(0x00);

  //write to sd
  file.write(sector_buffer, 512);
}
digitalWrite(VSPI_SS, HIGH); //pull ss high to signify end of data transfer
vspi->endTransaction();

Instead of transferring every single byte seperately you should consider using the SPI.transfer(buffer, size) methode.您应该考虑使用SPI.transfer(buffer, size)方法,而不是单独传输每个字节。 The table found in https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/spi_master.html#transfer-speed-considerations will give you a good idea why sending single bytes is suboptimal at best. https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/spi_master.html#transfer-speed-considerations中的表格将让您很好地了解为什么发送单字节充其量是次优的。 According to https://www.arduino.cc/en/Reference/SPITransfer : "In case of buffer transfers the received data is stored in the buffer in-place (the old data is replaced with the data received). "根据https://www.arduino.cc/en/Reference/SPITransfer :“在缓冲区传输的情况下,接收到的数据就地存储在缓冲区中(旧数据被接收到的数据替换)。”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM