[Atmel] 用ASF跑SAMD21程序(18)EEPROM

[复制链接]
1919|2
 楼主| ddllxxrr 发表于 2015-1-13 23:52 | 显示全部楼层 |阅读模式
首先,新建ASF工程,然后加入EEPROM模块。


然后在ASF explorer中打开QUICK START GUIDE


按照上面步骤做,然后编译通过:


但下进去灯不亮,有断点才发现原来熔丝位没有设EEPROM段。究竟怎么原因,下回分解。

上程序先:

  1. /**
  2. * \file
  3. *
  4. * \brief Empty user application template
  5. *
  6. */

  7. /**
  8. * \mainpage User Application template doxygen documentation
  9. *
  10. * \par Empty user application template
  11. *
  12. * This is a bare minimum user application template.
  13. *
  14. * For documentation of the board, go \ref group_common_boards "here" for a link
  15. * to the board-specific documentation.
  16. *
  17. * \par Content
  18. *
  19. * -# Include the ASF header files (through asf.h)
  20. * -# Minimal main function that starts with a call to system_init()
  21. * -# Basic usage of on-board LED and button
  22. * -# "Insert application code here" comment
  23. *
  24. */

  25. /*
  26. * Include header files for all drivers that have been imported from
  27. * Atmel Software Framework (ASF).
  28. */
  29. #include <asf.h>
  30. void configure_eeprom(void);

  31. void configure_eeprom(void)
  32. {   
  33.          /* Setup EEPROM emulator service */
  34.          enum status_code error_code = eeprom_emulator_init();
  35.          if (error_code == STATUS_ERR_NO_MEMORY)
  36.           {
  37.                           while (true)
  38.                                    {            /* No EEPROM section has been set in the device's fuses */        }   
  39.            }
  40.          else if (error_code != STATUS_OK)
  41.          {        /* Erase the emulated EEPROM memory (assume it is unformatted or         * irrecoverably corrupt) */
  42.                         eeprom_emulator_erase_memory();
  43.                                  eeprom_emulator_init();    }}

  44. int main (void)
  45. {
  46.         system_init();
  47.         configure_eeprom();
  48.        
  49.          uint8_t page_data[EEPROM_PAGE_SIZE];
  50.          eeprom_emulator_read_page(0, page_data);
  51.          page_data[0] = !page_data[0];
  52.          port_pin_set_output_level(LED_0_PIN, page_data[0]);
  53.          eeprom_emulator_write_page(0, page_data);
  54.          eeprom_emulator_commit_page_buffer();
  55.           while (true) {    }

  56.        
  57. }

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
百能网PCB 发表于 2015-1-14 09:58 | 显示全部楼层
mcuzone 发表于 2015-1-14 11:20 | 显示全部楼层
版主很努力
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

2404

主题

7001

帖子

68

粉丝
快速回复 在线客服 返回列表 返回顶部