我正在尝试做一些研究和开发,需要看看在一个没有连接到串行控制台的位置上,RFduino上的温度在5分钟的时间间隔内是如何变化的,每秒钟测量一次。我想用内置的闪光灯来做这个。(我正在存储字节,这是300字节的信息,应该适合1K页面,对吗?)这是我想出的代码,但它只将一个值保存到闪存。或者我只能拿回一个值。它目前运行10秒(而count<10)。如何保存和检索整个值数组?
// select a flash page that isn't in use (see Memory.h for more info)
#define MY_FLASH_PAGE 251
// double level of indirection required to get gcc
// to apply the stringizing operator correctly
#define str(x) xstr(x)
#define xstr(x) #x
byte values[500];
int count = 0;
void setup() {
Serial.begin(38400);
Serial.println("All output will appear on the serial monitor.");
// a flash page is 1K in length, so page 251 starts at address 251 * 1024 = 257024 = 3EC00 hex
byte *p = (byte*)ADDRESS_OF_PAGE(MY_FLASH_PAGE);
int rc;
Serial.println("The data stored in flash page " str(MY_FLASH_PAGE) " contains: ");
Serial.println(*p);
Serial.print("Attempting to erase flash page " str(MY_FLASH_PAGE) ": ");
rc = flashPageErase(PAGE_FROM_ADDRESS(p));
if (rc == 0)
Serial.println("Success");
else if (rc == 1)
Serial.println("Error - the flash page is reserved");
else if (rc == 2)
Serial.println("Error - the flash page is used by the sketch");
Serial.println("The data stored in flash page " str(MY_FLASH_PAGE) " contains: ");
Serial.println(*p);
while (count<10){
RFduino_ULPDelay(SECONDS(1));
byte temp = RFduino_temperature(CELSIUS);
Serial.println (count);
Serial.println (temp);
values[count]=temp;
count++;
}
Serial.print("Attempting to write data to flash page " str(MY_FLASH_PAGE) ": ");
rc = flashWriteBlock(p, &values, sizeof(values));
if (rc == 0)
Serial.println("Success");
else if (rc == 1)
Serial.println("Error - the flash page is reserved");
else if (rc == 2)
Serial.println("Error - the flash page is used by the sketch");
Serial.println("The data stored in flash page " str(MY_FLASH_PAGE) " contains: ");
Serial.println(*p);
}
void loop() {
}这是我的输出:
All output will appear on the serial monitor.
The data stored in flash page 251 contains:
255
Attempting to erase flash page 251: Success
The data stored in flash page 251 contains:
255
0
33
1
33
2
33
3
33
4
33
5
33
6
33
7
33
8
33
9
33
Attempting to write data to flash page 251: Success
The data stored in flash page 251 contains:
33我想要它写和检索所有的10个值!
发布于 2015-05-30 09:10:08
您可以像访问数组一样访问数据。
为了测试这一点,您可以(暂时)注释掉您的闪存编写代码,并运行以下代码片段:
byte *p = (byte*)ADDRESS_OF_PAGE(MY_FLASH_PAGE);
Serial.println("The data stored in flash page " str(MY_FLASH_PAGE) " contains: ");
for (count = 0; count < 10; count++)
{
Serial.print(count);
Serial.print(":");
Serial.print(p[count]);
Serial.print("; ");
}
Serial.println();注意:RFduino_temperature(CELSIUS)返回浮点值。
https://stackoverflow.com/questions/30514659
复制相似问题