gpt4 book ai didi

flash - 如何将数据存入ESP32的Flash中?

转载 作者:行者123 更新时间:2023-12-03 07:38:08 25 4
gpt4 key购买 nike

我正在尝试使用此library将数据存储到ESP32闪存中。我特别使用example来读写浮点值。我刚刚向该代码添加了Serial.println(“error”),如下所示:

for (uint8_t i = 0; i < arrayLen(floatAddr); i++) 
{
if (flash.writeFloat(0x00, testFloat[i]))
{
Serial.print(testFloat[i]);
Serial.print(" written to 0x");
Serial.println(floatAddr[i], HEX);
}
else
{
Serial.println("error");
}

_float = flash.readFloat(floatAddr[i]);
Serial.print(_float);
Serial.print(" read from 0x");
Serial.println(floatAddr[i], HEX);
}
如果我运行此代码,则会打印出错误声明,即flash.write无法正常工作。我只在页面上看到了一些说明,说明ESP32需要进行一些修改。
*

"An alternate version SPIFlash flash (SPIPinsArray) of theconstructor can be used (only with ESP32 board as of now) to enablethe use of custom SPI pins. SPIPinsArray has to be a 4 element arraycontaining the custom SPI pin numbers (as signed integers - int8_t) inthe following order - sck, miso, mosi, ss.Also make sure to include flash.begin(CHIPSIZE*) in void setup(). This enables the library to detect the type of flash chip installedand load the right parameters.* Optional"


所以我修改了我的代码,如下所示:
#include<SPIMemory.h>

#if defined(ARDUINO_SAMD_ZERO) && defined(SERIAL_PORT_USBVIRTUAL)
// Required for Serial on Zero based boards
#define Serial SERIAL_PORT_USBVIRTUAL
#endif

#if defined (SIMBLEE)
#define BAUD_RATE 250000
#else
#define BAUD_RATE 115200
#endif

#define arrayLen(x) sizeof(x)/sizeof(x[0])
uint32_t strAddr[3], floatAddr[2], byteAddr[4];
String testStr[] = {
"Test String 0",
"Test String 1",
"Test String 2"
};
float testFloat[] = {
3.1415, 6.283
};
byte testByte[] = {
3, 245, 84, 100
};
int8_t SPIPinsArray[] = {18,21,19,5}; //sclk,miso,mosi,ss
//SPIFlash flash(SS1, &SPI1); //Use this constructor if using an SPI bus other than the default SPI. Only works with chips with more than one hardware SPI bus
//SPIFlash flash;
SPIFlash flash(int8_t *SPIPinsArray);
void getAddresses();
void writeData();
void setup() {
Serial.begin(BAUD_RATE);
#if defined (ARDUINO_ARCH_SAMD) || (__AVR_ATmega32U4__) || defined(ARCH_STM32)
while (!Serial) ; // Wait for Serial monitor to open
#endif
delay(50); //Time to terminal get connected
Serial.print(F("Initialising Flash memory"));
for (int i = 0; i < 10; ++i)
{
Serial.print(F("."));
}
Serial.println();
flash.begin();

Serial.println();
Serial.println();

// getAddresses();
dataIO();
//flash.eraseChip(); // Uncomment this if you would like to erase chip
}

void loop()
{

}



// Function to write data
void dataIO()
{
uint8_t _byte;
float _float;
String _string;


for (uint8_t i = 0; i < arrayLen(floatAddr); i++)
{
if (flash.writeFloat(0x00, testFloat[i]))
{
Serial.print(testFloat[i]);
Serial.print(" written to 0x");
Serial.println(floatAddr[i], HEX);
}
else
{
Serial.println("error");
}

_float = flash.readFloat(floatAddr[i]);
Serial.print(_float);
Serial.print(" read from 0x");
Serial.println(floatAddr[i], HEX);
}


}
但是当我这样做时出现以下错误-

request for member 'begin' in 'flash', which is of non-class type'SPIFlash(int8_t*) {aka SPIFlash(signed char*)}' flash.begin;


这个错误是什么意思?我无法调试它。谁能帮助我解决这个问题?

最佳答案

一些ESP32集成了闪存。有些使用外部闪存芯片。此闪存保存应用程序固件,上面可能有文件系统(通常为SPIFFS),并且可能有键值存储(NVS)。此闪存是ESP32上的主要且通常仅是闪存。
您尝试使用的库无法与上述主闪存配合使用。您尝试使用的库需要将辅助闪存芯片连接到ESP32。如果确实使用了主闪存,它将对其进行控制并干扰ESP32运行其固件的能力。仅在将辅助闪存连接到ESP32时使用此库。
要使用ESP32随附的闪存,请为文件系统使用SPIFFS或为键值存储使用Preferences(NVS)。两者都是ESP32的Arduino核心的一部分,易于使用,不需要第二个SPI闪存芯片。

关于flash - 如何将数据存入ESP32的Flash中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65334635/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com