Environmental Shield API

Committer:
Deepti
Date:
Tue Aug 19 07:13:15 2014 +0000
Revision:
0:9e645e6ed2ce
Environment Shield API

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Deepti 0:9e645e6ed2ce 1 /**
Deepti 0:9e645e6ed2ce 2 ******************************************************************************
Deepti 0:9e645e6ed2ce 3 * @file nucleo-f401re.c
Deepti 0:9e645e6ed2ce 4 * @author MCD Application Team
Deepti 0:9e645e6ed2ce 5 * @version V1.0.0
Deepti 0:9e645e6ed2ce 6 * @date 22-April-2014
Deepti 0:9e645e6ed2ce 7 * @brief This file provides set of firmware functions to manage:
Deepti 0:9e645e6ed2ce 8 * - LEDs and push-button available on NUCLEO-F401RE Kit
Deepti 0:9e645e6ed2ce 9 * from STMicroelectronics
Deepti 0:9e645e6ed2ce 10 ******************************************************************************
Deepti 0:9e645e6ed2ce 11 * @attention
Deepti 0:9e645e6ed2ce 12 *
Deepti 0:9e645e6ed2ce 13 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
Deepti 0:9e645e6ed2ce 14 *
Deepti 0:9e645e6ed2ce 15 * Redistribution and use in source and binary forms, with or without modification,
Deepti 0:9e645e6ed2ce 16 * are permitted provided that the following conditions are met:
Deepti 0:9e645e6ed2ce 17 * 1. Redistributions of source code must retain the above copyright notice,
Deepti 0:9e645e6ed2ce 18 * this list of conditions and the following disclaimer.
Deepti 0:9e645e6ed2ce 19 * 2. Redistributions in binary form must reproduce the above copyright notice,
Deepti 0:9e645e6ed2ce 20 * this list of conditions and the following disclaimer in the documentation
Deepti 0:9e645e6ed2ce 21 * and/or other materials provided with the distribution.
Deepti 0:9e645e6ed2ce 22 * 3. Neither the name of STMicroelectronics nor the names of its contributors
Deepti 0:9e645e6ed2ce 23 * may be used to endorse or promote products derived from this software
Deepti 0:9e645e6ed2ce 24 * without specific prior written permission.
Deepti 0:9e645e6ed2ce 25 *
Deepti 0:9e645e6ed2ce 26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Deepti 0:9e645e6ed2ce 27 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Deepti 0:9e645e6ed2ce 28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Deepti 0:9e645e6ed2ce 29 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
Deepti 0:9e645e6ed2ce 30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Deepti 0:9e645e6ed2ce 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
Deepti 0:9e645e6ed2ce 32 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
Deepti 0:9e645e6ed2ce 33 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
Deepti 0:9e645e6ed2ce 34 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Deepti 0:9e645e6ed2ce 35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Deepti 0:9e645e6ed2ce 36 *
Deepti 0:9e645e6ed2ce 37 ******************************************************************************
Deepti 0:9e645e6ed2ce 38 */
Deepti 0:9e645e6ed2ce 39
Deepti 0:9e645e6ed2ce 40 /* Includes ------------------------------------------------------------------*/
Deepti 0:9e645e6ed2ce 41 #include "nucleo-f401re.h"
Deepti 0:9e645e6ed2ce 42 //#include "cmsis_os.h"
Deepti 0:9e645e6ed2ce 43 //#include "stm32f4xx_hal.h"
Deepti 0:9e645e6ed2ce 44 //#include "stm32f4xx_hal_i2c.h"
Deepti 0:9e645e6ed2ce 45 //#include "stm32f4xx_hal_i2c_ex.h"
Deepti 0:9e645e6ed2ce 46
Deepti 0:9e645e6ed2ce 47
Deepti 0:9e645e6ed2ce 48 /** @addtogroup BSP
Deepti 0:9e645e6ed2ce 49 * @{
Deepti 0:9e645e6ed2ce 50 */
Deepti 0:9e645e6ed2ce 51
Deepti 0:9e645e6ed2ce 52 /** @addtogroup NUCLEO_F401RE
Deepti 0:9e645e6ed2ce 53 * @{
Deepti 0:9e645e6ed2ce 54 */
Deepti 0:9e645e6ed2ce 55
Deepti 0:9e645e6ed2ce 56 /** @addtogroup NUCLEO_F401RE_LOW_LEVEL
Deepti 0:9e645e6ed2ce 57 * @brief This file provides set of firmware functions to manage Leds and push-button
Deepti 0:9e645e6ed2ce 58 * available on NUCLEO-F401RE Kit from STMicroelectronics.
Deepti 0:9e645e6ed2ce 59 * @{
Deepti 0:9e645e6ed2ce 60 */
Deepti 0:9e645e6ed2ce 61
Deepti 0:9e645e6ed2ce 62 /** @defgroup NUCLEO_F401RE_LOW_LEVEL_Private_TypesDefinitions
Deepti 0:9e645e6ed2ce 63 * @{
Deepti 0:9e645e6ed2ce 64 */
Deepti 0:9e645e6ed2ce 65 /**
Deepti 0:9e645e6ed2ce 66 * @}
Deepti 0:9e645e6ed2ce 67 */
Deepti 0:9e645e6ed2ce 68
Deepti 0:9e645e6ed2ce 69
Deepti 0:9e645e6ed2ce 70 /** @defgroup NUCLEO_F401RE_LOW_LEVEL_Private_Defines
Deepti 0:9e645e6ed2ce 71 * @{
Deepti 0:9e645e6ed2ce 72 */
Deepti 0:9e645e6ed2ce 73
Deepti 0:9e645e6ed2ce 74 /**
Deepti 0:9e645e6ed2ce 75 * @brief STM32L0XX NUCLEO BSP Driver version number V1.0.0
Deepti 0:9e645e6ed2ce 76 */
Deepti 0:9e645e6ed2ce 77 #define __NUCLEO_F401RE_BSP_VERSION_MAIN (0x01) /*!< [31:24] main version */
Deepti 0:9e645e6ed2ce 78 #define __NUCLEO_F401RE_BSP_VERSION_SUB1 (0x00) /*!< [23:16] sub1 version */
Deepti 0:9e645e6ed2ce 79 #define __NUCLEO_F401RE_BSP_VERSION_SUB2 (0x00) /*!< [15:8] sub2 version */
Deepti 0:9e645e6ed2ce 80 #define __NUCLEO_F401RE_BSP_VERSION_RC (0x00) /*!< [7:0] release candidate */
Deepti 0:9e645e6ed2ce 81 #define __NUCLEO_F401RE_BSP_VERSION ((__NUCLEO_F401RE_BSP_VERSION_MAIN << 24)\
Deepti 0:9e645e6ed2ce 82 |(__NUCLEO_F401RE_BSP_VERSION_SUB1 << 16)\
Deepti 0:9e645e6ed2ce 83 |(__NUCLEO_F401RE_BSP_VERSION_SUB2 << 8 )\
Deepti 0:9e645e6ed2ce 84 |(__NUCLEO_F401RE_BSP_VERSION_RC))
Deepti 0:9e645e6ed2ce 85
Deepti 0:9e645e6ed2ce 86 /**
Deepti 0:9e645e6ed2ce 87 * @brief LINK SD Card
Deepti 0:9e645e6ed2ce 88 */
Deepti 0:9e645e6ed2ce 89 #define SD_DUMMY_BYTE 0xFF
Deepti 0:9e645e6ed2ce 90 #define SD_NO_RESPONSE_EXPECTED 0x80
Deepti 0:9e645e6ed2ce 91
Deepti 0:9e645e6ed2ce 92 /**
Deepti 0:9e645e6ed2ce 93 * @}
Deepti 0:9e645e6ed2ce 94 */
Deepti 0:9e645e6ed2ce 95
Deepti 0:9e645e6ed2ce 96 /** @defgroup NUCLEO_F401RE_LOW_LEVEL_Private_Macros
Deepti 0:9e645e6ed2ce 97 * @{
Deepti 0:9e645e6ed2ce 98 */
Deepti 0:9e645e6ed2ce 99 /**
Deepti 0:9e645e6ed2ce 100 * @}
Deepti 0:9e645e6ed2ce 101 */
Deepti 0:9e645e6ed2ce 102
Deepti 0:9e645e6ed2ce 103 /** @defgroup NUCLEO_F401RE_LOW_LEVEL_Private_Variables
Deepti 0:9e645e6ed2ce 104 * @{
Deepti 0:9e645e6ed2ce 105 */
Deepti 0:9e645e6ed2ce 106 GPIO_TypeDef* GPIO_PORT[LEDn] = {LED2_GPIO_PORT};
Deepti 0:9e645e6ed2ce 107
Deepti 0:9e645e6ed2ce 108 const uint16_t GPIO_PIN[LEDn] = {LED2_PIN};
Deepti 0:9e645e6ed2ce 109
Deepti 0:9e645e6ed2ce 110 GPIO_TypeDef* BUTTON_PORT[BUTTONn] = {KEY_BUTTON_GPIO_PORT};
Deepti 0:9e645e6ed2ce 111 const uint16_t BUTTON_PIN[BUTTONn] = {KEY_BUTTON_PIN};
Deepti 0:9e645e6ed2ce 112 const uint16_t BUTTON_IRQn[BUTTONn] = {KEY_BUTTON_EXTI_IRQn};
Deepti 0:9e645e6ed2ce 113
Deepti 0:9e645e6ed2ce 114 /**
Deepti 0:9e645e6ed2ce 115 * @brief BUS variables
Deepti 0:9e645e6ed2ce 116 */
Deepti 0:9e645e6ed2ce 117
Deepti 0:9e645e6ed2ce 118 //uint32_t SpixTimeout = NUCLEO_SPIx_TIMEOUT_MAX; /*<! Value of Timeout when SPI communication fails */
Deepti 0:9e645e6ed2ce 119 //static SPI_HandleTypeDef hnucleo_Spi;
Deepti 0:9e645e6ed2ce 120 //static ADC_HandleTypeDef hnucleo_Adc;
Deepti 0:9e645e6ed2ce 121
Deepti 0:9e645e6ed2ce 122 /* ADC channel configuration structure declaration */
Deepti 0:9e645e6ed2ce 123 //static ADC_ChannelConfTypeDef sConfig;
Deepti 0:9e645e6ed2ce 124
Deepti 0:9e645e6ed2ce 125 /**
Deepti 0:9e645e6ed2ce 126 * @}
Deepti 0:9e645e6ed2ce 127 */
Deepti 0:9e645e6ed2ce 128
Deepti 0:9e645e6ed2ce 129 uint32_t I2C_SHIELDS_Timeout = NUCLEO_I2C_SHIELDS_TIMEOUT_MAX; /*<! Value of Timeout when I2C communication fails */
Deepti 0:9e645e6ed2ce 130
Deepti 0:9e645e6ed2ce 131 static I2C_HandleTypeDef I2C_SHIELDS_Handle;
Deepti 0:9e645e6ed2ce 132
Deepti 0:9e645e6ed2ce 133 //osMutexId I2C1_Mutex_id = 0;
Deepti 0:9e645e6ed2ce 134
Deepti 0:9e645e6ed2ce 135 /** @defgroup NUCLEO_F401RE_LOW_LEVEL_Private_FunctionPrototypes
Deepti 0:9e645e6ed2ce 136 * @{
Deepti 0:9e645e6ed2ce 137 */
Deepti 0:9e645e6ed2ce 138
Deepti 0:9e645e6ed2ce 139 /* Link function for PRESSURE peripheral */
Deepti 0:9e645e6ed2ce 140 void PRESSURE_IO_Init(void);
Deepti 0:9e645e6ed2ce 141 void PRESSURE_IO_ITConfig(void);
Deepti 0:9e645e6ed2ce 142 void PRESSURE_IO_Write(uint8_t* pBuffer, uint8_t DeviceAddr, uint8_t WriteAddr, uint16_t NumByteToWrite);
Deepti 0:9e645e6ed2ce 143 void PRESSURE_IO_Read(uint8_t* pBuffer, uint8_t DeviceAddr, uint8_t RegisterAddr, uint16_t NumByteToRead);
Deepti 0:9e645e6ed2ce 144
Deepti 0:9e645e6ed2ce 145 /* Link function for UV peripheral */
Deepti 0:9e645e6ed2ce 146 void UV_IO_Init(void);
Deepti 0:9e645e6ed2ce 147 void UV_IO_ITConfig(void);
Deepti 0:9e645e6ed2ce 148 void UV_IO_Write(uint8_t* pBuffer, uint8_t DeviceAddr, uint8_t WriteAddr, uint16_t NumByteToWrite);
Deepti 0:9e645e6ed2ce 149 void UV_IO_Read(uint8_t* pBuffer, uint8_t DeviceAddr, uint8_t RegisterAddr, uint16_t NumByteToRead);
Deepti 0:9e645e6ed2ce 150
Deepti 0:9e645e6ed2ce 151 /* Link function for HUM_TEMP peripheral */
Deepti 0:9e645e6ed2ce 152 void HUM_TEMP_IO_Init(void);
Deepti 0:9e645e6ed2ce 153 void HUM_TEMP_IO_ITConfig(void);
Deepti 0:9e645e6ed2ce 154 void HUM_TEMP_IO_Write(uint8_t* pBuffer, uint8_t DeviceAddr, uint8_t WriteAddr, uint16_t NumByteToWrite);
Deepti 0:9e645e6ed2ce 155 void HUM_TEMP_IO_Read(uint8_t* pBuffer, uint8_t DeviceAddr, uint8_t RegisterAddr, uint16_t NumByteToRead);
Deepti 0:9e645e6ed2ce 156
Deepti 0:9e645e6ed2ce 157
Deepti 0:9e645e6ed2ce 158 static void I2C_SHIELDS_MspInit(void);
Deepti 0:9e645e6ed2ce 159 static void I2C_SHIELDS_Error(uint8_t Addr);
Deepti 0:9e645e6ed2ce 160
Deepti 0:9e645e6ed2ce 161 /**
Deepti 0:9e645e6ed2ce 162 * @}
Deepti 0:9e645e6ed2ce 163 */
Deepti 0:9e645e6ed2ce 164
Deepti 0:9e645e6ed2ce 165 /** @defgroup NUCLEO_F401RE_LOW_LEVEL_Private_Functions
Deepti 0:9e645e6ed2ce 166 * @{
Deepti 0:9e645e6ed2ce 167 */
Deepti 0:9e645e6ed2ce 168
Deepti 0:9e645e6ed2ce 169 /**
Deepti 0:9e645e6ed2ce 170 * @brief This method returns the STM32L0XX NUCLEO BSP Driver revision
Deepti 0:9e645e6ed2ce 171 * @param None
Deepti 0:9e645e6ed2ce 172 * @retval version : 0xXYZR (8bits for each decimal, R for RC)
Deepti 0:9e645e6ed2ce 173 */
Deepti 0:9e645e6ed2ce 174 uint32_t BSP_GetVersion(void)
Deepti 0:9e645e6ed2ce 175 {
Deepti 0:9e645e6ed2ce 176 return __NUCLEO_F401RE_BSP_VERSION;
Deepti 0:9e645e6ed2ce 177 }
Deepti 0:9e645e6ed2ce 178
Deepti 0:9e645e6ed2ce 179
Deepti 0:9e645e6ed2ce 180 /**
Deepti 0:9e645e6ed2ce 181 * @brief Configures Button GPIO and EXTI Line.
Deepti 0:9e645e6ed2ce 182 * @param Button: Specifies the Button to be configured.
Deepti 0:9e645e6ed2ce 183 * This parameter should be: BUTTON_KEY
Deepti 0:9e645e6ed2ce 184 * @param ButtonMode: Specifies Button mode.
Deepti 0:9e645e6ed2ce 185 * This parameter can be one of following parameters:
Deepti 0:9e645e6ed2ce 186 * @arg BUTTON_MODE_GPIO: Button will be used as simple IO
Deepti 0:9e645e6ed2ce 187 * @arg BUTTON_MODE_EXTI: Button will be connected to EXTI line with interrupt
Deepti 0:9e645e6ed2ce 188 * generation capability
Deepti 0:9e645e6ed2ce 189 * @retval None
Deepti 0:9e645e6ed2ce 190 */
Deepti 0:9e645e6ed2ce 191 void BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef Button_Mode)
Deepti 0:9e645e6ed2ce 192 {
Deepti 0:9e645e6ed2ce 193 GPIO_InitTypeDef GPIO_InitStruct;
Deepti 0:9e645e6ed2ce 194
Deepti 0:9e645e6ed2ce 195 /* Enable the BUTTON Clock */
Deepti 0:9e645e6ed2ce 196 BUTTONx_GPIO_CLK_ENABLE(Button);
Deepti 0:9e645e6ed2ce 197 __SYSCFG_CLK_ENABLE();
Deepti 0:9e645e6ed2ce 198
Deepti 0:9e645e6ed2ce 199 if(Button_Mode == BUTTON_MODE_GPIO)
Deepti 0:9e645e6ed2ce 200 {
Deepti 0:9e645e6ed2ce 201 /* Configure Button pin as input */
Deepti 0:9e645e6ed2ce 202 GPIO_InitStruct.Pin = BUTTON_PIN[Button];
Deepti 0:9e645e6ed2ce 203 GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
Deepti 0:9e645e6ed2ce 204 GPIO_InitStruct.Pull = GPIO_NOPULL;
Deepti 0:9e645e6ed2ce 205 GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
Deepti 0:9e645e6ed2ce 206
Deepti 0:9e645e6ed2ce 207 HAL_GPIO_Init(BUTTON_PORT[Button], &GPIO_InitStruct);
Deepti 0:9e645e6ed2ce 208 }
Deepti 0:9e645e6ed2ce 209
Deepti 0:9e645e6ed2ce 210 if(Button_Mode == BUTTON_MODE_EXTI)
Deepti 0:9e645e6ed2ce 211 {
Deepti 0:9e645e6ed2ce 212 /* Configure Button pin as input with External interrupt */
Deepti 0:9e645e6ed2ce 213 GPIO_InitStruct.Pin = BUTTON_PIN[Button];
Deepti 0:9e645e6ed2ce 214 GPIO_InitStruct.Pull = GPIO_NOPULL;
Deepti 0:9e645e6ed2ce 215 GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
Deepti 0:9e645e6ed2ce 216 GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
Deepti 0:9e645e6ed2ce 217 HAL_GPIO_Init(BUTTON_PORT[Button], &GPIO_InitStruct);
Deepti 0:9e645e6ed2ce 218
Deepti 0:9e645e6ed2ce 219 /* Enable and set Button EXTI Interrupt to the lowest priority */
Deepti 0:9e645e6ed2ce 220 NVIC_SetPriority((IRQn_Type)(BUTTON_IRQn[Button]), 0x03);
Deepti 0:9e645e6ed2ce 221 HAL_NVIC_EnableIRQ((IRQn_Type)(BUTTON_IRQn[Button]));
Deepti 0:9e645e6ed2ce 222 }
Deepti 0:9e645e6ed2ce 223 }
Deepti 0:9e645e6ed2ce 224
Deepti 0:9e645e6ed2ce 225 /**
Deepti 0:9e645e6ed2ce 226 * @brief Returns the selected Button state.
Deepti 0:9e645e6ed2ce 227 * @param Button: Specifies the Button to be checked.
Deepti 0:9e645e6ed2ce 228 * This parameter should be: BUTTON_KEY
Deepti 0:9e645e6ed2ce 229 * @retval The Button GPIO pin value.
Deepti 0:9e645e6ed2ce 230 */
Deepti 0:9e645e6ed2ce 231 uint32_t BSP_PB_GetState(Button_TypeDef Button)
Deepti 0:9e645e6ed2ce 232 {
Deepti 0:9e645e6ed2ce 233 return HAL_GPIO_ReadPin(BUTTON_PORT[Button], BUTTON_PIN[Button]);
Deepti 0:9e645e6ed2ce 234 }
Deepti 0:9e645e6ed2ce 235
Deepti 0:9e645e6ed2ce 236 /******************************* I2C Routines**********************************/
Deepti 0:9e645e6ed2ce 237 /**
Deepti 0:9e645e6ed2ce 238 * @brief Configures I2C interface.
Deepti 0:9e645e6ed2ce 239 * @param None
Deepti 0:9e645e6ed2ce 240 * @retval None
Deepti 0:9e645e6ed2ce 241 */
Deepti 0:9e645e6ed2ce 242 static void I2C_SHIELDS_Init(void)
Deepti 0:9e645e6ed2ce 243 {
Deepti 0:9e645e6ed2ce 244 if(HAL_I2C_GetState(&I2C_SHIELDS_Handle) == HAL_I2C_STATE_RESET)
Deepti 0:9e645e6ed2ce 245 {
Deepti 0:9e645e6ed2ce 246 /* I2C_SHIELDS peripheral configuration */
Deepti 0:9e645e6ed2ce 247 I2C_SHIELDS_Handle.Init.ClockSpeed = NUCLEO_I2C_SHIELDS_SPEED;
Deepti 0:9e645e6ed2ce 248 I2C_SHIELDS_Handle.Init.DutyCycle = I2C_DUTYCYCLE_2;
Deepti 0:9e645e6ed2ce 249 I2C_SHIELDS_Handle.Init.OwnAddress1 = 0x33;
Deepti 0:9e645e6ed2ce 250 I2C_SHIELDS_Handle.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
Deepti 0:9e645e6ed2ce 251 I2C_SHIELDS_Handle.Instance = NUCLEO_I2C_SHIELDS;
Deepti 0:9e645e6ed2ce 252
Deepti 0:9e645e6ed2ce 253 /* Init the I2C */
Deepti 0:9e645e6ed2ce 254 I2C_SHIELDS_MspInit();
Deepti 0:9e645e6ed2ce 255 HAL_I2C_Init(&I2C_SHIELDS_Handle);
Deepti 0:9e645e6ed2ce 256 }
Deepti 0:9e645e6ed2ce 257 }
Deepti 0:9e645e6ed2ce 258
Deepti 0:9e645e6ed2ce 259 /**
Deepti 0:9e645e6ed2ce 260 * @brief Write a value in a register of the device through BUS.
Deepti 0:9e645e6ed2ce 261 * @param Addr: Device address on BUS Bus.
Deepti 0:9e645e6ed2ce 262 * @param Reg: The target register address to write
Deepti 0:9e645e6ed2ce 263 * @param Value: The target register value to be written
Deepti 0:9e645e6ed2ce 264 * @retval HAL status
Deepti 0:9e645e6ed2ce 265 */
Deepti 0:9e645e6ed2ce 266
Deepti 0:9e645e6ed2ce 267 static void I2C_SHIELDS_WriteData(uint8_t* pBuffer, uint8_t Addr, uint8_t Reg, uint16_t Size)
Deepti 0:9e645e6ed2ce 268 {
Deepti 0:9e645e6ed2ce 269 HAL_StatusTypeDef status = HAL_OK;
Deepti 0:9e645e6ed2ce 270
Deepti 0:9e645e6ed2ce 271 status = HAL_I2C_Mem_Write(&I2C_SHIELDS_Handle, Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, pBuffer, Size, I2C_SHIELDS_Timeout);
Deepti 0:9e645e6ed2ce 272
Deepti 0:9e645e6ed2ce 273 /* Check the communication status */
Deepti 0:9e645e6ed2ce 274 if(status != HAL_OK)
Deepti 0:9e645e6ed2ce 275 {
Deepti 0:9e645e6ed2ce 276 /* Execute user timeout callback */
Deepti 0:9e645e6ed2ce 277 I2C_SHIELDS_Error(Addr);
Deepti 0:9e645e6ed2ce 278 }
Deepti 0:9e645e6ed2ce 279 }
Deepti 0:9e645e6ed2ce 280
Deepti 0:9e645e6ed2ce 281 /**
Deepti 0:9e645e6ed2ce 282 * @brief Read a register of the device through BUS
Deepti 0:9e645e6ed2ce 283 * @param Addr: Device address on BUS .
Deepti 0:9e645e6ed2ce 284 * @param Reg: The target register address to read
Deepti 0:9e645e6ed2ce 285 * @retval HAL status
Deepti 0:9e645e6ed2ce 286 */
Deepti 0:9e645e6ed2ce 287 static void I2C_SHIELDS_ReadData(uint8_t* pBuffer, uint8_t Addr, uint8_t Reg, uint16_t Size)
Deepti 0:9e645e6ed2ce 288 {
Deepti 0:9e645e6ed2ce 289 HAL_StatusTypeDef status = HAL_OK;
Deepti 0:9e645e6ed2ce 290
Deepti 0:9e645e6ed2ce 291 status = HAL_I2C_Mem_Read(&I2C_SHIELDS_Handle, Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, pBuffer, Size, I2C_SHIELDS_Timeout);
Deepti 0:9e645e6ed2ce 292
Deepti 0:9e645e6ed2ce 293 /* Check the communication status */
Deepti 0:9e645e6ed2ce 294 if(status != HAL_OK)
Deepti 0:9e645e6ed2ce 295 {
Deepti 0:9e645e6ed2ce 296 /* Execute user timeout callback */
Deepti 0:9e645e6ed2ce 297 I2C_SHIELDS_Error(Addr);
Deepti 0:9e645e6ed2ce 298 }
Deepti 0:9e645e6ed2ce 299
Deepti 0:9e645e6ed2ce 300 }
Deepti 0:9e645e6ed2ce 301
Deepti 0:9e645e6ed2ce 302 /**
Deepti 0:9e645e6ed2ce 303 * @brief Manages error callback by re-initializing I2C.
Deepti 0:9e645e6ed2ce 304 * @param Addr: I2C Address
Deepti 0:9e645e6ed2ce 305 * @retval None
Deepti 0:9e645e6ed2ce 306 */
Deepti 0:9e645e6ed2ce 307 static void I2C_SHIELDS_Error(uint8_t Addr)
Deepti 0:9e645e6ed2ce 308 {
Deepti 0:9e645e6ed2ce 309 /* De-initialize the I2C comunication bus */
Deepti 0:9e645e6ed2ce 310 HAL_I2C_DeInit(&I2C_SHIELDS_Handle);
Deepti 0:9e645e6ed2ce 311
Deepti 0:9e645e6ed2ce 312 /* Re-Initiaize the I2C comunication bus */
Deepti 0:9e645e6ed2ce 313 I2C_SHIELDS_Init();
Deepti 0:9e645e6ed2ce 314 }
Deepti 0:9e645e6ed2ce 315
Deepti 0:9e645e6ed2ce 316 /**
Deepti 0:9e645e6ed2ce 317 * @brief I2C MSP Initialization
Deepti 0:9e645e6ed2ce 318 * @param None
Deepti 0:9e645e6ed2ce 319 * @retval None
Deepti 0:9e645e6ed2ce 320 */
Deepti 0:9e645e6ed2ce 321 static void I2C_SHIELDS_MspInit(void)
Deepti 0:9e645e6ed2ce 322 {
Deepti 0:9e645e6ed2ce 323 GPIO_InitTypeDef GPIO_InitStruct;
Deepti 0:9e645e6ed2ce 324
Deepti 0:9e645e6ed2ce 325 /*if(!NUCLEO_I2C_SHIELDS_MUTEX) {
Deepti 0:9e645e6ed2ce 326 NUCLEO_I2C_SHIELDS_MUTEX = osMutexCreate(0);
Deepti 0:9e645e6ed2ce 327 }*/
Deepti 0:9e645e6ed2ce 328 /* Enable I2C GPIO clocks */
Deepti 0:9e645e6ed2ce 329 NUCLEO_I2C_SHIELDS_SCL_SDA_GPIO_CLK_ENABLE();
Deepti 0:9e645e6ed2ce 330
Deepti 0:9e645e6ed2ce 331 /* I2C_SHIELDS SCL and SDA pins configuration -------------------------------------*/
Deepti 0:9e645e6ed2ce 332 GPIO_InitStruct.Pin = NUCLEO_I2C_SHIELDS_SCL_PIN | NUCLEO_I2C_SHIELDS_SDA_PIN;
Deepti 0:9e645e6ed2ce 333 GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
Deepti 0:9e645e6ed2ce 334 GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
Deepti 0:9e645e6ed2ce 335 GPIO_InitStruct.Pull = GPIO_NOPULL;
Deepti 0:9e645e6ed2ce 336 GPIO_InitStruct.Alternate = NUCLEO_I2C_SHIELDS_SCL_SDA_AF;
Deepti 0:9e645e6ed2ce 337 HAL_GPIO_Init(NUCLEO_I2C_SHIELDS_SCL_SDA_GPIO_PORT, &GPIO_InitStruct);
Deepti 0:9e645e6ed2ce 338
Deepti 0:9e645e6ed2ce 339 /* Enable the I2C_SHIELDS peripheral clock */
Deepti 0:9e645e6ed2ce 340 NUCLEO_I2C_SHIELDS_CLK_ENABLE();
Deepti 0:9e645e6ed2ce 341
Deepti 0:9e645e6ed2ce 342 /* Force the I2C peripheral clock reset */
Deepti 0:9e645e6ed2ce 343 NUCLEO_I2C_SHIELDS_FORCE_RESET();
Deepti 0:9e645e6ed2ce 344
Deepti 0:9e645e6ed2ce 345 /* Release the I2C peripheral clock reset */
Deepti 0:9e645e6ed2ce 346 NUCLEO_I2C_SHIELDS_RELEASE_RESET();
Deepti 0:9e645e6ed2ce 347
Deepti 0:9e645e6ed2ce 348 /* Enable and set I2C_SHIELDS Interrupt to the highest priority */
Deepti 0:9e645e6ed2ce 349 HAL_NVIC_SetPriority(NUCLEO_I2C_SHIELDS_EV_IRQn, 0, 0);
Deepti 0:9e645e6ed2ce 350 HAL_NVIC_EnableIRQ(NUCLEO_I2C_SHIELDS_EV_IRQn);
Deepti 0:9e645e6ed2ce 351
Deepti 0:9e645e6ed2ce 352 /* Enable and set I2C_SHIELDS Interrupt to the highest priority */
Deepti 0:9e645e6ed2ce 353 HAL_NVIC_SetPriority(NUCLEO_I2C_SHIELDS_ER_IRQn, 0, 0);
Deepti 0:9e645e6ed2ce 354 HAL_NVIC_EnableIRQ(NUCLEO_I2C_SHIELDS_ER_IRQn);
Deepti 0:9e645e6ed2ce 355 }
Deepti 0:9e645e6ed2ce 356
Deepti 0:9e645e6ed2ce 357
Deepti 0:9e645e6ed2ce 358 /********************************* LINK PRESSURE *****************************/
Deepti 0:9e645e6ed2ce 359 /**
Deepti 0:9e645e6ed2ce 360 * @brief Configures Pressure I2C interface.
Deepti 0:9e645e6ed2ce 361 * @param None
Deepti 0:9e645e6ed2ce 362 * @retval None
Deepti 0:9e645e6ed2ce 363 */
Deepti 0:9e645e6ed2ce 364 void PRESSURE_IO_Init(void)
Deepti 0:9e645e6ed2ce 365 {
Deepti 0:9e645e6ed2ce 366 I2C_SHIELDS_Init();
Deepti 0:9e645e6ed2ce 367 }
Deepti 0:9e645e6ed2ce 368
Deepti 0:9e645e6ed2ce 369 /**
Deepti 0:9e645e6ed2ce 370 * @brief Writes a buffer to the Pressure sensor.
Deepti 0:9e645e6ed2ce 371 * @param pBuffer: pointer to data to be written.
Deepti 0:9e645e6ed2ce 372 * @param DeviceAddr: specifies the slave address to be programmed.
Deepti 0:9e645e6ed2ce 373 * @param RegisterAddr: specifies the Pressure register to be written.
Deepti 0:9e645e6ed2ce 374 * @param NumByteToWrite: number of bytes to be written.
Deepti 0:9e645e6ed2ce 375 * @retval None.
Deepti 0:9e645e6ed2ce 376 */
Deepti 0:9e645e6ed2ce 377 void PRESSURE_IO_Write(uint8_t* pBuffer, uint8_t DeviceAddr, uint8_t RegisterAddr, uint16_t NumByteToWrite)
Deepti 0:9e645e6ed2ce 378 {
Deepti 0:9e645e6ed2ce 379 //NUCLEO_I2C_SHIELDS_MUTEX_TAKE();
Deepti 0:9e645e6ed2ce 380 /* call I2C_SHIELDS Read data bus function */
Deepti 0:9e645e6ed2ce 381 I2C_SHIELDS_WriteData(pBuffer, DeviceAddr, RegisterAddr, NumByteToWrite);
Deepti 0:9e645e6ed2ce 382 //NUCLEO_I2C_SHIELDS_MUTEX_RELEASE();
Deepti 0:9e645e6ed2ce 383 }
Deepti 0:9e645e6ed2ce 384
Deepti 0:9e645e6ed2ce 385 /**
Deepti 0:9e645e6ed2ce 386 * @brief Reads a buffer from the Pressure sensor.
Deepti 0:9e645e6ed2ce 387 * @param pBuffer: pointer to data to be read.
Deepti 0:9e645e6ed2ce 388 * @param DeviceAddr: specifies the address of the device.
Deepti 0:9e645e6ed2ce 389 * @param RegisterAddr: specifies the Pressure internal address register to read from.
Deepti 0:9e645e6ed2ce 390 * @param NumByteToRead: number of bytes to be read.
Deepti 0:9e645e6ed2ce 391 * @retval None.
Deepti 0:9e645e6ed2ce 392 */
Deepti 0:9e645e6ed2ce 393 void PRESSURE_IO_Read(uint8_t* pBuffer, uint8_t DeviceAddr, uint8_t RegisterAddr, uint16_t NumByteToRead)
Deepti 0:9e645e6ed2ce 394 {
Deepti 0:9e645e6ed2ce 395 //NUCLEO_I2C_SHIELDS_MUTEX_TAKE();
Deepti 0:9e645e6ed2ce 396 /* call I2C_SHIELDS Read data bus function */
Deepti 0:9e645e6ed2ce 397 I2C_SHIELDS_ReadData(pBuffer, DeviceAddr, RegisterAddr, NumByteToRead);
Deepti 0:9e645e6ed2ce 398 //NUCLEO_I2C_SHIELDS_MUTEX_RELEASE();
Deepti 0:9e645e6ed2ce 399 }
Deepti 0:9e645e6ed2ce 400
Deepti 0:9e645e6ed2ce 401
Deepti 0:9e645e6ed2ce 402
Deepti 0:9e645e6ed2ce 403
Deepti 0:9e645e6ed2ce 404 /********************************* LINK UVI *****************************/
Deepti 0:9e645e6ed2ce 405 /**
Deepti 0:9e645e6ed2ce 406 * @brief Configures Uvi I2C interface.
Deepti 0:9e645e6ed2ce 407 * @param None
Deepti 0:9e645e6ed2ce 408 * @retval None
Deepti 0:9e645e6ed2ce 409 */
Deepti 0:9e645e6ed2ce 410 void UV_IO_Init(void)
Deepti 0:9e645e6ed2ce 411 {
Deepti 0:9e645e6ed2ce 412 I2C_SHIELDS_Init();
Deepti 0:9e645e6ed2ce 413 }
Deepti 0:9e645e6ed2ce 414
Deepti 0:9e645e6ed2ce 415 /**
Deepti 0:9e645e6ed2ce 416 * @brief Writes a buffer to the Uvi sensor.
Deepti 0:9e645e6ed2ce 417 * @param pBuffer: pointer to data to be written.
Deepti 0:9e645e6ed2ce 418 * @param DeviceAddr: specifies the slave address to be programmed.
Deepti 0:9e645e6ed2ce 419 * @param RegisterAddr: specifies the Pressure register to be written.
Deepti 0:9e645e6ed2ce 420 * @param NumByteToWrite: number of bytes to be written.
Deepti 0:9e645e6ed2ce 421 * @retval None.
Deepti 0:9e645e6ed2ce 422 */
Deepti 0:9e645e6ed2ce 423 void UV_IO_Write(uint8_t* pBuffer, uint8_t DeviceAddr, uint8_t RegisterAddr, uint16_t NumByteToWrite)
Deepti 0:9e645e6ed2ce 424 {
Deepti 0:9e645e6ed2ce 425 //NUCLEO_I2C_SHIELDS_MUTEX_TAKE();
Deepti 0:9e645e6ed2ce 426 /* call I2C_SHIELDS Read data bus function */
Deepti 0:9e645e6ed2ce 427 I2C_SHIELDS_WriteData(pBuffer, DeviceAddr, RegisterAddr, NumByteToWrite);
Deepti 0:9e645e6ed2ce 428 //NUCLEO_I2C_SHIELDS_MUTEX_RELEASE();
Deepti 0:9e645e6ed2ce 429 }
Deepti 0:9e645e6ed2ce 430
Deepti 0:9e645e6ed2ce 431 /**
Deepti 0:9e645e6ed2ce 432 * @brief Reads a buffer from the Uvi sensor.
Deepti 0:9e645e6ed2ce 433 * @param pBuffer: pointer to data to be read.
Deepti 0:9e645e6ed2ce 434 * @param DeviceAddr: specifies the address of the device.
Deepti 0:9e645e6ed2ce 435 * @param RegisterAddr: specifies the Pressure internal address register to read from.
Deepti 0:9e645e6ed2ce 436 * @param NumByteToRead: number of bytes to be read.
Deepti 0:9e645e6ed2ce 437 * @retval None.
Deepti 0:9e645e6ed2ce 438 */
Deepti 0:9e645e6ed2ce 439 void UV_IO_Read(uint8_t* pBuffer, uint8_t DeviceAddr, uint8_t RegisterAddr, uint16_t NumByteToRead)
Deepti 0:9e645e6ed2ce 440 {
Deepti 0:9e645e6ed2ce 441 //NUCLEO_I2C_SHIELDS_MUTEX_TAKE();
Deepti 0:9e645e6ed2ce 442 /* call I2C_SHIELDS Read data bus function */
Deepti 0:9e645e6ed2ce 443 I2C_SHIELDS_ReadData(pBuffer, DeviceAddr, RegisterAddr, NumByteToRead);
Deepti 0:9e645e6ed2ce 444 //NUCLEO_I2C_SHIELDS_MUTEX_RELEASE();
Deepti 0:9e645e6ed2ce 445 }
Deepti 0:9e645e6ed2ce 446
Deepti 0:9e645e6ed2ce 447
Deepti 0:9e645e6ed2ce 448
Deepti 0:9e645e6ed2ce 449
Deepti 0:9e645e6ed2ce 450
Deepti 0:9e645e6ed2ce 451 /********************************* LINK HUM_TEMP *****************************/
Deepti 0:9e645e6ed2ce 452 /**
Deepti 0:9e645e6ed2ce 453 * @brief Configures Uvi I2C interface.
Deepti 0:9e645e6ed2ce 454 * @param None
Deepti 0:9e645e6ed2ce 455 * @retval None
Deepti 0:9e645e6ed2ce 456 */
Deepti 0:9e645e6ed2ce 457 void HUM_TEMP_IO_Init(void)
Deepti 0:9e645e6ed2ce 458 {
Deepti 0:9e645e6ed2ce 459 I2C_SHIELDS_Init();
Deepti 0:9e645e6ed2ce 460 }
Deepti 0:9e645e6ed2ce 461
Deepti 0:9e645e6ed2ce 462 /**
Deepti 0:9e645e6ed2ce 463 * @brief Writes a buffer to the Uvi sensor.
Deepti 0:9e645e6ed2ce 464 * @param pBuffer: pointer to data to be written.
Deepti 0:9e645e6ed2ce 465 * @param DeviceAddr: specifies the slave address to be programmed.
Deepti 0:9e645e6ed2ce 466 * @param RegisterAddr: specifies the Pressure register to be written.
Deepti 0:9e645e6ed2ce 467 * @param NumByteToWrite: number of bytes to be written.
Deepti 0:9e645e6ed2ce 468 * @retval None.
Deepti 0:9e645e6ed2ce 469 */
Deepti 0:9e645e6ed2ce 470 void HUM_TEMP_IO_Write(uint8_t* pBuffer, uint8_t DeviceAddr, uint8_t RegisterAddr, uint16_t NumByteToWrite)
Deepti 0:9e645e6ed2ce 471 {
Deepti 0:9e645e6ed2ce 472 //NUCLEO_I2C_SHIELDS_MUTEX_TAKE();
Deepti 0:9e645e6ed2ce 473 /* call I2C_SHIELDS Read data bus function */
Deepti 0:9e645e6ed2ce 474 I2C_SHIELDS_WriteData(pBuffer, DeviceAddr, RegisterAddr, NumByteToWrite);
Deepti 0:9e645e6ed2ce 475 //NUCLEO_I2C_SHIELDS_MUTEX_RELEASE();
Deepti 0:9e645e6ed2ce 476 }
Deepti 0:9e645e6ed2ce 477
Deepti 0:9e645e6ed2ce 478 /**
Deepti 0:9e645e6ed2ce 479 * @brief Reads a buffer from the Uvi sensor.
Deepti 0:9e645e6ed2ce 480 * @param pBuffer: pointer to data to be read.
Deepti 0:9e645e6ed2ce 481 * @param DeviceAddr: specifies the address of the device.
Deepti 0:9e645e6ed2ce 482 * @param RegisterAddr: specifies the Pressure internal address register to read from.
Deepti 0:9e645e6ed2ce 483 * @param NumByteToRead: number of bytes to be read.
Deepti 0:9e645e6ed2ce 484 * @retval None.
Deepti 0:9e645e6ed2ce 485 */
Deepti 0:9e645e6ed2ce 486 void HUM_TEMP_IO_Read(uint8_t* pBuffer, uint8_t DeviceAddr, uint8_t RegisterAddr, uint16_t NumByteToRead)
Deepti 0:9e645e6ed2ce 487 {
Deepti 0:9e645e6ed2ce 488 //NUCLEO_I2C_SHIELDS_MUTEX_TAKE();
Deepti 0:9e645e6ed2ce 489 /* call I2C_SHIELDS Read data bus function */
Deepti 0:9e645e6ed2ce 490 I2C_SHIELDS_ReadData(pBuffer, DeviceAddr, RegisterAddr, NumByteToRead);
Deepti 0:9e645e6ed2ce 491 //NUCLEO_I2C_SHIELDS_MUTEX_RELEASE();
Deepti 0:9e645e6ed2ce 492 }
Deepti 0:9e645e6ed2ce 493
Deepti 0:9e645e6ed2ce 494 /**
Deepti 0:9e645e6ed2ce 495 * @}
Deepti 0:9e645e6ed2ce 496 */
Deepti 0:9e645e6ed2ce 497
Deepti 0:9e645e6ed2ce 498 /**
Deepti 0:9e645e6ed2ce 499 * @}
Deepti 0:9e645e6ed2ce 500 */
Deepti 0:9e645e6ed2ce 501
Deepti 0:9e645e6ed2ce 502 /**
Deepti 0:9e645e6ed2ce 503 * @}
Deepti 0:9e645e6ed2ce 504 */
Deepti 0:9e645e6ed2ce 505
Deepti 0:9e645e6ed2ce 506 /**
Deepti 0:9e645e6ed2ce 507 * @}
Deepti 0:9e645e6ed2ce 508 */
Deepti 0:9e645e6ed2ce 509
Deepti 0:9e645e6ed2ce 510 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Deepti 0:9e645e6ed2ce 511