打印
[Atmel]

用ASF跑SAMD21程序(24)重跑EEPROM

[复制链接]
2142|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
上次跑EEPROM,提示没有定义EEPROM,并提示通过熔丝位写,

由于本人,就这么一个D21开发板,所以采取,无过便是功的方法,就是先搞清楚究竟是怎么回事,再采取行动,

现在条件成熟了。

https://bbs.21ic.com/forum.php?mod=viewthread&tid=874803&extra=page%3D1%26filter%3Dtypeid%26typeid%3D380%26typeid%3D380

那就再跑一下EEPROM

首先新建ASF工程,然后加入EEPROM模块,再后打开ASF EXPLOERE,点开快速指导,按提示形成文件。



然后把熔丝位改为0x04



然后重新编译工程

下载运行

则灯亮,若下电再上电灯又亮,再重复又灭。

程序清单:

/**
* \file
*
* \brief Empty user application template
*
*/

/**
* \mainpage User Application template doxygen documentation
*
* \par Empty user application template
*
* This is a bare minimum user application template.
*
* For documentation of the board, go \ref group_common_boards "here" for a link
* to the board-specific documentation.
*
* \par Content
*
* -# Include the ASF header files (through asf.h)
* -# Minimal main function that starts with a call to system_init()
* -# Basic usage of on-board LED and button
* -# "Insert application code here" comment
*
*/

/*
* Include header files for all drivers that have been imported from
* Atmel Software Framework (ASF).
*/
/**
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
*/

void configure_eeprom(void);
#include <asf.h>
void configure_eeprom(void)
{    /* Setup EEPROM emulator service */
            enum status_code error_code = eeprom_emulator_init();
                if (error_code == STATUS_ERR_NO_MEMORY)
                {        
                        while (true) {            /* No EEPROM section has been set in the device's fuses */        }    }
            else if (error_code != STATUS_OK) {        /* Erase the emulated EEPROM memory (assume it is unformatted or         * irrecoverably corrupt) */        
                eeprom_emulator_erase_memory();
                eeprom_emulator_init();    }}
int main (void)
{
        system_init();
        configure_eeprom();
       
       

         uint8_t page_data[EEPROM_PAGE_SIZE];  
         eeprom_emulator_read_page(0, page_data);
         page_data[0] = !page_data[0];
         port_pin_set_output_level(LED_0_PIN, page_data[0]);
         eeprom_emulator_write_page(0, page_data);
         eeprom_emulator_commit_page_buffer();
         while (true) {    }
}

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:http://shop34182318.taobao.com/ http://shop562064536.taobao.com

2399

主题

6964

帖子

68

粉丝