小学生
最后登录1970-1-1
在线时间 小时
注册时间2025-1-9
|
在这段代码中,如果写地址没有对齐页,并且写入数据小于页大小时,我认为并不能直接用整页写入。
如果写地址为 WriteAddr = 5,页大小为8,并且要写入 7 字节数据,这是满足上述条件的。那么从地址 5 开始写入 7 字节,写操作将涉及地址 5, 6, 7, 8, 9, 10, 11。这意味着,数据的第四个字节将落在页面边界之后(即页大小为 8 字节,地址 8 是一个新页面的开始)。因此,数据将跨越页面边界。EEPROM 无法跨页面进行写操作
有大佬解答一下我的问题吗?
- /**
- * [url=home.php?mod=space&uid=41770]@brief[/url] 将缓冲区中的数据写到I2C EEPROM中
- * @param
- * @arg pBuffer:缓冲区指针
- * @arg WriteAddr:写地址
- * @arg NumByteToWrite:写的字节数
- * @retval 无
- */
- void I2C_EE_BufferWrite(u8* pBuffer, u8 WriteAddr, u16 NumByteToWrite)
- {
- u8 NumOfPage = 0, NumOfSingle = 0, Addr = 0, count = 0;
- Addr = WriteAddr % I2C_PageSize;
- count = I2C_PageSize - Addr;
- NumOfPage = NumByteToWrite / I2C_PageSize;
- NumOfSingle = NumByteToWrite % I2C_PageSize;
-
- /* If WriteAddr is I2C_PageSize aligned */
- if(Addr == 0)
- {
- /* If NumByteToWrite < I2C_PageSize */
- if(NumOfPage == 0)
- {
- I2C_EE_PageWrite(pBuffer, WriteAddr, NumOfSingle);
- I2C_EE_WaitEepromStandbyState();
- }
- /* If NumByteToWrite > I2C_PageSize */
- else
- {
- while(NumOfPage--)
- {
- I2C_EE_PageWrite(pBuffer, WriteAddr, I2C_PageSize);
- I2C_EE_WaitEepromStandbyState();
- WriteAddr += I2C_PageSize;
- pBuffer += I2C_PageSize;
- }
- if(NumOfSingle!=0)
- {
- I2C_EE_PageWrite(pBuffer, WriteAddr, NumOfSingle);
- I2C_EE_WaitEepromStandbyState();
- }
- }
- }
- /* If WriteAddr is not I2C_PageSize aligned */
- else
- {
- /* If NumByteToWrite < I2C_PageSize */
- if(NumOfPage== 0)
- {
- I2C_EE_PageWrite(pBuffer, WriteAddr, NumOfSingle);
- I2C_EE_WaitEepromStandbyState();
- }
- /* If NumByteToWrite > I2C_PageSize */
- else
- {
- NumByteToWrite -= count;
- NumOfPage = NumByteToWrite / I2C_PageSize;
- NumOfSingle = NumByteToWrite % I2C_PageSize;
-
- if(count != 0)
- {
- I2C_EE_PageWrite(pBuffer, WriteAddr, count);
- I2C_EE_WaitEepromStandbyState();
- WriteAddr += count;
- pBuffer += count;
- }
-
- while(NumOfPage--)
- {
- I2C_EE_PageWrite(pBuffer, WriteAddr, I2C_PageSize);
- I2C_EE_WaitEepromStandbyState();
- WriteAddr += I2C_PageSize;
- pBuffer += I2C_PageSize;
- }
- if(NumOfSingle != 0)
- {
- I2C_EE_PageWrite(pBuffer, WriteAddr, NumOfSingle);
- I2C_EE_WaitEepromStandbyState();
- }
- }
- }
- }
复制代码
|
|