IIC_Send_Byte(0XA0+((ReadAddr/256)<<1))解释

想要搞清楚这句话,就得先把下面这段数据手册中的关键字句读明白。多读几遍,我就读了快10遍。

The device address word consists of a mandatory “1”, “0” sequence for the first four
most significant bits as shown. This is common to all the Serial EEPROM devices.
The next 3 bits are the A2, A1 and A0 device address bits for the 1K/2K EEPROM.
These 3 bits must compare to their corresponding hardwired input pins.
The 4K EEPROM only uses the A2 and A1 device address bits with the third bit being a
memory page address bit. The two device address bits must compare to their corresponding
hardwired input pins. The A0 pin is no connect.
The 8K EEPROM only uses the A2 device address bit with the next two bits being for
memory page addressing. The A2 bit must compare to its corresponding hardwired
input pin. The A1 and A0 pins are no connect.
The 16K does not use any device address bits but instead the three bits are used for
memory page addressing. These page addressing bits on the 4K, 8K and 16K devices
should be considered the most significant bits of the data word address which follows.
The A0, A1 and A2 pins are no connect.

IIC_Send_Byte(0XA0+((ReadAddr/256)<<1)):这句话适用于AT24C16-AT24C02;这句话是通用的;才会这样写;

首先对于AT系列,大分块区间大小为256字节,小分块区间为8位;以c02和c04为例,c02容量为256字节。对于c02,

一个字节对应一个地址(常识微机原理),那么就需要用八位,也就是(0-255),来表示每个字节的地址;

原子开发板,就用的AT24c02,可以研究一下,AT24c02的A0~A2这3个引脚直接接地,这是为什么呢?因为这3个引脚

可以决定你访问哪一个大分块区间(编程实现),如果直接接地,这三个引脚始终为低,对应了设备地址0XA0。

对于ATC04来说,他就有两个256字节空间,那么我们如何快速的区分我想访问的是哪个256空间呢!上面那段英文就规定了

ATC04的访问格式,0x1010  A2+A1+空+读写方向位(这里加只是用来隔开这几个位而已,不要问为什么这样,芯片设计就是这样的),这个“空”位与ATc04硬件连接相对应,

如果硬件也将A0~A2这3个引脚直接接地,那么你猜猜,会有什么结果,不错,就是我们只能寻址0~256这段空间,后面的就寻不到了,就成了c02.

IIC_Send_Byte(0XA0+((ReadAddr/256)<<1))

中(ReadAddr/256)<<1)这半句,作用就是选择这两个256空间的中的某个。

记得还有一句是发送ReadAddr%256,这个就是对某个256空间中的某个8位空间进行寻址,对的就是这样。

如果是AT24C16,它有8个256空间,那么怎么知道选哪个呢,那就在硬件上把这三位留出来,也就是把A0~A2这3个引脚不接。那么再当我们写(ReadAddr/256)<<1)

这句话的时候呢,就能让AT24C16知道我要找哪个256空间了!

这是AT2~16这种型号的芯片,如果超过16了,你猜猜怎样搞呢!对了,没错,那就将16位addr分两次开发,就是这样!希望能给大家解惑。

  • 13
    点赞
  • 42
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值