EEPROM在NVM (Non Volatile Memory模块中。
所以要加入NVM模块:
以下程序,分两个数组,第一个数组装用户定义的,第二个数组先清零然后再用API函数往里装。
以下是程序:
#include <asf.h>
#define EXAMPLE_PAGE 2
#define EXAMPLE_ADDR EXAMPLE_PAGE * EEPROM_PAGE_SIZE
uint8_t write_page[EEPROM_PAGE_SIZE];
uint8_t read_page[EEPROM_PAGE_SIZE];
fill_page_with_known_data(uint8_t * ppp);
fill_page_with_zeroes(uint8_t * ppp);
int main (void)
{
/* Insert system clock initialization code here (sysclk_init()). */
//sysclk_init();
sysclk_init();
board_init();
fill_page_with_known_data(write_page);
fill_page_with_zeroes(read_page);
nvm_eeprom_load_page_to_buffer(write_page);
nvm_eeprom_atomic_write_page(EXAMPLE_PAGE);
nvm_eeprom_read_buffer(EXAMPLE_ADDR,
read_page, EEPROM_PAGE_SIZE);
;
//check_if_pages_are_equal(write_page, read_page);
}
fill_page_with_known_data(uint8_t * ppp)
{
uint16_t i;
for(i=0;i<32;i++)
{
*(ppp+i) = i;
}
}
fill_page_with_zeroes(uint8_t * ppp)
{
uint16_t i;
for(i=0;i<32;i++)
{
*(ppp+i) = 0;
}
}
以下是仿真的截图,可见数组中已经变成了用户定义的内容。
|