高中生
最后登录1970-1-1
在线时间 小时
注册时间2017-3-9
|
void IIC_EE_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
I2C_InitTypeDef I2C_InitStructure;
EEPROM_I2C_GPIO_APBxClkCmd(EEPROM_I2C_GPIO_CLK, ENABLE);
EEPROM_I2C_APBxClkCmd(EEPROM_I2C_CLK,ENABLE);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
GPIO_InitStructure.GPIO_Pin = EEPROM_I2C_SDA_GPIO_PIN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(EEPROM_I2C_SDA_GPIO_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
GPIO_InitStructure.GPIO_Pin = EEPROM_I2C_SCL_GPIO_PIN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(EEPROM_I2C_SCL_GPIO_PORT, &GPIO_InitStructure);
I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
I2C_InitStructure.I2C_ClockSpeed = EEPROM_I2C_BAUDRATE;
I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
I2C_InitStructure.I2C_OwnAddress1 = STM32_IIC_ADDR;
I2C_Init(EEPROM_I2C, &I2C_InitStructure);
I2C_Cmd(EEPROM_I2C,ENABLE);
}
void EEPROM_Write_Byte(uint8_t Addr,uint8_t Date)
{
I2C_GenerateSTART(EEPROM_I2C,ENABLE);
while(!I2C_CheckEvent(EEPROM_I2C, I2C_EVENT_MASTER_MODE_SELECT));
I2C_Send7bitAddress(EEPROM_I2C,EEPROM_ADDR,I2C_Direction_Transmitter);
while(I2C_CheckEvent(EEPROM_I2C,I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED) == ERROR);
I2C_SendData(EEPROM_I2C,Addr);
while(I2C_CheckEvent(EEPROM_I2C,I2C_EVENT_MASTER_BYTE_TRANSMITTING) == ERROR);
I2C_SendData(EEPROM_I2C,Date);
while(I2C_CheckEvent(EEPROM_I2C,I2C_EVENT_MASTER_BYTE_TRANSMITTING) == ERROR);
I2C_GenerateSTOP(EEPROM_I2C,ENABLE);
}
上面那些宏定义我查了几遍没查出问题。
但程序死在这个while这里,也就是说发送启动信号不成功。
I2C_GenerateSTART(EEPROM_I2C,ENABLE);
while(!I2C_CheckEvent(EEPROM_I2C, I2C_EVENT_MASTER_MODE_SELECT));
求指导 |
|