123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714 |
- /**
- ******************************************************************************
- * @file stm320518_eval_i2c_tsensor.c
- * @author MCD Application Team
- * @version V1.0.0
- * @date 20-April-2012
- * @brief This file provides a set of functions needed to manage the I2C LM75
- * temperature sensor mounted on STM320518-EVAL board.
- * It implements a high level communication layer for read and write
- * from/to this sensor. The needed STM32F0xx hardware resources (I2C and
- * GPIO) are defined in stm320518_eval.h file, and the initialization is
- * performed in LM75_LowLevel_Init() function declared in stm320518_eval.c
- * file.
- * You can easily tailor this driver to any other development board,
- * by just adapting the defines for hardware resources and
- * LM75_LowLevel_Init() function.
- *
- * +-----------------------------------------------------------------+
- * | Pin assignment |
- * +---------------------------------------+-----------+-------------+
- * | STM32F0xx I2C Pins | STLM75 | Pin |
- * +---------------------------------------+-----------+-------------+
- * | LM75_I2C_SDA_PIN/ SDA | SDA | 1 |
- * | LM75_I2C_SCL_PIN/ SCL | SCL | 2 |
- * | LM75_I2C_SMBUSALERT_PIN/ SMBUS ALERT | OS/INT | 3 |
- * | . | GND | 4 (0V) |
- * | . | GND | 5 (0V) |
- * | . | GND | 6 (0V) |
- * | . | GND | 7 (0V) |
- * | . | VDD | 8 (3.3V)|
- * +---------------------------------------+-----------+-------------+
- ******************************************************************************
- * @attention
- *
- * <h2><center>© COPYRIGHT 2012 STMicroelectronics</center></h2>
- *
- * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
- * You may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.st.com/software_license_agreement_liberty_v2
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************
- */
- /* Includes ------------------------------------------------------------------*/
- #include "stm320518_eval_i2c_tsensor.h"
- /** @addtogroup Utilities
- * @{
- */
-
- /** @addtogroup STM32_EVAL
- * @{
- */
- /** @addtogroup STM320518_EVAL
- * @{
- */
-
- /** @addtogroup STM320518_EVAL_I2C_TSENSOR
- * @brief This file includes the LM75 Temperature Sensor driver of
- * STM320518-EVAL boards.
- * @{
- */
- /** @defgroup STM320518_EVAL_I2C_TSENSOR_Private_Types
- * @{
- */
- /**
- * @}
- */
- /** @defgroup STM320518_EVAL_I2C_TSENSOR_Private_Defines
- * @{
- */
- #define LM75_SD_SET 0x01 /*!< Set SD bit in the configuration register */
- #define LM75_SD_RESET 0xFE /*!< Reset SD bit in the configuration register */
- /**
- * @}
- */
- /** @defgroup STM320518_EVAL_I2C_TSENSOR_Private_Macros
- * @{
- */
- /**
- * @}
- */
-
- /** @defgroup STM320518_EVAL_I2C_TSENSOR_Private_Variables
- * @{
- */
-
- __IO uint32_t LM75_Timeout = LM75_LONG_TIMEOUT;
- /**
- * @}
- */
- /** @defgroup STM320518_EVAL_I2C_TSENSOR_Private_Function_Prototypes
- * @{
- */
- /**
- * @}
- */
- /** @defgroup STM320518_EVAL_I2C_TSENSOR_Private_Functions
- * @{
- */
- /**
- * @brief DeInitializes the LM75_I2C.
- * @param None
- * @retval None
- */
- void LM75_DeInit(void)
- {
- LM75_LowLevel_DeInit();
- }
- /**
- * @brief Initializes the LM75_I2C.
- * @param None
- * @retval None
- */
- void LM75_Init(void)
- {
- I2C_InitTypeDef I2C_InitStructure;
-
- LM75_LowLevel_Init();
-
- /* LM75_I2C configuration */
- I2C_InitStructure.I2C_Mode = I2C_Mode_SMBusHost;
- I2C_InitStructure.I2C_AnalogFilter = I2C_AnalogFilter_Enable;
- I2C_InitStructure.I2C_DigitalFilter = 0x00;
- I2C_InitStructure.I2C_OwnAddress1 = 0x00;
- I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
- I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
- I2C_InitStructure.I2C_Timing = LM75_I2C_TIMING;
-
- /* Apply LM75_I2C configuration after enabling it */
- I2C_Init(LM75_I2C, &I2C_InitStructure);
-
- /* LM75_I2C Peripheral Enable */
- I2C_Cmd(LM75_I2C, ENABLE);
- }
- /**
- * @brief Checks the LM75 status.
- * @param None
- * @retval ErrorStatus: LM75 Status (ERROR or SUCCESS).
- */
- ErrorStatus LM75_GetStatus(void)
- {
- uint32_t I2C_TimeOut = I2C_TIMEOUT;
-
- /* Configure slave address, nbytes, reload, end mode and start or stop generation */
- I2C_TransferHandling(LM75_I2C, LM75_ADDR, 0, I2C_AutoEnd_Mode, I2C_No_StartStop);
-
- /* Clear NACKF and STOPF */
- I2C_ClearFlag(LM75_I2C, I2C_ICR_NACKCF | I2C_ICR_STOPCF);
-
- /* Generate start */
- I2C_GenerateSTART(LM75_I2C, ENABLE);
-
- /* Wait until timeout elapsed */
- while ((I2C_GetFlagStatus(LM75_I2C, I2C_ISR_STOPF) == RESET) && (I2C_TimeOut-- != 0));
-
- /* Check if Temp sensor is ready for use */
- if ((I2C_GetFlagStatus(LM75_I2C, I2C_ISR_NACKF) != RESET) || (I2C_TimeOut == 0))
- {
- /* Clear NACKF and STOPF */
- I2C_ClearFlag(LM75_I2C, I2C_ICR_NACKCF | I2C_ICR_STOPCF);
-
- return ERROR;
- }
- else
- {
- /* Clear STOPF */
- I2C_ClearFlag(LM75_I2C, I2C_ICR_STOPCF);
-
- return SUCCESS;
- }
- }
- /**
- * @brief Read the specified register from the LM75.
- * @param RegName: specifies the LM75 register to be read.
- * This parameter can be one of the following values:
- * @arg LM75_REG_TEMP: temperature register
- * @arg LM75_REG_TOS: Over-limit temperature register
- * @arg LM75_REG_THYS: Hysteresis temperature register
- * @retval LM75 register value.
- */
- uint16_t LM75_ReadReg(uint8_t RegName)
- {
- uint8_t LM75_BufferRX[2] ={0,0};
- uint16_t tmp = 0;
- uint32_t DataNum = 0;
-
- /* Test on BUSY Flag */
- LM75_Timeout = LM75_LONG_TIMEOUT;
- while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_BUSY) != RESET)
- {
- if((LM75_Timeout--) == 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 */
- LM75_Timeout = LM75_LONG_TIMEOUT;
- while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_TXIS) == RESET)
- {
- if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
- }
-
- /* Send Register address */
- I2C_SendData(LM75_I2C, (uint8_t)RegName);
-
- /* Wait until TC flag is set */
- LM75_Timeout = LM75_LONG_TIMEOUT;
- while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_TC) == RESET)
- {
- if((LM75_Timeout--) == 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 */
- LM75_Timeout = LM75_LONG_TIMEOUT;
- while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_RXNE) == RESET)
- {
- if((LM75_Timeout--) == 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 */
- LM75_Timeout = LM75_LONG_TIMEOUT;
- while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_STOPF) == RESET)
- {
- if((LM75_Timeout--) == 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 a Reg value */
- return (uint16_t)tmp;
- }
- /**
- * @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 */
- LM75_Timeout = LM75_LONG_TIMEOUT;
- while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_BUSY) != RESET)
- {
- if((LM75_Timeout--) == 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 */
- LM75_Timeout = LM75_LONG_TIMEOUT;
- while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_TXIS) == RESET)
- {
- if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
- }
-
- /* Send Register address */
- I2C_SendData(LM75_I2C, (uint8_t)RegName);
-
- /* Wait until TCR flag is set */
- LM75_Timeout = LM75_LONG_TIMEOUT;
- while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_TCR) == RESET)
- {
- if((LM75_Timeout--) == 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 */
- LM75_Timeout = LM75_LONG_TIMEOUT;
- while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_TXIS) == RESET)
- {
- if((LM75_Timeout--) == 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 */
- LM75_Timeout = LM75_LONG_TIMEOUT;
- while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_STOPF) == RESET)
- {
- if((LM75_Timeout--) == 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 */
- LM75_Timeout = LM75_LONG_TIMEOUT;
- while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_BUSY) != RESET)
- {
- if((LM75_Timeout--) == 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 */
- LM75_Timeout = LM75_LONG_TIMEOUT;
- while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_TXIS) == RESET)
- {
- if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
- }
-
- /* Send Register address */
- I2C_SendData(LM75_I2C, (uint8_t)LM75_REG_TEMP);
-
- /* Wait until TC flag is set */
- LM75_Timeout = LM75_LONG_TIMEOUT;
- while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_TC) == RESET)
- {
- if((LM75_Timeout--) == 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 */
- LM75_Timeout = LM75_LONG_TIMEOUT;
- while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_RXNE) == RESET)
- {
- if((LM75_Timeout--) == 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 */
- LM75_Timeout = LM75_LONG_TIMEOUT;
- while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_STOPF) == RESET)
- {
- if((LM75_Timeout--) == 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 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_ISR_BUSY) != RESET)
- {
- if((LM75_Timeout--) == 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 */
- LM75_Timeout = LM75_LONG_TIMEOUT;
- while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_TXIS) == RESET)
- {
- if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
- }
-
- /* Send Register address */
- I2C_SendData(LM75_I2C, (uint8_t)LM75_REG_CONF);
-
- /* Wait until TC flag is set */
- LM75_Timeout = LM75_LONG_TIMEOUT;
- while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_TC) == RESET)
- {
- if((LM75_Timeout--) == 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 */
- LM75_Timeout = LM75_LONG_TIMEOUT;
- while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_RXNE) == RESET)
- {
- if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
- }
-
- /* Read data from RXDR */
- LM75_BufferRX[0]= I2C_ReceiveData(LM75_I2C);
-
- /* Wait until STOPF flag is set */
- LM75_Timeout = LM75_LONG_TIMEOUT;
- while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_STOPF) == RESET)
- {
- if((LM75_Timeout--) == 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 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 */
- LM75_Timeout = LM75_LONG_TIMEOUT;
- while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_BUSY) != RESET)
- {
- if((LM75_Timeout--) == 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 */
- LM75_Timeout = LM75_LONG_TIMEOUT;
- while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_TXIS) == RESET)
- {
- if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
- }
-
- /* Send Register address */
- I2C_SendData(LM75_I2C, (uint8_t)LM75_REG_CONF);
-
- /* Wait until TCR flag is set */
- LM75_Timeout = LM75_LONG_TIMEOUT;
- while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_TCR) == RESET)
- {
- if((LM75_Timeout--) == 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 */
- LM75_Timeout = LM75_LONG_TIMEOUT;
- while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_TXIS) == RESET)
- {
- if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
- }
-
- /* Write data to TXDR */
- I2C_SendData(LM75_I2C, (uint8_t)LM75_BufferTX);
-
- /* Wait until STOPF flag is set */
- LM75_Timeout = LM75_LONG_TIMEOUT;
- while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_STOPF) == RESET)
- {
- if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
- }
-
- /* Clear STOPF flag */
- I2C_ClearFlag(LM75_I2C, I2C_ICR_STOPCF);
-
- return LM75_OK;
- }
- /**
- * @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_ISR_BUSY) != RESET)
- {
- if((LM75_Timeout--) == 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 */
- LM75_Timeout = LM75_LONG_TIMEOUT;
- while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_TXIS) == RESET)
- {
- if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
- }
-
- /* Send Register address */
- I2C_SendData(LM75_I2C, (uint8_t)LM75_REG_CONF);
-
- /* Wait until TC flag is set */
- LM75_Timeout = LM75_LONG_TIMEOUT;
- while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_TC) == RESET)
- {
- if((LM75_Timeout--) == 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 */
- LM75_Timeout = LM75_LONG_TIMEOUT;
- while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_RXNE) == RESET)
- {
- if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
- }
-
- /* Read data from RXDR */
- LM75_BufferRX[0]= I2C_ReceiveData(LM75_I2C);
-
- /* Wait until STOPF flag is set */
- LM75_Timeout = LM75_LONG_TIMEOUT;
- while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_STOPF) == RESET)
- {
- if((LM75_Timeout--) == 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 */
- LM75_Timeout = LM75_LONG_TIMEOUT;
- while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_BUSY) != RESET)
- {
- if((LM75_Timeout--) == 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 */
- LM75_Timeout = LM75_LONG_TIMEOUT;
- while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_TXIS) == RESET)
- {
- if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
- }
-
- /* Send Register address */
- I2C_SendData(LM75_I2C, (uint8_t)LM75_REG_CONF);
-
- /* Wait until TCR flag is set */
- LM75_Timeout = LM75_LONG_TIMEOUT;
- while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_TCR) == RESET)
- {
- if((LM75_Timeout--) == 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 */
- LM75_Timeout = LM75_LONG_TIMEOUT;
- while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_TXIS) == RESET)
- {
- if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
- }
-
- /* Write data to TXDR */
- I2C_SendData(LM75_I2C, (uint8_t)LM75_BufferTX);
-
- /* Wait until STOPF flag is set */
- LM75_Timeout = LM75_LONG_TIMEOUT;
- while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_STOPF) == RESET)
- {
- if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
- }
-
- /* Clear STOPF flag */
- I2C_ClearFlag(LM75_I2C, I2C_ICR_STOPCF);
-
- return LM75_OK;
- }
- /**
- * @}
- */
- /**
- * @}
- */
- /**
- * @}
- */
- /**
- * @}
- */
- /**
- * @}
- */
- /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|