小学生
最后登录1970-1-1
在线时间 小时
注册时间2015-7-31
|
发表于 2015-8-18 22:15:40
|
显示全部楼层
对于这一部分的知识 我也有些疑问 请问各位大神。就是野火教程中 硬件I2C_EEPROM程序中- 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();
- }
- }
- }
- }
- /**
- * @brief D′ò»¸ö×Ö½úμ½I2C EEPROMÖD
- * @param
- * @arg pBuffer:»o3åÇøÖ¸Õë
- * @arg WriteAddr:D′μØÖ·
- * @retval ÎT
- */
- void I2C_EE_ByteWrite(u8* pBuffer, u8 WriteAddr)
- {
- /* Send STRAT condition */
- I2C_GenerateSTART(I2C1, ENABLE);
- /* Test on EV5 and clear it */
- while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT));
- /* Send EEPROM address for write */
- I2C_Send7bitAddress(I2C1, EEPROM_ADDRESS, I2C_Direction_Transmitter);
-
- /* Test on EV6 and clear it */
- while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
-
- /* Send the EEPROM's internal address to write to */
- I2C_SendData(I2C1, WriteAddr);
-
- /* Test on EARM and clear it */
- while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
- /* Send the byte to be written */
- I2C_SendData(I2C1, *pBuffer);
-
- /* Test on EARM and clear it */
- while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
-
- /* Send STOP condition */
- I2C_GenerateSTOP(I2C1, ENABLE);
- }
- /**
- * @brief ÔúEEPROMμÄò»¸öD′Ñ-»·ÖD¿éòÔD′¶à¸ö×Ö½ú£¬μ«ò»′ÎD′èëμÄ×Ö½úêy
- * 2»Äü3¬1yEEPROMò3μÄ′óD¡£¬AT24C02ÿò3óD8¸ö×Ö½ú
- * @param
- * @arg pBuffer:»o3åÇøÖ¸Õë
- * @arg WriteAddr:D′μØÖ·
- * @arg NumByteToWrite:D′μÄ×Ö½úêy
- * @retval ÎT
- */
- void I2C_EE_PageWrite(u8* pBuffer, u8 WriteAddr, u8 NumByteToWrite)
- {
- while(I2C_GetFlagStatus(I2C1, I2C_FLAG_BUSY)); // Added by Najoua 27/08/2008
-
- /* Send START condition */
- I2C_GenerateSTART(I2C1, ENABLE);
-
- /* Test on EV5 and clear it */
- while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT));
-
- /* Send EEPROM address for write */
- I2C_Send7bitAddress(I2C1, EEPROM_ADDRESS, I2C_Direction_Transmitter);
-
- /* Test on EV6 and clear it */
- while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
- /* Send the EEPROM's internal address to write to */
- I2C_SendData(I2C1, WriteAddr);
- /* Test on EARM and clear it */
- while(! I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
- /* While there is data to be written */
- while(NumByteToWrite--)
- {
- /* Send the current byte */
- I2C_SendData(I2C1, *pBuffer);
- /* Point to the next byte to be written */
- pBuffer++;
-
- /* Test on EARM and clear it */
- while (!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
- }
- /* Send STOP condition */
- I2C_GenerateSTOP(I2C1, ENABLE);
- }
复制代码 |
|