2019-09-19 08:54 PM
here is the read 16 bytes register code
uint16_t TMP_ReadConfReg(void)
{
__IO uint16_t RegValue = 0;
/* Enable LM75_I2C acknowledgement if it is already disabled by other function */
I2C_AcknowledgeConfig(LM75_I2C, ENABLE);
/*----------------------------- Transmission Phase --------------------------*/
/* Send LM75_I2C START condition */
I2C_GenerateSTART(LM75_I2C, ENABLE);
/* Test on LM75_I2C EV5 and clear it */
while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_MODE_SELECT)) /* EV5 */
{
}
/* Send STLM75 slave address for write */
I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Transmitter);
/* Test on LM75_I2C EV6 and clear it */
while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)) /* EV6 */
{
}
/* Send the configuration register data pointer */
I2C_SendData(LM75_I2C, LM75_REG_CONF);
/* Test on LM75_I2C EV8 and clear it */
while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_BYTE_TRANSMITTED)) /* EV8 */
{
}
/*----------------------------- Reception Phase -----------------------------*/
/* Send Re-STRAT condition */
I2C_GenerateSTART(LM75_I2C, ENABLE);
/* Test on EV5 and clear it */
while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_MODE_SELECT)) /* EV5 */
{
}
/* Send STLM75 slave address for read */
I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Receiver);
/* Test on EV6 and clear it */
while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED)) /* EV6 */
{
}
//while (I2C_GetFlagStatus(LM75_I2C, I2C_FLAG_RXNE) == RESET);
while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_BYTE_RECEIVED)) /* EV7 */
{
}
/* Store LM75_I2C received data */
RegValue = I2C_ReceiveData(LM75_I2C) << 8;
/* Disable LM75_I2C acknowledgement */
I2C_AcknowledgeConfig(LM75_I2C, DISABLE);
/* Send LM75_I2C STOP Condition */
I2C_GenerateSTOP(LM75_I2C, ENABLE);
/* Test on RXNE flag */
while (I2C_GetFlagStatus(LM75_I2C, I2C_FLAG_RXNE) == RESET);
/* Store LM75_I2C received data */
RegValue |= I2C_ReceiveData(LM75_I2C);
/* Return configuration register value */
return (RegValue);
}
if i call TMP_ReadConfReg first , then code frozen , loop at while (I2C_GetFlagStatus(LM75_I2C, I2C_FLAG_RXNE) == RESET);
if i write configure register first , then TMP_ReadConfReg return ok