RT-Thread使用SPI接口操作eeprom(M950x0)

一、介绍

        RT-Thread使用SPI读写eeprom例程,芯片使用的是M95020,在AT32F407和STM32f107上已经测试使用过。

二、软件架构

软件架构说明 依赖 RT-Thread-V4.1.0 的SPI设备驱动框架。

三、修改

1、根据自己的硬件设计,修改SPI通道,并确定SPI正常。

2、修改EEPROM_CS_PIN和EEPROM_WP_PIN。

3、修改EEPROM_TYPE

#ifndef EEPROM_TYPE
#define EEPROM_TYPE     EEPROM_M95020
#endif

#define BUS_NAME        "spi1"
#define CS_GPIO_X       GPIOA
#define CS_GPIO_PIN     GPIO_PINS_4
#define SPI_DEVICE_NAME "m950x0"

#define EEPROM_WP_PIN		GET_PIN(C, 4) 

当前使用的电路如下:

四、测试接口

1、检查测试(向最后一个字节写入数据,再读出来进行判断)

        eeprom_check

2、擦除(将指定的数据块擦除成指定的数据)

eeprom_erase [addr] [date] [len]

3、写入(写入随意数据)

eeprom_write [start addr] 11 22 33 44

4、读取

eeprom_read  [addr]  [count]

五、测试结果

eeprom检查

msh >eeprom_check
[D/eeprom] eeprom check ok


读取20个字节

msh >eeprom_read 0 20
[I/eeprom] read buf[0]=0xff
[I/eeprom] read buf[1]=0xff
[I/eeprom] read buf[2]=0xff
[I/eeprom] read buf[3]=0xff
[I/eeprom] read buf[4]=0xff
[I/eeprom] read buf[5]=0xff
[I/eeprom] read buf[6]=0xff
[I/eeprom] read buf[7]=0xff
[I/eeprom] read buf[8]=0xff
[I/eeprom] read buf[9]=0xff
[I/eeprom] read buf[10]=0xff
[I/eeprom] read buf[11]=0xff
[I/eeprom] read buf[12]=0xff
[I/eeprom] read buf[13]=0xff
[I/eeprom] read buf[14]=0xff
[I/eeprom] read buf[15]=0xff
[I/eeprom] read buf[16]=0xff
[I/eeprom] read buf[17]=0xff
[I/eeprom] read buf[18]=0xff
[I/eeprom] read buf[19]=0xff


从地址0开始写入1~8

msh >eeprom_write 0 1 2 3 4 5 6 7 8
[D/eeprom] buf[0]=1 (0x1)
[D/eeprom] buf[1]=2 (0x2)
[D/eeprom] buf[2]=3 (0x3)
[D/eeprom] buf[3]=4 (0x4)
[D/eeprom] buf[4]=5 (0x5)
[D/eeprom] buf[5]=6 (0x6)
[D/eeprom] buf[6]=7 (0x7)
[D/eeprom] buf[7]=8 (0x8)


从地址10开始,写入1~8
msh >eeprom_write 10 1 2 3 4 5 6 7 8
[D/eeprom] buf[0]=1 (0x1)
[D/eeprom] buf[1]=2 (0x2)
[D/eeprom] buf[2]=3 (0x3)
[D/eeprom] buf[3]=4 (0x4)
[D/eeprom] buf[4]=5 (0x5)
[D/eeprom] buf[5]=6 (0x6)
[D/eeprom] buf[6]=7 (0x7)
[D/eeprom] buf[7]=8 (0x8)


读取后对比

msh >eeprom_read 0 20
[I/eeprom] read buf[0]=0x1
[I/eeprom] read buf[1]=0x2
[I/eeprom] read buf[2]=0x3
[I/eeprom] read buf[3]=0x4
[I/eeprom] read buf[4]=0x5
[I/eeprom] read buf[5]=0x6
[I/eeprom] read buf[6]=0x7
[I/eeprom] read buf[7]=0x8
[I/eeprom] read buf[8]=0xff
[I/eeprom] read buf[9]=0xff
[I/eeprom] read buf[10]=0x1
[I/eeprom] read buf[11]=0x2
[I/eeprom] read buf[12]=0x3
[I/eeprom] read buf[13]=0x4
[I/eeprom] read buf[14]=0x5
[I/eeprom] read buf[15]=0x6
[I/eeprom] read buf[16]=0x7
[I/eeprom] read buf[17]=0x8
[I/eeprom] read buf[18]=0xff
[I/eeprom] read buf[19]=0xff
 

六、代码库

https://gitee.com/liuc0721/spi_eeprom_m950x0.git

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值