/**
  * @brief  Write to the configuration register of the LM75.
  * @param  RegValue: specifies the value to be written to LM75 configuration 
  *         register.
  * @retval None
  */
uint8_t LM75_WriteConfReg(uint8_t RegValue)
{   
  uint8_t LM75_BufferTX = 0;  
  
  LM75_BufferTX = (uint8_t)(RegValue);
  
  /* Test on BUSY Flag */
  LM75Timeout = LM75_LONG_TIMEOUT;
  while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_BUSY) != RESET) 
  {
    if((LM75Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }
  
  /* Configure slave address, nbytes, reload, end mode and start or stop generation */
  I2C_TransferHandling(LM75_I2C, LM75_ADDR, 1, I2C_Reload_Mode, I2C_Generate_Start_Write);
  
  /* Wait until TXIS flag is set */
  LM75Timeout = LM75_LONG_TIMEOUT;  
  while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_TXIS) == RESET)
  {
    if((LM75Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }
  
  /* Send Register address */
  I2C_SendData(LM75_I2C, (uint8_t)LM75_REG_CONF);
  
  /* Wait until TCR flag is set */
  LM75Timeout = LM75_LONG_TIMEOUT;
  while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_TCR) == RESET)
  {
    if((LM75Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }
  
  /* Configure slave address, nbytes, reload, end mode and start or stop generation */
  I2C_TransferHandling(LM75_I2C, LM75_ADDR, 1, I2C_AutoEnd_Mode, I2C_No_StartStop);
  
  /* Wait until TXIS flag is set */
  LM75Timeout = LM75_LONG_TIMEOUT;
  while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_TXIS) == RESET)
  {
    if((LM75Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }  
  
  /* Write data to TXDR */
  I2C_SendData(LM75_I2C, (uint8_t)LM75_BufferTX);
  
  /* Wait until STOPF flag is set */
  LM75Timeout = LM75_LONG_TIMEOUT;
  while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_STOPF) == RESET)
  {
    if((LM75Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }   
  
  /* Clear STOPF flag */
  I2C_ClearFlag(LM75_I2C, I2C_ICR_STOPCF);
    
  return LM75_OK;  
}
/**
  * @brief  Read the configuration register from the LM75.
  * @param  None
  * @retval LM75 configuration register value.
  */
uint8_t LM75_ReadConfReg(void)
{   
  uint8_t LM75_BufferRX[2] ={0,0}; 
  
  /* Test on BUSY Flag */
  LM75Timeout = LM75_LONG_TIMEOUT;
  while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_BUSY) != RESET)
  {
    if((LM75Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }
  
  /* Configure slave address, nbytes, reload, end mode and start or stop generation */
  I2C_TransferHandling(LM75_I2C, LM75_ADDR, 1, I2C_SoftEnd_Mode, I2C_Generate_Start_Write);
  
  /* Wait until TXIS flag is set */
  LM75Timeout = LM75_LONG_TIMEOUT;
  while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_TXIS) == RESET)
  {
    if((LM75Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }
  
  /* Send Register address */
  I2C_SendData(LM75_I2C, (uint8_t)LM75_REG_CONF);
  
  /* Wait until TC flag is set */
  LM75Timeout = LM75_LONG_TIMEOUT;
  while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_TC) == RESET)
  {
    if((LM75Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }  
  
  /* Configure slave address, nbytes, reload, end mode and start or stop generation */
  I2C_TransferHandling(LM75_I2C, LM75_ADDR, 1, I2C_AutoEnd_Mode, I2C_Generate_Start_Read);
  
  /* Wait until RXNE flag is set */
  LM75Timeout = LM75_LONG_TIMEOUT;  
  while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_RXNE) == RESET)  
  {
    if((LM75Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }
  
  /* Read data from RXDR */
  LM75_BufferRX[0]= I2C_ReceiveData(LM75_I2C);  
  
  /* Wait until STOPF flag is set */
  LM75Timeout = LM75_LONG_TIMEOUT;
  while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_STOPF) == RESET) 
  {
    if((LM75Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }
  
  /* Clear STOPF flag */
  I2C_ClearFlag(LM75_I2C, I2C_ICR_STOPCF);
  
  /* Return Register value */
  return (uint8_t)LM75_BufferRX[0];
}
/**
  * @brief  Enables or disables the LM75.
  * @param  NewState: specifies the LM75 new status. This parameter can be ENABLE
  *         or DISABLE.  
  * @retval None
  */
uint8_t LM75_ShutDown(FunctionalState NewState)
{   
  uint8_t LM75_BufferRX[2] ={0,0};
  uint8_t LM75_BufferTX = 0;
  __IO uint8_t RegValue = 0;    
  
  /* Test on BUSY Flag */
  LM75_Timeout = LM75_LONG_TIMEOUT;
  while (I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BUSY)) 
  {
    if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }
  
  /* Configure DMA Peripheral */
  LM75_DMA_Config(LM75_DMA_RX, (uint8_t*)LM75_BufferRX, 2);  
  
  /* Enable DMA NACK automatic generation */
  I2C_DMALastTransferCmd(LM75_I2C, ENABLE);
  
  /* Enable the I2C peripheral */
  I2C_GenerateSTART(LM75_I2C, ENABLE);
  
  /* Test on SB Flag */
  LM75_Timeout = LM75_FLAG_TIMEOUT;
  while (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_SB)) 
  {
    if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }
  
  /* Send device address for write */
  I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Transmitter);
  
  /* Test on ADDR Flag */
  LM75_Timeout = LM75_FLAG_TIMEOUT;
  while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)) 
  {
    if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }
  
  /* Send the device's internal address to write to */
  I2C_SendData(LM75_I2C, LM75_REG_CONF);  
  
  /* Test on TXE FLag (data sent) */
  LM75_Timeout = LM75_FLAG_TIMEOUT;
  while ((!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_TXE)) && (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BTF)))  
  {
    if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }
  
  /* Send START condition a second time */  
  I2C_GenerateSTART(LM75_I2C, ENABLE);
  
  /* Test on SB Flag */
  LM75_Timeout = LM75_FLAG_TIMEOUT;
  while (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_SB)) 
  {
    if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }
  
  /* Send LM75 address for read */
  I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Receiver);
  
  /* Test on ADDR Flag */
  LM75_Timeout = LM75_FLAG_TIMEOUT;
  while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED))   
  {
    if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }
  
  /* Enable I2C DMA request */
  I2C_DMACmd(LM75_I2C,ENABLE);
  
  /* Enable DMA RX Channel */
  DMA_Cmd(LM75_DMA_RX_CHANNEL, ENABLE);
  
  /* Wait until DMA Transfer Complete */
  LM75_Timeout = LM75_LONG_TIMEOUT;
  while (!DMA_GetFlagStatus(LM75_DMA_RX_TCFLAG))
  {
    if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }        
  
  /* Send STOP Condition */
  I2C_GenerateSTOP(LM75_I2C, ENABLE);
  
  /* Disable DMA RX Channel */
  DMA_Cmd(LM75_DMA_RX_CHANNEL, DISABLE);
  
  /* Disable I2C DMA request */  
  I2C_DMACmd(LM75_I2C,DISABLE);
  
  /* Clear DMA RX Transfer Complete Flag */
  DMA_ClearFlag(LM75_DMA_RX_TCFLAG);
  
  /*!< Get received data */
  RegValue = (uint8_t)LM75_BufferRX[0];
  
  /*---------------------------- Transmission Phase ---------------------------*/
  
  /*!< Enable or disable SD bit */
  if (NewState != DISABLE)
  {
    /*!< Enable LM75 */
    LM75_BufferTX = RegValue & LM75_SD_RESET;
  }
  else
  {
    /*!< Disable LM75 */
    LM75_BufferTX = RegValue | LM75_SD_SET;
  }  
  
  /* Test on BUSY Flag */
  LM75_Timeout = LM75_LONG_TIMEOUT;
  while (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BUSY)) 
  {
    if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }
  
  /* Configure DMA Peripheral */
  LM75_DMA_Config(LM75_DMA_TX, (uint8_t*)(&LM75_BufferTX), 1);
  
  /* Enable the I2C peripheral */
  I2C_GenerateSTART(LM75_I2C, ENABLE);
  
  /* Test on SB Flag */
  LM75_Timeout = LM75_FLAG_TIMEOUT;
  while (I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_SB) == RESET) 
  {
    if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }
  
  /* Transmit the slave address and enable writing operation */
  I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Transmitter);
  
  /* Test on ADDR Flag */
  LM75_Timeout = LM75_FLAG_TIMEOUT;
  while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED))
  {
    if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }
  
  /* Transmit the first address for r/w operations */
  I2C_SendData(LM75_I2C, LM75_REG_CONF);
  
  /* Test on TXE FLag (data sent) */
  LM75_Timeout = LM75_FLAG_TIMEOUT;
  while ((!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_TXE)) && (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BTF)))  
  {
    if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }
  
  /* Enable I2C DMA request */
  I2C_DMACmd(LM75_I2C,ENABLE);
  
  /* Enable DMA TX Channel */
  DMA_Cmd(LM75_DMA_TX_CHANNEL, ENABLE);
  
  /* Wait until DMA Transfer Complete */
  LM75_Timeout = LM75_LONG_TIMEOUT;
  while (!DMA_GetFlagStatus(LM75_DMA_TX_TCFLAG))
  {
    if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }  
  
  /* Wait until BTF Flag is set before generating STOP */
  LM75_Timeout = LM75_LONG_TIMEOUT;
  while ((!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BTF)))  
  {
    if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }
  
  /* Send STOP Condition */
  I2C_GenerateSTOP(LM75_I2C, ENABLE);
  
  /* Disable DMA TX Channel */
  DMA_Cmd(LM75_DMA_TX_CHANNEL, DISABLE);
  
  /* Disable I2C DMA request */  
  I2C_DMACmd(LM75_I2C,DISABLE);
  
  /* Clear DMA TX Transfer Complete Flag */
  DMA_ClearFlag(LM75_DMA_TX_TCFLAG);  
  
  return LM75_OK;
}
/**
  * @brief  Write to the configuration register of the LM75.
  * @param  RegValue: sepecifies the value to be written to LM75 configuration 
  *         register.
  * @retval None
  */
uint8_t LM75_WriteConfReg(uint8_t RegValue)
{   
  uint8_t LM75_BufferTX = 0;  
  LM75_BufferTX = (uint8_t)(RegValue);
  
  /* Test on BUSY Flag */
  LM75_Timeout = LM75_LONG_TIMEOUT;
  while (I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BUSY)) 
  {
    if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }
  
  /* Configure DMA Peripheral */
  LM75_DMA_Config(LM75_DMA_TX, (uint8_t*)(&LM75_BufferTX), 1);
  
  /* Enable the I2C peripheral */
  I2C_GenerateSTART(LM75_I2C, ENABLE);
  
  /* Test on SB Flag */
  LM75_Timeout = LM75_FLAG_TIMEOUT;
  while (I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_SB) == RESET) 
  {
    if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }
  
  /* Transmit the slave address and enable writing operation */
  I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Transmitter);
  
  /* Test on ADDR Flag */
  LM75_Timeout = LM75_FLAG_TIMEOUT;
  while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED))
  {
    if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }
  
  /* Transmit the first address for r/w operations */
  I2C_SendData(LM75_I2C, LM75_REG_CONF);
  
  /* Test on TXE FLag (data sent) */
  LM75_Timeout = LM75_FLAG_TIMEOUT;
  while ((!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_TXE)) && (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BTF)))  
  {
    if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }
  
  /* Enable I2C DMA request */
  I2C_DMACmd(LM75_I2C,ENABLE);
  
  /* Enable DMA TX Channel */
  DMA_Cmd(LM75_DMA_TX_CHANNEL, ENABLE);
  
  /* Wait until DMA Transfer Complete */
  LM75_Timeout = LM75_LONG_TIMEOUT;
  while (!DMA_GetFlagStatus(LM75_DMA_TX_TCFLAG))
  {
    if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }  
  
  /* Wait until BTF Flag is set before generating STOP */
  LM75_Timeout = LM75_LONG_TIMEOUT;
  while ((!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BTF)))  
  {
    if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }
  
  /* Send STOP Condition */
  I2C_GenerateSTOP(LM75_I2C, ENABLE);
  
  /* Disable DMA TX Channel */
  DMA_Cmd(LM75_DMA_TX_CHANNEL, DISABLE);
  
  /* Disable I2C DMA request */  
  I2C_DMACmd(LM75_I2C,DISABLE);
  
  /* Clear DMA TX Transfer Complete Flag */
  DMA_ClearFlag(LM75_DMA_TX_TCFLAG);  
  
  return LM75_OK;
  
}
/**
  * @brief  Read the configuration register from the LM75.
  * @param  None
  * @retval LM75 configuration register value.
  */
uint8_t LM75_ReadConfReg(void)
{   
  uint8_t LM75_BufferRX[2] ={0,0}; 
  
  /* Test on BUSY Flag */
  LM75_Timeout = LM75_LONG_TIMEOUT;
  while (I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BUSY)) 
  {
    if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }
  
  /* Configure DMA Peripheral */
  LM75_DMA_Config(LM75_DMA_RX, (uint8_t*)LM75_BufferRX, 2);  
  
  /* Enable DMA NACK automatic generation */
  I2C_DMALastTransferCmd(LM75_I2C, ENABLE);
  
  /* Enable the I2C peripheral */
  I2C_GenerateSTART(LM75_I2C, ENABLE);
  
  /* Test on SB Flag */
  LM75_Timeout = LM75_FLAG_TIMEOUT;
  while (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_SB)) 
  {
    if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }
  
  /* Send device address for write */
  I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Transmitter);
  
  /* Test on ADDR Flag */
  LM75_Timeout = LM75_FLAG_TIMEOUT;
  while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)) 
  {
    if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }
  
  /* Send the device's internal address to write to */
  I2C_SendData(LM75_I2C, LM75_REG_CONF);  
  
  /* Test on TXE FLag (data sent) */
  LM75_Timeout = LM75_FLAG_TIMEOUT;
  while ((!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_TXE)) && (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BTF)))  
  {
    if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }
  
  /* Send START condition a second time */  
  I2C_GenerateSTART(LM75_I2C, ENABLE);
  
  /* Test on SB Flag */
  LM75_Timeout = LM75_FLAG_TIMEOUT;
  while (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_SB)) 
  {
    if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }
  
  /* Send LM75 address for read */
  I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Receiver);
  
  /* Test on ADDR Flag */
  LM75_Timeout = LM75_FLAG_TIMEOUT;
  while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED))   
  {
    if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }
  
  /* Enable I2C DMA request */
  I2C_DMACmd(LM75_I2C,ENABLE);
  
  /* Enable DMA RX Channel */
  DMA_Cmd(LM75_DMA_RX_CHANNEL, ENABLE);
  
  /* Wait until DMA Transfer Complete */
  LM75_Timeout = LM75_LONG_TIMEOUT;
  while (!DMA_GetFlagStatus(LM75_DMA_RX_TCFLAG))
  {
    if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }        
  
  /* Send STOP Condition */
  I2C_GenerateSTOP(LM75_I2C, ENABLE);
  
  /* Disable DMA RX Channel */
  DMA_Cmd(LM75_DMA_RX_CHANNEL, DISABLE);
  
  /* Disable I2C DMA request */  
  I2C_DMACmd(LM75_I2C,DISABLE);
  
  /* Clear DMA RX Transfer Complete Flag */
  DMA_ClearFlag(LM75_DMA_RX_TCFLAG);
  
  /*!< Return Temperature value */
  return (uint8_t)LM75_BufferRX[0];
}
/**
  * @brief  Enables or disables the LM75.
  * @param  NewState: specifies the LM75 new status. This parameter can be ENABLE
  *         or DISABLE.  
  * @retval None
  */
uint8_t LM75_ShutDown(FunctionalState NewState)
{   
  uint8_t LM75_BufferRX[2] ={0,0};
  uint8_t LM75_BufferTX = 0;
  __IO uint8_t RegValue = 0;    
  
  /* Test on BUSY Flag */
  LM75Timeout = LM75_LONG_TIMEOUT;
  while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_BUSY) != RESET)
  {
    if((LM75Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }
  
  /* Configure slave address, nbytes, reload, end mode and start or stop generation */
  I2C_TransferHandling(LM75_I2C, LM75_ADDR, 1, I2C_SoftEnd_Mode, I2C_Generate_Start_Write);
  
  /* Wait until TXIS flag is set */
  LM75Timeout = LM75_LONG_TIMEOUT;
  while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_TXIS) == RESET)
  {
    if((LM75Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }
  
  /* Send Register address */
  I2C_SendData(LM75_I2C, (uint8_t)LM75_REG_CONF);
  
  /* Wait until TC flag is set */
  LM75Timeout = LM75_LONG_TIMEOUT;
  while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_TC) == RESET)
  {
    if((LM75Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }  
  
  /* Configure slave address, nbytes, reload, end mode and start or stop generation */
  I2C_TransferHandling(LM75_I2C, LM75_ADDR, 1, I2C_AutoEnd_Mode, I2C_Generate_Start_Read);
  
  /* Wait until RXNE flag is set */
  LM75Timeout = LM75_LONG_TIMEOUT;   
  while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_RXNE) == RESET)
  {
    if((LM75Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }
  
  /* Read data from RXDR */
  LM75_BufferRX[0]= I2C_ReceiveData(LM75_I2C); 
  
  /* Wait until STOPF flag is set */
  LM75Timeout = LM75_LONG_TIMEOUT;
  while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_STOPF) == RESET)
  {
    if((LM75Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }
  
  /* Clear STOPF flag */
  I2C_ClearFlag(LM75_I2C, I2C_ICR_STOPCF);
  
  /* Get received data */
  RegValue = (uint8_t)LM75_BufferRX[0];
  
  /*---------------------------- Transmission Phase ---------------------------*/
  
  /* Enable or disable SD bit */
  if (NewState != DISABLE)
  {
    /* Enable LM75 */
    LM75_BufferTX = RegValue & LM75_SD_RESET;
  }
  else
  {
    /* Disable LM75 */
    LM75_BufferTX = RegValue | LM75_SD_SET;
  }  
  
  /* Test on BUSY Flag */
  LM75Timeout = LM75_LONG_TIMEOUT;
  while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_BUSY) != RESET)
  {
    if((LM75Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }
  
  /* Configure slave address, nbytes, reload, end mode and start or stop generation */
  I2C_TransferHandling(LM75_I2C, LM75_ADDR, 1, I2C_Reload_Mode, I2C_Generate_Start_Write);
  
  /* Wait until TXIS flag is set */
  LM75Timeout = LM75_LONG_TIMEOUT;  
  while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_TXIS) == RESET)
  {
    if((LM75Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }
  
  /* Send Register address */
  I2C_SendData(LM75_I2C, (uint8_t)LM75_REG_CONF);
  
  /* Wait until TCR flag is set */
  LM75Timeout = LM75_LONG_TIMEOUT;
  while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_TCR) == RESET)
  {
    if((LM75Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }
  
  /* Configure slave address, nbytes, reload, end mode and start or stop generation */
  I2C_TransferHandling(LM75_I2C, LM75_ADDR, 1, I2C_AutoEnd_Mode, I2C_No_StartStop);
  
  /* Wait until TXIS flag is set */
  LM75Timeout = LM75_LONG_TIMEOUT;
  while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_TXIS) == RESET)
  {
    if((LM75Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }  
  
  /* Write data to TXDR */
  I2C_SendData(LM75_I2C, (uint8_t)LM75_BufferTX);
  
  /* Wait until STOPF flag is set */
  LM75Timeout = LM75_LONG_TIMEOUT;
  while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_STOPF) == RESET)
  {
    if((LM75Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }   
  
  /* Clear STOPF flag */
  I2C_ClearFlag(LM75_I2C, I2C_ICR_STOPCF);
  
  return LM75_OK;
}
/**
  * @brief  Read Temperature register of LM75: double temperature value.
  * @param  None
  * @retval LM75 measured temperature value.
  */
uint16_t LM75_ReadTemp(void)
{   
  uint8_t LM75_BufferRX[2] ={0,0};
  uint16_t tmp = 0;
  uint32_t DataNum = 0;  
  
  /* Test on BUSY Flag */
  LM75Timeout = LM75_LONG_TIMEOUT;
  while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_BUSY) != RESET)
  {
    if((LM75Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }
  
  /* Configure slave address, nbytes, reload, end mode and start or stop generation */
  I2C_TransferHandling(LM75_I2C, LM75_ADDR, 1, I2C_SoftEnd_Mode, I2C_Generate_Start_Write);
  
  /* Wait until TXIS flag is set */
  LM75Timeout = LM75_LONG_TIMEOUT;
  while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_TXIS) == RESET)
  {
    if((LM75Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }
  
  /* Send Register address */
  I2C_SendData(LM75_I2C, (uint8_t)LM75_REG_TEMP);
  
  /* Wait until TC flag is set */
  LM75Timeout = LM75_LONG_TIMEOUT;
  while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_TC) == RESET)
  {
    if((LM75Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }  
  
  /* Configure slave address, nbytes, reload, end mode and start or stop generation */
  I2C_TransferHandling(LM75_I2C, LM75_ADDR, 2, I2C_AutoEnd_Mode, I2C_Generate_Start_Read);
  
  /* Reset local variable */
  DataNum = 0;
  
  /* Wait until all data are received */
  while (DataNum != 2)
  {
    /* Wait until RXNE flag is set */
    LM75Timeout = LM75_LONG_TIMEOUT;    
    while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_RXNE) == RESET)
    {
      if((LM75Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
    }
    
    /* Read data from RXDR */
    LM75_BufferRX[DataNum]= I2C_ReceiveData(LM75_I2C);
    
    /* Update number of received data */
    DataNum++;
  }    
  
  /* Wait until STOPF flag is set */
  LM75Timeout = LM75_LONG_TIMEOUT;
  while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_STOPF) == RESET)
  {
    if((LM75Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }
  
  /* Clear STOPF flag */
  I2C_ClearFlag(LM75_I2C, I2C_ICR_STOPCF);
  
  /* Store LM75_I2C received data */
  tmp = (uint16_t)(LM75_BufferRX[0] << 8);
  tmp |= LM75_BufferRX[1];    
  
  /* Return Temperature value */
  return (uint16_t)(tmp >> 7);
}
/**
  * @brief  Write to the specified register of the LM75.
  * @param  RegName: specifies the LM75 register to be written.
  *          This parameter can be one of the following values:    
  *            @arg LM75_REG_TOS: Over-limit temperature register
  *            @arg LM75_REG_THYS: Hysteresis temperature register
  * @param  RegValue: value to be written to LM75 register.  
  * @retval None
  */
uint8_t LM75_WriteReg(uint8_t RegName, uint16_t RegValue)
{ 
  uint32_t DataNum = 0;  
  uint8_t LM75_BufferTX[2] ={0,0};
  
  LM75_BufferTX[0] = (uint8_t)(RegValue >> 8);
  LM75_BufferTX[1] = (uint8_t)(RegValue);
  
  /* Test on BUSY Flag */
  LM75Timeout = LM75_LONG_TIMEOUT;
  while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_BUSY) != RESET)
  {
    if((LM75Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }
  
  /* Configure slave address, nbytes, reload, end mode and start or stop generation */
  I2C_TransferHandling(LM75_I2C, LM75_ADDR, 1, I2C_Reload_Mode, I2C_Generate_Start_Write);
  
  /* Wait until TXIS flag is set */
  LM75Timeout = LM75_LONG_TIMEOUT;  
  while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_TXIS) == RESET)   
  {
    if((LM75Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }
  
  /* Send Register address */
  I2C_SendData(LM75_I2C, (uint8_t)RegName);
  
  /* Wait until TCR flag is set */
  LM75Timeout = LM75_LONG_TIMEOUT;
  while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_TCR) == RESET)
  {
    if((LM75Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }
  
  /* Configure slave address, nbytes, reload, end mode and start or stop generation */
  I2C_TransferHandling(LM75_I2C, LM75_ADDR, 2, I2C_AutoEnd_Mode, I2C_No_StartStop);
  
  while (DataNum != 2)
  {      
    /* Wait until TXIS flag is set */
    LM75Timeout = LM75_LONG_TIMEOUT;
    while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_TXIS) == RESET)
    {
      if((LM75Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
    }  
    
    /* Write data to TXDR */
    I2C_SendData(LM75_I2C, (uint8_t)(LM75_BufferTX[DataNum]));
    
    /* Update number of transmitted data */
    DataNum++;   
  }  
  
  /* Wait until STOPF flag is set */
  LM75Timeout = LM75_LONG_TIMEOUT;
  while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_STOPF) == RESET)
  {
    if((LM75Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }   
  
  /* Clear STOPF flag */
  I2C_ClearFlag(LM75_I2C, I2C_ICR_STOPCF);
  
  return LM75_OK;
}