微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > STM32的I2C-EEPROM已调试成功

STM32的I2C-EEPROM已调试成功

时间:11-17 来源:互联网 点击:

if(NumByteToRead == 1)
{
/* Send STOP Condition */
I2C_GenerateSTOP(I2C1, ENABLE);//产生 I2Cx传输 STOP条件
}

/* Read a byte from the EEPROM */
*pBuffer = I2C_ReceiveData(I2C1);//返回通过 I2Cx最近接收的数据

/* Point to the next location where the byte read will be saved */
pBuffer++;

/* Decrement the read bytes counter */
NumByteToRead--;
}
}

/* Enable Acknowledgement to be ready for another reception */
I2C_AcknowledgeConfig(I2C1, ENABLE);//使能或者失能指定 I2C的应答功能
}

/*******************************************************************************
* Function Name : I2C_EE_WaitEepromStandbyState
* Description : Wait for EEPROM Standby state
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void I2C_EE_WaitEepromStandbyState(void) //EEPROM设为待命状态
{
vu16 SR1_Tmp = 0;

do
{
/* Send START condition */
I2C_GenerateSTART(I2C1, ENABLE);//产生 I2Cx传输 START条件
/* Read I2C1 SR1 register */
SR1_Tmp = I2C_ReadRegister(I2C1, I2C_Register_SR1);//读取指定的 I2C寄存器 I2C_SR1 并返回其值
/* Send EEPROM address for write */
I2C_Send7bitAddress(I2C1, EEPROM_ADDRESS, I2C_Direction_Transmitter);//向指定的从 I2C设备传送地址字 ,选择发送方向
}while(!(I2C_ReadRegister(I2C1, I2C_Register_SR1) & 0x0002));//地址发送结束
/* Clear AF flag */
I2C_ClearFlag(I2C1, I2C_FLAG_AF);//清除 I2Cx的应答错误标志位


Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top