ESP32如何使SPI传输更快
ESP32 how to make SPI transfer faster
我正在使用 ESP32 传输 32MB NOR 闪存芯片的芯片内容,但是传输需要 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();
您应该考虑使用 SPI.transfer(buffer, size)
方法,而不是单独传输每个字节。在 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 中找到的 table:"In case of buffer transfers the received data is stored in the buffer in-place (the old data is replaced with the data received). "
我正在使用 ESP32 传输 32MB NOR 闪存芯片的芯片内容,但是传输需要 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();
您应该考虑使用 SPI.transfer(buffer, size)
方法,而不是单独传输每个字节。在 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 中找到的 table:"In case of buffer transfers the received data is stored in the buffer in-place (the old data is replaced with the data received). "