小学生
最后登录1970-1-1
在线时间 小时
注册时间2025-1-9
|
- /**
- * [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();
- }
- }
- }
- }
复制代码
|
|