简体   繁体   中英

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

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. 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. 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). "

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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