查看: 450|回复: 0

[经验] 详解TI--M4内部EEPROM

[复制链接]

该用户从未签到

发表于 2021-3-2 09:38:22 | 显示全部楼层 |阅读模式
分享到:
M4里面的EEPROM并不是编址在内存空间中的,而是直接通过操作寄存器(Register)进行读写的。所以EEPROM中间的某个地址就是只属于EEPROM的地址,并不和内存地址有冲突。


要想方便的使用EEPROM,最好的办法就是使用TI的StellarisWare驱动库程序:


  1. <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">#include "inc/hw_memmap.h"</font>
  2. <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">#include "inc/hw_types.h"</font>
  3. <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">#include "inc/hw_timer.h"</font>
  4. <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">#include "inc/hw_ints.h"</font>
  5. <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">#include "inc/hw_gpio.h"</font>
  6. <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">#include "driverlib/sysctl.h"</font>
  7. <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">#include "driverlib/eeprom.h"</font>
  8. <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">
  9. </font>
  10. <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">unsigned long pulRead[2];</font>
  11. <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">
  12. </font>
  13. <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">void main()</font>
  14. <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">{</font>
  15. <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">    unsigned long pulData[2];</font>
  16. <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">
  17. </font>
  18. <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">    // 系统工作在50MHZ</font>
  19. <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">    SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |SYSCTL_XTAL_16MHZ);</font>
  20. <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">
  21. </font>
  22. <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">    // 使能EEPROM</font>
  23. <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">    SysCtlPeripheralEnable(SYSCTL_PERIPH_EEPROM0); </font>
  24. <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">  </font>
  25. <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">    // 初始化EEPROM</font>
  26. <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">    EEPROMInit(); </font>
  27. <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">
  28. </font>
  29. <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">    pulData[0] = 0x12345678;</font>
  30. <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">    pulData[1] = 0x56789abc; </font>
  31. <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">
  32. </font>
  33. <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">    // 向EEPROM里面0x400地址写入数据</font>
  34. <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">    EEPROMProgram(pulData, 0x400, sizeof(pulData)); </font>
  35. <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">
  36. </font>
  37. <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">    // 读回来</font>
  38. <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">    EEPROMRead(pulRead, 0x400, sizeof(pulRead));    </font>
  39. <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">    while(1)</font>
  40. <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">    {</font>
  41. <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">    }</font>
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 注册/登录

本版积分规则

关闭

站长推荐上一条 /2 下一条



手机版|小黑屋|与非网

GMT+8, 2024-4-19 22:28 , Processed in 0.116228 second(s), 15 queries , MemCache On.

ICP经营许可证 苏B2-20140176  苏ICP备14012660号-2   苏州灵动帧格网络科技有限公司 版权所有.

苏公网安备 32059002001037号

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.