範例 -- 如何在 Arduino Due 使用 DueFlashStorage

您好

我們要告訴大家這個題目,主要是因為 Arduino Mega2560 的 EEPROM 不夠使用,因此我們找尋其他方法來解決這問題。現在我們找到了 Arduino Due 這 DueFlashStorage 的解決方案,讓 Flash 記憶體記憶下載的資料。使用方法如下。

<< from: >>

// 1Kb of data

#define DATA_LENGTH ((IFLASH1_PAGE_SIZE/sizeof(byte))*4)

<< to: >>

// 250Kb of data (It is useful, Implement )

#define DATA_LENGTH ((IFLASH1_PAGE_SIZE/sizeof(byte))* 4)

:

: //(it is more setup)

// you need mail to author with your requirement.

    • 請使用範例建立新專案如 (Due_Balance_Car) ,改變如下:

.<< from: >>

#include <EEPROM.h>

byte iLogic_eeprom_read_byte(unsigned int addr)

{ return EEPROM.read(addr);

}

void iLogic_eeprom_write_byte( unsigned int addr , byte data )

{ EEPROM.write(addr, data);

}

<< to: >>

#include <DueFlashStorage.h>

DueFlashStorage dueFlashStorage;

byte iLogic_eeprom_read_byte(unsigned int addr)

{ return dueFlashStorage.read(addr);

}

void iLogic_eeprom_write_byte( unsigned int addr , byte data )

{ dueFlashStorage.write(addr,data);

}

    • 以上項目完成,您可以使用 flash 去記憶資料了,請小心使用 SetDValue 和 SetDAValue 不要設定太多次在 Func 函示裡,因為這樣會寫入 Flash 裡太多次會損害。