
Example for Bluetooth low energy interface
Dependencies: mbed HC_SR04_Ultrasonic_Library
Sensor_Shield/x_nucleo_iks01a1.c@1:bdbf36f8408d, 2015-05-19 (annotated)
- Committer:
- julientiron
- Date:
- Tue May 19 16:53:44 2015 +0000
- Revision:
- 1:bdbf36f8408d
ddd; ;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
julientiron | 1:bdbf36f8408d | 1 | /** |
julientiron | 1:bdbf36f8408d | 2 | ****************************************************************************** |
julientiron | 1:bdbf36f8408d | 3 | * @file x_nucleo_iks01a1.c |
julientiron | 1:bdbf36f8408d | 4 | * @author MEMS Application Team |
julientiron | 1:bdbf36f8408d | 5 | * @version V1.0.0 |
julientiron | 1:bdbf36f8408d | 6 | * @date 30-July-2014 |
julientiron | 1:bdbf36f8408d | 7 | * @brief This file provides X_NUCLEO_IKS01A1 MEMS shield board specific functions |
julientiron | 1:bdbf36f8408d | 8 | ****************************************************************************** |
julientiron | 1:bdbf36f8408d | 9 | * @attention |
julientiron | 1:bdbf36f8408d | 10 | * |
julientiron | 1:bdbf36f8408d | 11 | * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> |
julientiron | 1:bdbf36f8408d | 12 | * |
julientiron | 1:bdbf36f8408d | 13 | * Redistribution and use in source and binary forms, with or without modification, |
julientiron | 1:bdbf36f8408d | 14 | * are permitted provided that the following conditions are met: |
julientiron | 1:bdbf36f8408d | 15 | * 1. Redistributions of source code must retain the above copyright notice, |
julientiron | 1:bdbf36f8408d | 16 | * this list of conditions and the following disclaimer. |
julientiron | 1:bdbf36f8408d | 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
julientiron | 1:bdbf36f8408d | 18 | * this list of conditions and the following disclaimer in the documentation |
julientiron | 1:bdbf36f8408d | 19 | * and/or other materials provided with the distribution. |
julientiron | 1:bdbf36f8408d | 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
julientiron | 1:bdbf36f8408d | 21 | * may be used to endorse or promote products derived from this software |
julientiron | 1:bdbf36f8408d | 22 | * without specific prior written permission. |
julientiron | 1:bdbf36f8408d | 23 | * |
julientiron | 1:bdbf36f8408d | 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
julientiron | 1:bdbf36f8408d | 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
julientiron | 1:bdbf36f8408d | 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
julientiron | 1:bdbf36f8408d | 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
julientiron | 1:bdbf36f8408d | 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
julientiron | 1:bdbf36f8408d | 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
julientiron | 1:bdbf36f8408d | 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
julientiron | 1:bdbf36f8408d | 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
julientiron | 1:bdbf36f8408d | 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
julientiron | 1:bdbf36f8408d | 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
julientiron | 1:bdbf36f8408d | 34 | * |
julientiron | 1:bdbf36f8408d | 35 | ****************************************************************************** |
julientiron | 1:bdbf36f8408d | 36 | */ |
julientiron | 1:bdbf36f8408d | 37 | /* Includes ------------------------------------------------------------------*/ |
julientiron | 1:bdbf36f8408d | 38 | #include "x_nucleo_iks01a1.h" |
julientiron | 1:bdbf36f8408d | 39 | |
julientiron | 1:bdbf36f8408d | 40 | /** @addtogroup BSP |
julientiron | 1:bdbf36f8408d | 41 | * @{ |
julientiron | 1:bdbf36f8408d | 42 | */ |
julientiron | 1:bdbf36f8408d | 43 | |
julientiron | 1:bdbf36f8408d | 44 | /** @addtogroup X_NUCLEO_IKS01A1 |
julientiron | 1:bdbf36f8408d | 45 | * @{ |
julientiron | 1:bdbf36f8408d | 46 | */ |
julientiron | 1:bdbf36f8408d | 47 | |
julientiron | 1:bdbf36f8408d | 48 | /** @defgroup X_NUCLEO_IKS01A1_Private_Types_Definitions |
julientiron | 1:bdbf36f8408d | 49 | * @{ |
julientiron | 1:bdbf36f8408d | 50 | */ |
julientiron | 1:bdbf36f8408d | 51 | |
julientiron | 1:bdbf36f8408d | 52 | /** |
julientiron | 1:bdbf36f8408d | 53 | * @} |
julientiron | 1:bdbf36f8408d | 54 | */ |
julientiron | 1:bdbf36f8408d | 55 | |
julientiron | 1:bdbf36f8408d | 56 | |
julientiron | 1:bdbf36f8408d | 57 | /** @defgroup X_NUCLEO_IKS01A1_Private_Defines |
julientiron | 1:bdbf36f8408d | 58 | * @{ |
julientiron | 1:bdbf36f8408d | 59 | */ |
julientiron | 1:bdbf36f8408d | 60 | #ifndef NULL |
julientiron | 1:bdbf36f8408d | 61 | #define NULL (void *) 0 |
julientiron | 1:bdbf36f8408d | 62 | #endif |
julientiron | 1:bdbf36f8408d | 63 | /** |
julientiron | 1:bdbf36f8408d | 64 | * @} |
julientiron | 1:bdbf36f8408d | 65 | */ |
julientiron | 1:bdbf36f8408d | 66 | |
julientiron | 1:bdbf36f8408d | 67 | /** @defgroup X_NUCLEO_IKS01A1_Private_Macros |
julientiron | 1:bdbf36f8408d | 68 | * @{ |
julientiron | 1:bdbf36f8408d | 69 | */ |
julientiron | 1:bdbf36f8408d | 70 | |
julientiron | 1:bdbf36f8408d | 71 | /** |
julientiron | 1:bdbf36f8408d | 72 | * @} |
julientiron | 1:bdbf36f8408d | 73 | */ |
julientiron | 1:bdbf36f8408d | 74 | |
julientiron | 1:bdbf36f8408d | 75 | /** @defgroup X_NUCLEO_IKS01A1_Private_Variables |
julientiron | 1:bdbf36f8408d | 76 | * @{ |
julientiron | 1:bdbf36f8408d | 77 | */ |
julientiron | 1:bdbf36f8408d | 78 | |
julientiron | 1:bdbf36f8408d | 79 | uint32_t I2C_SHIELDS_Timeout = NUCLEO_I2C_SHIELDS_TIMEOUT_MAX; /*<! Value of Timeout when I2C communication fails */ |
julientiron | 1:bdbf36f8408d | 80 | |
julientiron | 1:bdbf36f8408d | 81 | static I2C_HandleTypeDef I2C_SHIELDS_Handle; |
julientiron | 1:bdbf36f8408d | 82 | |
julientiron | 1:bdbf36f8408d | 83 | |
julientiron | 1:bdbf36f8408d | 84 | #ifdef USE_FREE_RTOS |
julientiron | 1:bdbf36f8408d | 85 | osMutexId I2C1_Mutex_id = 0; |
julientiron | 1:bdbf36f8408d | 86 | #endif |
julientiron | 1:bdbf36f8408d | 87 | |
julientiron | 1:bdbf36f8408d | 88 | /** |
julientiron | 1:bdbf36f8408d | 89 | * @} |
julientiron | 1:bdbf36f8408d | 90 | */ |
julientiron | 1:bdbf36f8408d | 91 | |
julientiron | 1:bdbf36f8408d | 92 | /** @defgroup X_NUCLEO_IKS01A1_Private_Function_Prototypes |
julientiron | 1:bdbf36f8408d | 93 | * @{ |
julientiron | 1:bdbf36f8408d | 94 | */ |
julientiron | 1:bdbf36f8408d | 95 | |
julientiron | 1:bdbf36f8408d | 96 | /* Link function for 6 Axes IMU peripheral */ |
julientiron | 1:bdbf36f8408d | 97 | void IMU_6AXES_IO_Init(void); |
julientiron | 1:bdbf36f8408d | 98 | void IMU_6AXES_IO_Write(uint8_t* pBuffer, uint8_t DeviceAddr, uint8_t WriteAddr, uint16_t NumByteToWrite); |
julientiron | 1:bdbf36f8408d | 99 | void IMU_6AXES_IO_Read(uint8_t* pBuffer, uint8_t DeviceAddr, uint8_t ReadAddr, uint16_t NumByteToRead); |
julientiron | 1:bdbf36f8408d | 100 | |
julientiron | 1:bdbf36f8408d | 101 | /* Link function for MAGNETO peripheral */ |
julientiron | 1:bdbf36f8408d | 102 | void MAGNETO_IO_Init(void); |
julientiron | 1:bdbf36f8408d | 103 | void MAGNETO_IO_Write(uint8_t* pBuffer, uint8_t DeviceAddr, uint8_t WriteAddr, uint16_t NumByteToWrite); |
julientiron | 1:bdbf36f8408d | 104 | void MAGNETO_IO_Read(uint8_t* pBuffer, uint8_t DeviceAddr, uint8_t ReadAddr, uint16_t NumByteToRead); |
julientiron | 1:bdbf36f8408d | 105 | |
julientiron | 1:bdbf36f8408d | 106 | /* Link function for PRESSURE peripheral */ |
julientiron | 1:bdbf36f8408d | 107 | void PRESSURE_IO_Init(void); |
julientiron | 1:bdbf36f8408d | 108 | void PRESSURE_IO_Write(uint8_t* pBuffer, uint8_t DeviceAddr, uint8_t WriteAddr, uint16_t NumByteToWrite); |
julientiron | 1:bdbf36f8408d | 109 | void PRESSURE_IO_Read(uint8_t* pBuffer, uint8_t DeviceAddr, uint8_t RegisterAddr, uint16_t NumByteToRead); |
julientiron | 1:bdbf36f8408d | 110 | |
julientiron | 1:bdbf36f8408d | 111 | /* Link function for HUM_TEMP peripheral */ |
julientiron | 1:bdbf36f8408d | 112 | void HUM_TEMP_IO_Init(void); |
julientiron | 1:bdbf36f8408d | 113 | void HUM_TEMP_IO_Write(uint8_t* pBuffer, uint8_t DeviceAddr, uint8_t WriteAddr, uint16_t NumByteToWrite); |
julientiron | 1:bdbf36f8408d | 114 | void HUM_TEMP_IO_Read(uint8_t* pBuffer, uint8_t DeviceAddr, uint8_t RegisterAddr, uint16_t NumByteToRead); |
julientiron | 1:bdbf36f8408d | 115 | |
julientiron | 1:bdbf36f8408d | 116 | |
julientiron | 1:bdbf36f8408d | 117 | static void I2C_SHIELDS_MspInit(void); |
julientiron | 1:bdbf36f8408d | 118 | static void I2C_SHIELDS_Error(uint8_t Addr); |
julientiron | 1:bdbf36f8408d | 119 | static void I2C_SHIELDS_ReadData(uint8_t* pBuffer, uint8_t Addr, uint8_t Reg, uint16_t Size); |
julientiron | 1:bdbf36f8408d | 120 | static void I2C_SHIELDS_WriteData(uint8_t* pBuffer, uint8_t Addr, uint8_t Reg, uint16_t Size); |
julientiron | 1:bdbf36f8408d | 121 | static void I2C_SHIELDS_Init(void); |
julientiron | 1:bdbf36f8408d | 122 | |
julientiron | 1:bdbf36f8408d | 123 | /** |
julientiron | 1:bdbf36f8408d | 124 | * @} |
julientiron | 1:bdbf36f8408d | 125 | */ |
julientiron | 1:bdbf36f8408d | 126 | |
julientiron | 1:bdbf36f8408d | 127 | /** @defgroup X_NUCLEO_IKS01A1_Private_Functions |
julientiron | 1:bdbf36f8408d | 128 | * @{ |
julientiron | 1:bdbf36f8408d | 129 | */ |
julientiron | 1:bdbf36f8408d | 130 | |
julientiron | 1:bdbf36f8408d | 131 | |
julientiron | 1:bdbf36f8408d | 132 | |
julientiron | 1:bdbf36f8408d | 133 | /********************************* LINK IMU 6 AXES *****************************/ |
julientiron | 1:bdbf36f8408d | 134 | /** |
julientiron | 1:bdbf36f8408d | 135 | * @brief Configures Imu 6 axes I2C interface. |
julientiron | 1:bdbf36f8408d | 136 | * @param None |
julientiron | 1:bdbf36f8408d | 137 | * @retval None |
julientiron | 1:bdbf36f8408d | 138 | */ |
julientiron | 1:bdbf36f8408d | 139 | void IMU_6AXES_IO_Init(void) |
julientiron | 1:bdbf36f8408d | 140 | { |
julientiron | 1:bdbf36f8408d | 141 | I2C_SHIELDS_Init(); |
julientiron | 1:bdbf36f8408d | 142 | } |
julientiron | 1:bdbf36f8408d | 143 | |
julientiron | 1:bdbf36f8408d | 144 | |
julientiron | 1:bdbf36f8408d | 145 | /** |
julientiron | 1:bdbf36f8408d | 146 | * @brief Writes a buffer to the IMU 6 axes sensor. |
julientiron | 1:bdbf36f8408d | 147 | * @param pBuffer: pointer to data to be written. |
julientiron | 1:bdbf36f8408d | 148 | * @param DeviceAddr: specifies the slave address to be programmed. |
julientiron | 1:bdbf36f8408d | 149 | * @param RegisterAddr: specifies the IMU 6 axes register to be written. |
julientiron | 1:bdbf36f8408d | 150 | * @param NumByteToWrite: number of bytes to be written. |
julientiron | 1:bdbf36f8408d | 151 | * @retval None. |
julientiron | 1:bdbf36f8408d | 152 | */ |
julientiron | 1:bdbf36f8408d | 153 | void IMU_6AXES_IO_Write(uint8_t* pBuffer, uint8_t DeviceAddr, uint8_t RegisterAddr, uint16_t NumByteToWrite) |
julientiron | 1:bdbf36f8408d | 154 | { |
julientiron | 1:bdbf36f8408d | 155 | #ifdef USE_FREE_RTOS |
julientiron | 1:bdbf36f8408d | 156 | NUCLEO_I2C_SHIELDS_MUTEX_TAKE(); |
julientiron | 1:bdbf36f8408d | 157 | #endif |
julientiron | 1:bdbf36f8408d | 158 | |
julientiron | 1:bdbf36f8408d | 159 | /* call I2C_SHIELDS Read data bus function */ |
julientiron | 1:bdbf36f8408d | 160 | I2C_SHIELDS_WriteData(pBuffer, DeviceAddr, RegisterAddr, NumByteToWrite); |
julientiron | 1:bdbf36f8408d | 161 | |
julientiron | 1:bdbf36f8408d | 162 | #ifdef USE_FREE_RTOS |
julientiron | 1:bdbf36f8408d | 163 | NUCLEO_I2C_SHIELDS_MUTEX_RELEASE(); |
julientiron | 1:bdbf36f8408d | 164 | #endif |
julientiron | 1:bdbf36f8408d | 165 | } |
julientiron | 1:bdbf36f8408d | 166 | |
julientiron | 1:bdbf36f8408d | 167 | /** |
julientiron | 1:bdbf36f8408d | 168 | * @brief Reads a buffer from the IMU 6 axes sensor. |
julientiron | 1:bdbf36f8408d | 169 | * @param pBuffer: pointer to data to be read. |
julientiron | 1:bdbf36f8408d | 170 | * @param DeviceAddr: specifies the address of the device. |
julientiron | 1:bdbf36f8408d | 171 | * @param RegisterAddr: specifies the IMU 6 axes internal address register to read from. |
julientiron | 1:bdbf36f8408d | 172 | * @param NumByteToRead: number of bytes to be read. |
julientiron | 1:bdbf36f8408d | 173 | * @retval None. |
julientiron | 1:bdbf36f8408d | 174 | */ |
julientiron | 1:bdbf36f8408d | 175 | void IMU_6AXES_IO_Read(uint8_t* pBuffer, uint8_t DeviceAddr, uint8_t RegisterAddr, uint16_t NumByteToRead) |
julientiron | 1:bdbf36f8408d | 176 | { |
julientiron | 1:bdbf36f8408d | 177 | #ifdef USE_FREE_RTOS |
julientiron | 1:bdbf36f8408d | 178 | NUCLEO_I2C_SHIELDS_MUTEX_TAKE(); |
julientiron | 1:bdbf36f8408d | 179 | #endif |
julientiron | 1:bdbf36f8408d | 180 | |
julientiron | 1:bdbf36f8408d | 181 | /* call I2C_SHIELDS Read data bus function */ |
julientiron | 1:bdbf36f8408d | 182 | I2C_SHIELDS_ReadData(pBuffer, DeviceAddr, RegisterAddr, NumByteToRead); |
julientiron | 1:bdbf36f8408d | 183 | |
julientiron | 1:bdbf36f8408d | 184 | #ifdef USE_FREE_RTOS |
julientiron | 1:bdbf36f8408d | 185 | NUCLEO_I2C_SHIELDS_MUTEX_RELEASE(); |
julientiron | 1:bdbf36f8408d | 186 | #endif |
julientiron | 1:bdbf36f8408d | 187 | } |
julientiron | 1:bdbf36f8408d | 188 | |
julientiron | 1:bdbf36f8408d | 189 | |
julientiron | 1:bdbf36f8408d | 190 | |
julientiron | 1:bdbf36f8408d | 191 | /********************************* LINK MAGNETO *****************************/ |
julientiron | 1:bdbf36f8408d | 192 | /** |
julientiron | 1:bdbf36f8408d | 193 | * @brief Configures MAGNETO I2C interface. |
julientiron | 1:bdbf36f8408d | 194 | * @param None |
julientiron | 1:bdbf36f8408d | 195 | * @retval None |
julientiron | 1:bdbf36f8408d | 196 | */ |
julientiron | 1:bdbf36f8408d | 197 | void MAGNETO_IO_Init(void) |
julientiron | 1:bdbf36f8408d | 198 | { |
julientiron | 1:bdbf36f8408d | 199 | I2C_SHIELDS_Init(); |
julientiron | 1:bdbf36f8408d | 200 | } |
julientiron | 1:bdbf36f8408d | 201 | |
julientiron | 1:bdbf36f8408d | 202 | |
julientiron | 1:bdbf36f8408d | 203 | /** |
julientiron | 1:bdbf36f8408d | 204 | * @brief Writes a buffer to the MAGNETO sensor. |
julientiron | 1:bdbf36f8408d | 205 | * @param pBuffer: pointer to data to be written. |
julientiron | 1:bdbf36f8408d | 206 | * @param DeviceAddr: specifies the slave address to be programmed. |
julientiron | 1:bdbf36f8408d | 207 | * @param RegisterAddr: specifies the MAGNETO register to be written. |
julientiron | 1:bdbf36f8408d | 208 | * @param NumByteToWrite: number of bytes to be written. |
julientiron | 1:bdbf36f8408d | 209 | * @retval None. |
julientiron | 1:bdbf36f8408d | 210 | */ |
julientiron | 1:bdbf36f8408d | 211 | void MAGNETO_IO_Write(uint8_t* pBuffer, uint8_t DeviceAddr, uint8_t RegisterAddr, uint16_t NumByteToWrite) |
julientiron | 1:bdbf36f8408d | 212 | { |
julientiron | 1:bdbf36f8408d | 213 | #ifdef USE_FREE_RTOS |
julientiron | 1:bdbf36f8408d | 214 | NUCLEO_I2C_SHIELDS_MUTEX_TAKE(); |
julientiron | 1:bdbf36f8408d | 215 | #endif |
julientiron | 1:bdbf36f8408d | 216 | |
julientiron | 1:bdbf36f8408d | 217 | /* call I2C_SHIELDS Read data bus function */ |
julientiron | 1:bdbf36f8408d | 218 | I2C_SHIELDS_WriteData(pBuffer, DeviceAddr, RegisterAddr, NumByteToWrite); |
julientiron | 1:bdbf36f8408d | 219 | |
julientiron | 1:bdbf36f8408d | 220 | #ifdef USE_FREE_RTOS |
julientiron | 1:bdbf36f8408d | 221 | NUCLEO_I2C_SHIELDS_MUTEX_RELEASE(); |
julientiron | 1:bdbf36f8408d | 222 | #endif |
julientiron | 1:bdbf36f8408d | 223 | } |
julientiron | 1:bdbf36f8408d | 224 | |
julientiron | 1:bdbf36f8408d | 225 | /** |
julientiron | 1:bdbf36f8408d | 226 | * @brief Reads a buffer from the MAGNETO sensor. |
julientiron | 1:bdbf36f8408d | 227 | * @param pBuffer: pointer to data to be read. |
julientiron | 1:bdbf36f8408d | 228 | * @param DeviceAddr: specifies the address of the device. |
julientiron | 1:bdbf36f8408d | 229 | * @param RegisterAddr: specifies the MAGNETO internal address register to read from. |
julientiron | 1:bdbf36f8408d | 230 | * @param NumByteToRead: number of bytes to be read. |
julientiron | 1:bdbf36f8408d | 231 | * @retval None. |
julientiron | 1:bdbf36f8408d | 232 | */ |
julientiron | 1:bdbf36f8408d | 233 | void MAGNETO_IO_Read(uint8_t* pBuffer, uint8_t DeviceAddr, uint8_t RegisterAddr, uint16_t NumByteToRead) |
julientiron | 1:bdbf36f8408d | 234 | { |
julientiron | 1:bdbf36f8408d | 235 | #ifdef USE_FREE_RTOS |
julientiron | 1:bdbf36f8408d | 236 | NUCLEO_I2C_SHIELDS_MUTEX_TAKE(); |
julientiron | 1:bdbf36f8408d | 237 | #endif |
julientiron | 1:bdbf36f8408d | 238 | |
julientiron | 1:bdbf36f8408d | 239 | /* call I2C_SHIELDS Read data bus function */ |
julientiron | 1:bdbf36f8408d | 240 | I2C_SHIELDS_ReadData(pBuffer, DeviceAddr, RegisterAddr, NumByteToRead); |
julientiron | 1:bdbf36f8408d | 241 | |
julientiron | 1:bdbf36f8408d | 242 | #ifdef USE_FREE_RTOS |
julientiron | 1:bdbf36f8408d | 243 | NUCLEO_I2C_SHIELDS_MUTEX_RELEASE(); |
julientiron | 1:bdbf36f8408d | 244 | #endif |
julientiron | 1:bdbf36f8408d | 245 | } |
julientiron | 1:bdbf36f8408d | 246 | |
julientiron | 1:bdbf36f8408d | 247 | |
julientiron | 1:bdbf36f8408d | 248 | |
julientiron | 1:bdbf36f8408d | 249 | /********************************* LINK PRESSURE *****************************/ |
julientiron | 1:bdbf36f8408d | 250 | /** |
julientiron | 1:bdbf36f8408d | 251 | * @brief Configures Pressure I2C interface. |
julientiron | 1:bdbf36f8408d | 252 | * @param None |
julientiron | 1:bdbf36f8408d | 253 | * @retval None |
julientiron | 1:bdbf36f8408d | 254 | */ |
julientiron | 1:bdbf36f8408d | 255 | void PRESSURE_IO_Init(void) |
julientiron | 1:bdbf36f8408d | 256 | { |
julientiron | 1:bdbf36f8408d | 257 | I2C_SHIELDS_Init(); |
julientiron | 1:bdbf36f8408d | 258 | } |
julientiron | 1:bdbf36f8408d | 259 | |
julientiron | 1:bdbf36f8408d | 260 | |
julientiron | 1:bdbf36f8408d | 261 | /** |
julientiron | 1:bdbf36f8408d | 262 | * @brief Writes a buffer to the Pressure sensor. |
julientiron | 1:bdbf36f8408d | 263 | * @param pBuffer: pointer to data to be written. |
julientiron | 1:bdbf36f8408d | 264 | * @param DeviceAddr: specifies the slave address to be programmed. |
julientiron | 1:bdbf36f8408d | 265 | * @param RegisterAddr: specifies the Pressure register to be written. |
julientiron | 1:bdbf36f8408d | 266 | * @param NumByteToWrite: number of bytes to be written. |
julientiron | 1:bdbf36f8408d | 267 | * @retval None. |
julientiron | 1:bdbf36f8408d | 268 | */ |
julientiron | 1:bdbf36f8408d | 269 | void PRESSURE_IO_Write(uint8_t* pBuffer, uint8_t DeviceAddr, uint8_t RegisterAddr, uint16_t NumByteToWrite) |
julientiron | 1:bdbf36f8408d | 270 | { |
julientiron | 1:bdbf36f8408d | 271 | #ifdef USE_FREE_RTOS |
julientiron | 1:bdbf36f8408d | 272 | NUCLEO_I2C_SHIELDS_MUTEX_TAKE(); |
julientiron | 1:bdbf36f8408d | 273 | #endif |
julientiron | 1:bdbf36f8408d | 274 | /* call I2C_SHIELDS Read data bus function */ |
julientiron | 1:bdbf36f8408d | 275 | I2C_SHIELDS_WriteData(pBuffer, DeviceAddr, RegisterAddr, NumByteToWrite); |
julientiron | 1:bdbf36f8408d | 276 | |
julientiron | 1:bdbf36f8408d | 277 | #ifdef USE_FREE_RTOS |
julientiron | 1:bdbf36f8408d | 278 | NUCLEO_I2C_SHIELDS_MUTEX_RELEASE(); |
julientiron | 1:bdbf36f8408d | 279 | #endif |
julientiron | 1:bdbf36f8408d | 280 | } |
julientiron | 1:bdbf36f8408d | 281 | |
julientiron | 1:bdbf36f8408d | 282 | /** |
julientiron | 1:bdbf36f8408d | 283 | * @brief Reads a buffer from the Pressure sensor. |
julientiron | 1:bdbf36f8408d | 284 | * @param pBuffer: pointer to data to be read. |
julientiron | 1:bdbf36f8408d | 285 | * @param DeviceAddr: specifies the address of the device. |
julientiron | 1:bdbf36f8408d | 286 | * @param RegisterAddr: specifies the Pressure internal address register to read from. |
julientiron | 1:bdbf36f8408d | 287 | * @param NumByteToRead: number of bytes to be read. |
julientiron | 1:bdbf36f8408d | 288 | * @retval None. |
julientiron | 1:bdbf36f8408d | 289 | */ |
julientiron | 1:bdbf36f8408d | 290 | void PRESSURE_IO_Read(uint8_t* pBuffer, uint8_t DeviceAddr, uint8_t RegisterAddr, uint16_t NumByteToRead) |
julientiron | 1:bdbf36f8408d | 291 | { |
julientiron | 1:bdbf36f8408d | 292 | #ifdef USE_FREE_RTOS |
julientiron | 1:bdbf36f8408d | 293 | NUCLEO_I2C_SHIELDS_MUTEX_TAKE(); |
julientiron | 1:bdbf36f8408d | 294 | #endif |
julientiron | 1:bdbf36f8408d | 295 | /* call I2C_SHIELDS Read data bus function */ |
julientiron | 1:bdbf36f8408d | 296 | I2C_SHIELDS_ReadData(pBuffer, DeviceAddr, RegisterAddr, NumByteToRead); |
julientiron | 1:bdbf36f8408d | 297 | |
julientiron | 1:bdbf36f8408d | 298 | #ifdef USE_FREE_RTOS |
julientiron | 1:bdbf36f8408d | 299 | NUCLEO_I2C_SHIELDS_MUTEX_RELEASE(); |
julientiron | 1:bdbf36f8408d | 300 | #endif |
julientiron | 1:bdbf36f8408d | 301 | } |
julientiron | 1:bdbf36f8408d | 302 | |
julientiron | 1:bdbf36f8408d | 303 | |
julientiron | 1:bdbf36f8408d | 304 | /********************************* LINK HUM_TEMP *****************************/ |
julientiron | 1:bdbf36f8408d | 305 | /** |
julientiron | 1:bdbf36f8408d | 306 | * @brief Configures Humidity and Temperature I2C interface. |
julientiron | 1:bdbf36f8408d | 307 | * @param None |
julientiron | 1:bdbf36f8408d | 308 | * @retval None |
julientiron | 1:bdbf36f8408d | 309 | */ |
julientiron | 1:bdbf36f8408d | 310 | void HUM_TEMP_IO_Init(void) |
julientiron | 1:bdbf36f8408d | 311 | { |
julientiron | 1:bdbf36f8408d | 312 | I2C_SHIELDS_Init(); |
julientiron | 1:bdbf36f8408d | 313 | } |
julientiron | 1:bdbf36f8408d | 314 | |
julientiron | 1:bdbf36f8408d | 315 | |
julientiron | 1:bdbf36f8408d | 316 | /** |
julientiron | 1:bdbf36f8408d | 317 | * @brief Writes a buffer to the HUM_TEMP sensor. |
julientiron | 1:bdbf36f8408d | 318 | * @param pBuffer: pointer to data to be written. |
julientiron | 1:bdbf36f8408d | 319 | * @param DeviceAddr: specifies the slave address to be programmed. |
julientiron | 1:bdbf36f8408d | 320 | * @param RegisterAddr: specifies the Pressure register to be written. |
julientiron | 1:bdbf36f8408d | 321 | * @param NumByteToWrite: number of bytes to be written. |
julientiron | 1:bdbf36f8408d | 322 | * @retval None. |
julientiron | 1:bdbf36f8408d | 323 | */ |
julientiron | 1:bdbf36f8408d | 324 | void HUM_TEMP_IO_Write(uint8_t* pBuffer, uint8_t DeviceAddr, uint8_t RegisterAddr, uint16_t NumByteToWrite) |
julientiron | 1:bdbf36f8408d | 325 | { |
julientiron | 1:bdbf36f8408d | 326 | #ifdef USE_FREE_RTOS |
julientiron | 1:bdbf36f8408d | 327 | NUCLEO_I2C_SHIELDS_MUTEX_TAKE(); |
julientiron | 1:bdbf36f8408d | 328 | #endif |
julientiron | 1:bdbf36f8408d | 329 | /* call I2C_SHIELDS Read data bus function */ |
julientiron | 1:bdbf36f8408d | 330 | I2C_SHIELDS_WriteData(pBuffer, DeviceAddr, RegisterAddr, NumByteToWrite); |
julientiron | 1:bdbf36f8408d | 331 | #ifdef USE_FREE_RTOS |
julientiron | 1:bdbf36f8408d | 332 | NUCLEO_I2C_SHIELDS_MUTEX_RELEASE(); |
julientiron | 1:bdbf36f8408d | 333 | #endif |
julientiron | 1:bdbf36f8408d | 334 | } |
julientiron | 1:bdbf36f8408d | 335 | |
julientiron | 1:bdbf36f8408d | 336 | /** |
julientiron | 1:bdbf36f8408d | 337 | * @brief Reads a buffer from the Uvi sensor. |
julientiron | 1:bdbf36f8408d | 338 | * @param pBuffer: pointer to data to be read. |
julientiron | 1:bdbf36f8408d | 339 | * @param DeviceAddr: specifies the address of the device. |
julientiron | 1:bdbf36f8408d | 340 | * @param RegisterAddr: specifies the Pressure internal address register to read from. |
julientiron | 1:bdbf36f8408d | 341 | * @param NumByteToRead: number of bytes to be read. |
julientiron | 1:bdbf36f8408d | 342 | * @retval None. |
julientiron | 1:bdbf36f8408d | 343 | */ |
julientiron | 1:bdbf36f8408d | 344 | void HUM_TEMP_IO_Read(uint8_t* pBuffer, uint8_t DeviceAddr, uint8_t RegisterAddr, uint16_t NumByteToRead) |
julientiron | 1:bdbf36f8408d | 345 | { |
julientiron | 1:bdbf36f8408d | 346 | #ifdef USE_FREE_RTOS |
julientiron | 1:bdbf36f8408d | 347 | NUCLEO_I2C_SHIELDS_MUTEX_TAKE(); |
julientiron | 1:bdbf36f8408d | 348 | #endif |
julientiron | 1:bdbf36f8408d | 349 | /* call I2C_SHIELDS Read data bus function */ |
julientiron | 1:bdbf36f8408d | 350 | I2C_SHIELDS_ReadData(pBuffer, DeviceAddr, RegisterAddr, NumByteToRead); |
julientiron | 1:bdbf36f8408d | 351 | #ifdef USE_FREE_RTOS |
julientiron | 1:bdbf36f8408d | 352 | NUCLEO_I2C_SHIELDS_MUTEX_RELEASE(); |
julientiron | 1:bdbf36f8408d | 353 | #endif |
julientiron | 1:bdbf36f8408d | 354 | } |
julientiron | 1:bdbf36f8408d | 355 | |
julientiron | 1:bdbf36f8408d | 356 | |
julientiron | 1:bdbf36f8408d | 357 | |
julientiron | 1:bdbf36f8408d | 358 | /******************************* I2C Routines**********************************/ |
julientiron | 1:bdbf36f8408d | 359 | /** |
julientiron | 1:bdbf36f8408d | 360 | * @brief Configures I2C interface. |
julientiron | 1:bdbf36f8408d | 361 | * @param None |
julientiron | 1:bdbf36f8408d | 362 | * @retval None |
julientiron | 1:bdbf36f8408d | 363 | */ |
julientiron | 1:bdbf36f8408d | 364 | static void I2C_SHIELDS_Init(void) |
julientiron | 1:bdbf36f8408d | 365 | { |
julientiron | 1:bdbf36f8408d | 366 | if(HAL_I2C_GetState(&I2C_SHIELDS_Handle) == HAL_I2C_STATE_RESET) |
julientiron | 1:bdbf36f8408d | 367 | { |
julientiron | 1:bdbf36f8408d | 368 | /* I2C_SHIELDS peripheral configuration */ |
julientiron | 1:bdbf36f8408d | 369 | // I2C_SHIELDS_Handle.Init.ClockSpeed = NUCLEO_I2C_SHIELDS_SPEED; |
julientiron | 1:bdbf36f8408d | 370 | // I2C_SHIELDS_Handle.Init.DutyCycle = I2C_DUTYCYCLE_2; |
julientiron | 1:bdbf36f8408d | 371 | #ifdef STM32F401xE |
julientiron | 1:bdbf36f8408d | 372 | I2C_SHIELDS_Handle.Init.ClockSpeed = NUCLEO_I2C_SHIELDS_SPEED; |
julientiron | 1:bdbf36f8408d | 373 | I2C_SHIELDS_Handle.Init.DutyCycle = I2C_DUTYCYCLE_2; |
julientiron | 1:bdbf36f8408d | 374 | #endif |
julientiron | 1:bdbf36f8408d | 375 | #ifdef STM32L053xx |
julientiron | 1:bdbf36f8408d | 376 | I2C_SHIELDS_Handle.Init.Timing = 0x0070D8FF; /*Refer AN4235-Application note Document*/ |
julientiron | 1:bdbf36f8408d | 377 | #endif |
julientiron | 1:bdbf36f8408d | 378 | I2C_SHIELDS_Handle.Init.OwnAddress1 = 0x33; |
julientiron | 1:bdbf36f8408d | 379 | I2C_SHIELDS_Handle.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT; |
julientiron | 1:bdbf36f8408d | 380 | I2C_SHIELDS_Handle.Instance = NUCLEO_I2C_SHIELDS; |
julientiron | 1:bdbf36f8408d | 381 | |
julientiron | 1:bdbf36f8408d | 382 | /* Init the I2C */ |
julientiron | 1:bdbf36f8408d | 383 | I2C_SHIELDS_MspInit(); |
julientiron | 1:bdbf36f8408d | 384 | HAL_I2C_Init(&I2C_SHIELDS_Handle); |
julientiron | 1:bdbf36f8408d | 385 | } |
julientiron | 1:bdbf36f8408d | 386 | } |
julientiron | 1:bdbf36f8408d | 387 | |
julientiron | 1:bdbf36f8408d | 388 | /** |
julientiron | 1:bdbf36f8408d | 389 | * @brief Write a value in a register of the device through BUS. |
julientiron | 1:bdbf36f8408d | 390 | * @param Addr: Device address on BUS Bus. |
julientiron | 1:bdbf36f8408d | 391 | * @param Reg: The target register address to write |
julientiron | 1:bdbf36f8408d | 392 | * @param Value: The target register value to be written |
julientiron | 1:bdbf36f8408d | 393 | * @retval HAL status |
julientiron | 1:bdbf36f8408d | 394 | */ |
julientiron | 1:bdbf36f8408d | 395 | |
julientiron | 1:bdbf36f8408d | 396 | static void I2C_SHIELDS_WriteData(uint8_t* pBuffer, uint8_t Addr, uint8_t Reg, uint16_t Size) |
julientiron | 1:bdbf36f8408d | 397 | { |
julientiron | 1:bdbf36f8408d | 398 | HAL_StatusTypeDef status = HAL_OK; |
julientiron | 1:bdbf36f8408d | 399 | |
julientiron | 1:bdbf36f8408d | 400 | status = HAL_I2C_Mem_Write(&I2C_SHIELDS_Handle, Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, pBuffer, Size, I2C_SHIELDS_Timeout); |
julientiron | 1:bdbf36f8408d | 401 | |
julientiron | 1:bdbf36f8408d | 402 | /* Check the communication status */ |
julientiron | 1:bdbf36f8408d | 403 | if(status != HAL_OK) |
julientiron | 1:bdbf36f8408d | 404 | { |
julientiron | 1:bdbf36f8408d | 405 | /* Execute user timeout callback */ |
julientiron | 1:bdbf36f8408d | 406 | I2C_SHIELDS_Error(Addr); |
julientiron | 1:bdbf36f8408d | 407 | } |
julientiron | 1:bdbf36f8408d | 408 | } |
julientiron | 1:bdbf36f8408d | 409 | |
julientiron | 1:bdbf36f8408d | 410 | |
julientiron | 1:bdbf36f8408d | 411 | /** |
julientiron | 1:bdbf36f8408d | 412 | * @brief Read a register of the device through BUS |
julientiron | 1:bdbf36f8408d | 413 | * @param Addr: Device address on BUS . |
julientiron | 1:bdbf36f8408d | 414 | * @param Reg: The target register address to read |
julientiron | 1:bdbf36f8408d | 415 | * @retval HAL status |
julientiron | 1:bdbf36f8408d | 416 | */ |
julientiron | 1:bdbf36f8408d | 417 | static void I2C_SHIELDS_ReadData(uint8_t* pBuffer, uint8_t Addr, uint8_t Reg, uint16_t Size) |
julientiron | 1:bdbf36f8408d | 418 | { |
julientiron | 1:bdbf36f8408d | 419 | HAL_StatusTypeDef status = HAL_OK; |
julientiron | 1:bdbf36f8408d | 420 | |
julientiron | 1:bdbf36f8408d | 421 | status = HAL_I2C_Mem_Read(&I2C_SHIELDS_Handle, Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, pBuffer, Size, I2C_SHIELDS_Timeout); |
julientiron | 1:bdbf36f8408d | 422 | |
julientiron | 1:bdbf36f8408d | 423 | /* Check the communication status */ |
julientiron | 1:bdbf36f8408d | 424 | if(status != HAL_OK) |
julientiron | 1:bdbf36f8408d | 425 | { |
julientiron | 1:bdbf36f8408d | 426 | /* Execute user timeout callback */ |
julientiron | 1:bdbf36f8408d | 427 | I2C_SHIELDS_Error(Addr); |
julientiron | 1:bdbf36f8408d | 428 | } |
julientiron | 1:bdbf36f8408d | 429 | |
julientiron | 1:bdbf36f8408d | 430 | } |
julientiron | 1:bdbf36f8408d | 431 | |
julientiron | 1:bdbf36f8408d | 432 | /** |
julientiron | 1:bdbf36f8408d | 433 | * @brief Manages error callback by re-initializing I2C. |
julientiron | 1:bdbf36f8408d | 434 | * @param Addr: I2C Address |
julientiron | 1:bdbf36f8408d | 435 | * @retval None |
julientiron | 1:bdbf36f8408d | 436 | */ |
julientiron | 1:bdbf36f8408d | 437 | static void I2C_SHIELDS_Error(uint8_t Addr) |
julientiron | 1:bdbf36f8408d | 438 | { |
julientiron | 1:bdbf36f8408d | 439 | /* De-initialize the I2C comunication bus */ |
julientiron | 1:bdbf36f8408d | 440 | HAL_I2C_DeInit(&I2C_SHIELDS_Handle); |
julientiron | 1:bdbf36f8408d | 441 | |
julientiron | 1:bdbf36f8408d | 442 | /* Re-Initiaize the I2C comunication bus */ |
julientiron | 1:bdbf36f8408d | 443 | I2C_SHIELDS_Init(); |
julientiron | 1:bdbf36f8408d | 444 | } |
julientiron | 1:bdbf36f8408d | 445 | |
julientiron | 1:bdbf36f8408d | 446 | /** |
julientiron | 1:bdbf36f8408d | 447 | * @brief I2C MSP Initialization |
julientiron | 1:bdbf36f8408d | 448 | * @param None |
julientiron | 1:bdbf36f8408d | 449 | * @retval None |
julientiron | 1:bdbf36f8408d | 450 | */ |
julientiron | 1:bdbf36f8408d | 451 | |
julientiron | 1:bdbf36f8408d | 452 | static void I2C_SHIELDS_MspInit(void) |
julientiron | 1:bdbf36f8408d | 453 | { |
julientiron | 1:bdbf36f8408d | 454 | GPIO_InitTypeDef GPIO_InitStruct; |
julientiron | 1:bdbf36f8408d | 455 | |
julientiron | 1:bdbf36f8408d | 456 | #ifdef USE_FREE_RTOS |
julientiron | 1:bdbf36f8408d | 457 | if(!NUCLEO_I2C_SHIELDS_MUTEX) { |
julientiron | 1:bdbf36f8408d | 458 | NUCLEO_I2C_SHIELDS_MUTEX = osMutexCreate(0); |
julientiron | 1:bdbf36f8408d | 459 | } |
julientiron | 1:bdbf36f8408d | 460 | #endif |
julientiron | 1:bdbf36f8408d | 461 | |
julientiron | 1:bdbf36f8408d | 462 | /* Enable I2C GPIO clocks */ |
julientiron | 1:bdbf36f8408d | 463 | NUCLEO_I2C_SHIELDS_SCL_SDA_GPIO_CLK_ENABLE(); |
julientiron | 1:bdbf36f8408d | 464 | |
julientiron | 1:bdbf36f8408d | 465 | /* I2C_SHIELDS SCL and SDA pins configuration -------------------------------------*/ |
julientiron | 1:bdbf36f8408d | 466 | GPIO_InitStruct.Pin = NUCLEO_I2C_SHIELDS_SCL_PIN | NUCLEO_I2C_SHIELDS_SDA_PIN; |
julientiron | 1:bdbf36f8408d | 467 | GPIO_InitStruct.Mode = GPIO_MODE_AF_OD; |
julientiron | 1:bdbf36f8408d | 468 | GPIO_InitStruct.Speed = GPIO_SPEED_FAST; |
julientiron | 1:bdbf36f8408d | 469 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
julientiron | 1:bdbf36f8408d | 470 | GPIO_InitStruct.Alternate = NUCLEO_I2C_SHIELDS_SCL_SDA_AF; |
julientiron | 1:bdbf36f8408d | 471 | HAL_GPIO_Init(NUCLEO_I2C_SHIELDS_SCL_SDA_GPIO_PORT, &GPIO_InitStruct); |
julientiron | 1:bdbf36f8408d | 472 | |
julientiron | 1:bdbf36f8408d | 473 | /* Enable the I2C_SHIELDS peripheral clock */ |
julientiron | 1:bdbf36f8408d | 474 | NUCLEO_I2C_SHIELDS_CLK_ENABLE(); |
julientiron | 1:bdbf36f8408d | 475 | |
julientiron | 1:bdbf36f8408d | 476 | /* Force the I2C peripheral clock reset */ |
julientiron | 1:bdbf36f8408d | 477 | NUCLEO_I2C_SHIELDS_FORCE_RESET(); |
julientiron | 1:bdbf36f8408d | 478 | |
julientiron | 1:bdbf36f8408d | 479 | /* Release the I2C peripheral clock reset */ |
julientiron | 1:bdbf36f8408d | 480 | NUCLEO_I2C_SHIELDS_RELEASE_RESET(); |
julientiron | 1:bdbf36f8408d | 481 | |
julientiron | 1:bdbf36f8408d | 482 | /* Enable and set I2C_SHIELDS Interrupt to the highest priority */ |
julientiron | 1:bdbf36f8408d | 483 | HAL_NVIC_SetPriority(NUCLEO_I2C_SHIELDS_EV_IRQn, 0, 0); |
julientiron | 1:bdbf36f8408d | 484 | HAL_NVIC_EnableIRQ(NUCLEO_I2C_SHIELDS_EV_IRQn); |
julientiron | 1:bdbf36f8408d | 485 | |
julientiron | 1:bdbf36f8408d | 486 | #ifdef STM32F401xE |
julientiron | 1:bdbf36f8408d | 487 | /* Enable and set I2C_SHIELDS Interrupt to the highest priority */ |
julientiron | 1:bdbf36f8408d | 488 | HAL_NVIC_SetPriority(NUCLEO_I2C_SHIELDS_ER_IRQn, 0, 0); |
julientiron | 1:bdbf36f8408d | 489 | HAL_NVIC_EnableIRQ(NUCLEO_I2C_SHIELDS_ER_IRQn); |
julientiron | 1:bdbf36f8408d | 490 | #endif |
julientiron | 1:bdbf36f8408d | 491 | } |
julientiron | 1:bdbf36f8408d | 492 | |
julientiron | 1:bdbf36f8408d | 493 | |
julientiron | 1:bdbf36f8408d | 494 | /** |
julientiron | 1:bdbf36f8408d | 495 | * @} |
julientiron | 1:bdbf36f8408d | 496 | */ |
julientiron | 1:bdbf36f8408d | 497 | |
julientiron | 1:bdbf36f8408d | 498 | /** |
julientiron | 1:bdbf36f8408d | 499 | * @} |
julientiron | 1:bdbf36f8408d | 500 | */ |
julientiron | 1:bdbf36f8408d | 501 | |
julientiron | 1:bdbf36f8408d | 502 | /** |
julientiron | 1:bdbf36f8408d | 503 | * @} |
julientiron | 1:bdbf36f8408d | 504 | */ |
julientiron | 1:bdbf36f8408d | 505 | |
julientiron | 1:bdbf36f8408d | 506 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
julientiron | 1:bdbf36f8408d | 507 |