Dependencies: DHT
tm_stm32f4_i2c.h@1:68a123e2d60b, 2018-09-18 (annotated)
- Committer:
- binoit
- Date:
- Tue Sep 18 08:06:44 2018 +0000
- Revision:
- 1:68a123e2d60b
- Parent:
- 0:3adb31fbd547
Add_DHT22
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
binoit | 0:3adb31fbd547 | 1 | /** |
binoit | 0:3adb31fbd547 | 2 | * @author Tilen Majerle |
binoit | 0:3adb31fbd547 | 3 | * @email tilen@majerle.eu |
binoit | 0:3adb31fbd547 | 4 | * @website http://stm32f4-discovery.com |
binoit | 0:3adb31fbd547 | 5 | * @link http://stm32f4-discovery.com/2014/05/library-09-i2c-for-stm32f4xx/ |
binoit | 0:3adb31fbd547 | 6 | * @version v1.6.1 |
binoit | 0:3adb31fbd547 | 7 | * @ide Keil uVision |
binoit | 0:3adb31fbd547 | 8 | * @license GNU GPL v3 |
binoit | 0:3adb31fbd547 | 9 | * @brief I2C library for STM32F4xx |
binoit | 0:3adb31fbd547 | 10 | * |
binoit | 0:3adb31fbd547 | 11 | @verbatim |
binoit | 0:3adb31fbd547 | 12 | ---------------------------------------------------------------------- |
binoit | 0:3adb31fbd547 | 13 | Copyright (C) Tilen Majerle, 2015 |
binoit | 0:3adb31fbd547 | 14 | |
binoit | 0:3adb31fbd547 | 15 | This program is free software: you can redistribute it and/or modify |
binoit | 0:3adb31fbd547 | 16 | it under the terms of the GNU General Public License as published by |
binoit | 0:3adb31fbd547 | 17 | the Free Software Foundation, either version 3 of the License, or |
binoit | 0:3adb31fbd547 | 18 | any later version. |
binoit | 0:3adb31fbd547 | 19 | |
binoit | 0:3adb31fbd547 | 20 | This program is distributed in the hope that it will be useful, |
binoit | 0:3adb31fbd547 | 21 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
binoit | 0:3adb31fbd547 | 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
binoit | 0:3adb31fbd547 | 23 | GNU General Public License for more details. |
binoit | 0:3adb31fbd547 | 24 | |
binoit | 0:3adb31fbd547 | 25 | You should have received a copy of the GNU General Public License |
binoit | 0:3adb31fbd547 | 26 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
binoit | 0:3adb31fbd547 | 27 | ---------------------------------------------------------------------- |
binoit | 0:3adb31fbd547 | 28 | @endverbatim |
binoit | 0:3adb31fbd547 | 29 | */ |
binoit | 0:3adb31fbd547 | 30 | #ifndef TM_I2C_H |
binoit | 0:3adb31fbd547 | 31 | #define TM_I2C_H 161 |
binoit | 0:3adb31fbd547 | 32 | /** |
binoit | 0:3adb31fbd547 | 33 | * @addtogroup TM_STM32F4xx_Libraries |
binoit | 0:3adb31fbd547 | 34 | * @{ |
binoit | 0:3adb31fbd547 | 35 | */ |
binoit | 0:3adb31fbd547 | 36 | |
binoit | 0:3adb31fbd547 | 37 | /** |
binoit | 0:3adb31fbd547 | 38 | * @defgroup TM_I2C |
binoit | 0:3adb31fbd547 | 39 | * @brief I2C library for STM32F4xx - http://stm32f4-discovery.com/2014/05/library-09-i2c-for-stm32f4xx/ |
binoit | 0:3adb31fbd547 | 40 | * @{ |
binoit | 0:3adb31fbd547 | 41 | * |
binoit | 0:3adb31fbd547 | 42 | * \par Pinout |
binoit | 0:3adb31fbd547 | 43 | * |
binoit | 0:3adb31fbd547 | 44 | @verbatim |
binoit | 0:3adb31fbd547 | 45 | |PINSPACK 1 |PINSPACK 2 |PINSPACK 3 |
binoit | 0:3adb31fbd547 | 46 | I2CX |SCL SDA |SCL SDA |SCL SDA |
binoit | 0:3adb31fbd547 | 47 | | | | |
binoit | 0:3adb31fbd547 | 48 | I2C1 |PB6 PB7 |PB8 PB9 |PB6 PB9 |
binoit | 0:3adb31fbd547 | 49 | I2C2 |PB10 PB11 |PF1 PF0 |PH4 PH5 |
binoit | 0:3adb31fbd547 | 50 | I2C3 |PA8 PC9 |PH7 PH8 |- - |
binoit | 0:3adb31fbd547 | 51 | @endverbatim |
binoit | 0:3adb31fbd547 | 52 | * |
binoit | 0:3adb31fbd547 | 53 | * \par Custom pinout |
binoit | 0:3adb31fbd547 | 54 | * |
binoit | 0:3adb31fbd547 | 55 | * In case these pins are not good for you, you can use |
binoit | 0:3adb31fbd547 | 56 | * @ref TM_I2C_PinsPack_Custom in @ref TM_I2C_Init() function and callback function will be called, |
binoit | 0:3adb31fbd547 | 57 | * where you can initialize your custom pinout for your I2C peripheral |
binoit | 0:3adb31fbd547 | 58 | * |
binoit | 0:3adb31fbd547 | 59 | * Possible changes in your defines.h file: |
binoit | 0:3adb31fbd547 | 60 | * Change x to your I2C used, 1-3 |
binoit | 0:3adb31fbd547 | 61 | * |
binoit | 0:3adb31fbd547 | 62 | @verbatim |
binoit | 0:3adb31fbd547 | 63 | //By default library support only 7bit long address |
binoit | 0:3adb31fbd547 | 64 | #define TM_I2Cx_ACKNOWLEDGED_ADDRESS I2C_AcknowledgedAddress_7bit |
binoit | 0:3adb31fbd547 | 65 | //Library supports I2C mode |
binoit | 0:3adb31fbd547 | 66 | #define TM_I2Cx_MODE I2C_Mode_I2C |
binoit | 0:3adb31fbd547 | 67 | //Own address, if slave mode |
binoit | 0:3adb31fbd547 | 68 | #define TM_I2Cx_OWN_ADDRESS 0x00 |
binoit | 0:3adb31fbd547 | 69 | //By default, disable ack |
binoit | 0:3adb31fbd547 | 70 | #define TM_I2Cx_ACK I2C_Ack_Disable |
binoit | 0:3adb31fbd547 | 71 | //Duty cycle 2, 50% |
binoit | 0:3adb31fbd547 | 72 | #define TM_I2Cx_DUTY_CYCLE I2C_DutyCycle_2 |
binoit | 0:3adb31fbd547 | 73 | @endverbatim |
binoit | 0:3adb31fbd547 | 74 | * |
binoit | 0:3adb31fbd547 | 75 | * \par Changelog |
binoit | 0:3adb31fbd547 | 76 | * |
binoit | 0:3adb31fbd547 | 77 | @verbatim |
binoit | 0:3adb31fbd547 | 78 | Version 1.6.1 |
binoit | 0:3adb31fbd547 | 79 | - March 31, 2015 |
binoit | 0:3adb31fbd547 | 80 | - Fixed I2C issue when sometime it didn't send data |
binoit | 0:3adb31fbd547 | 81 | |
binoit | 0:3adb31fbd547 | 82 | Version 1.6 |
binoit | 0:3adb31fbd547 | 83 | - March 13, 2015 |
binoit | 0:3adb31fbd547 | 84 | - Added new function to write multi bytes to device without specify register address |
binoit | 0:3adb31fbd547 | 85 | |
binoit | 0:3adb31fbd547 | 86 | Version 1.5 |
binoit | 0:3adb31fbd547 | 87 | - March 10, 2015 |
binoit | 0:3adb31fbd547 | 88 | - Updated to be more independent of HAL/STD drivers. |
binoit | 0:3adb31fbd547 | 89 | |
binoit | 0:3adb31fbd547 | 90 | Version 1.4 |
binoit | 0:3adb31fbd547 | 91 | - March 08, 2015 |
binoit | 0:3adb31fbd547 | 92 | - Added support for new GPIO settings |
binoit | 0:3adb31fbd547 | 93 | |
binoit | 0:3adb31fbd547 | 94 | Version 1.3 |
binoit | 0:3adb31fbd547 | 95 | - December 22, 2014 |
binoit | 0:3adb31fbd547 | 96 | - Added option to read multi bytes from device without setting register from where |
binoit | 0:3adb31fbd547 | 97 | |
binoit | 0:3adb31fbd547 | 98 | Version 1.2 |
binoit | 0:3adb31fbd547 | 99 | - August 14, 2014 |
binoit | 0:3adb31fbd547 | 100 | - If you connect more devices on one I2C with different max SCL speed, low speed will be always selected. |
binoit | 0:3adb31fbd547 | 101 | - Added some additional pins for I2C |
binoit | 0:3adb31fbd547 | 102 | |
binoit | 0:3adb31fbd547 | 103 | Version 1.1 |
binoit | 0:3adb31fbd547 | 104 | - September 08, 2014 |
binoit | 0:3adb31fbd547 | 105 | - Added support to check if device is connected to I2C bus |
binoit | 0:3adb31fbd547 | 106 | |
binoit | 0:3adb31fbd547 | 107 | Version 1.0 |
binoit | 0:3adb31fbd547 | 108 | - First release |
binoit | 0:3adb31fbd547 | 109 | @endverbatim |
binoit | 0:3adb31fbd547 | 110 | * |
binoit | 0:3adb31fbd547 | 111 | * \par Dependencies |
binoit | 0:3adb31fbd547 | 112 | * |
binoit | 0:3adb31fbd547 | 113 | @verbatim |
binoit | 0:3adb31fbd547 | 114 | - STM32F4xx |
binoit | 0:3adb31fbd547 | 115 | - STM32F4xx I2C |
binoit | 0:3adb31fbd547 | 116 | - defines.h |
binoit | 0:3adb31fbd547 | 117 | - attributes.h |
binoit | 0:3adb31fbd547 | 118 | - TM GPIO |
binoit | 0:3adb31fbd547 | 119 | @endverbatim |
binoit | 0:3adb31fbd547 | 120 | */ |
binoit | 0:3adb31fbd547 | 121 | #include "stm32f4xx.h" |
binoit | 0:3adb31fbd547 | 122 | #include "stm32f4xx_i2c.h" |
binoit | 0:3adb31fbd547 | 123 | #include "attributes.h" |
binoit | 0:3adb31fbd547 | 124 | #include "defines.h" |
binoit | 0:3adb31fbd547 | 125 | #include "tm_stm32f4_gpio.h" |
binoit | 0:3adb31fbd547 | 126 | |
binoit | 0:3adb31fbd547 | 127 | /** |
binoit | 0:3adb31fbd547 | 128 | * @defgroup TM_I2C_Macros |
binoit | 0:3adb31fbd547 | 129 | * @brief Library defines |
binoit | 0:3adb31fbd547 | 130 | * @{ |
binoit | 0:3adb31fbd547 | 131 | */ |
binoit | 0:3adb31fbd547 | 132 | |
binoit | 0:3adb31fbd547 | 133 | /** |
binoit | 0:3adb31fbd547 | 134 | * @brief Timeout for I2C |
binoit | 0:3adb31fbd547 | 135 | */ |
binoit | 0:3adb31fbd547 | 136 | #ifndef TM_I2C_TIMEOUT |
binoit | 0:3adb31fbd547 | 137 | #define TM_I2C_TIMEOUT 20000 |
binoit | 0:3adb31fbd547 | 138 | #endif |
binoit | 0:3adb31fbd547 | 139 | |
binoit | 0:3adb31fbd547 | 140 | /* I2C1 settings, change them in defines.h project file */ |
binoit | 0:3adb31fbd547 | 141 | #ifndef TM_I2C1_ACKNOWLEDGED_ADDRESS |
binoit | 0:3adb31fbd547 | 142 | #define TM_I2C1_ACKNOWLEDGED_ADDRESS I2C_AcknowledgedAddress_7bit |
binoit | 0:3adb31fbd547 | 143 | #endif |
binoit | 0:3adb31fbd547 | 144 | #ifndef TM_I2C1_MODE |
binoit | 0:3adb31fbd547 | 145 | #define TM_I2C1_MODE I2C_Mode_I2C |
binoit | 0:3adb31fbd547 | 146 | #endif |
binoit | 0:3adb31fbd547 | 147 | #ifndef TM_I2C1_OWN_ADDRESS |
binoit | 0:3adb31fbd547 | 148 | #define TM_I2C1_OWN_ADDRESS 0x00 |
binoit | 0:3adb31fbd547 | 149 | #endif |
binoit | 0:3adb31fbd547 | 150 | #ifndef TM_I2C1_ACK |
binoit | 0:3adb31fbd547 | 151 | #define TM_I2C1_ACK I2C_Ack_Disable |
binoit | 0:3adb31fbd547 | 152 | #endif |
binoit | 0:3adb31fbd547 | 153 | #ifndef TM_I2C1_DUTY_CYCLE |
binoit | 0:3adb31fbd547 | 154 | #define TM_I2C1_DUTY_CYCLE I2C_DutyCycle_2 |
binoit | 0:3adb31fbd547 | 155 | #endif |
binoit | 0:3adb31fbd547 | 156 | |
binoit | 0:3adb31fbd547 | 157 | /* I2C2 settings, change them in defines.h project file */ |
binoit | 0:3adb31fbd547 | 158 | #ifndef TM_I2C2_ACKNOWLEDGED_ADDRESS |
binoit | 0:3adb31fbd547 | 159 | #define TM_I2C2_ACKNOWLEDGED_ADDRESS I2C_AcknowledgedAddress_7bit |
binoit | 0:3adb31fbd547 | 160 | #endif |
binoit | 0:3adb31fbd547 | 161 | #ifndef TM_I2C2_MODE |
binoit | 0:3adb31fbd547 | 162 | #define TM_I2C2_MODE I2C_Mode_I2C |
binoit | 0:3adb31fbd547 | 163 | #endif |
binoit | 0:3adb31fbd547 | 164 | #ifndef TM_I2C2_OWN_ADDRESS |
binoit | 0:3adb31fbd547 | 165 | #define TM_I2C2_OWN_ADDRESS 0x00 |
binoit | 0:3adb31fbd547 | 166 | #endif |
binoit | 0:3adb31fbd547 | 167 | #ifndef TM_I2C2_ACK |
binoit | 0:3adb31fbd547 | 168 | #define TM_I2C2_ACK I2C_Ack_Disable |
binoit | 0:3adb31fbd547 | 169 | #endif |
binoit | 0:3adb31fbd547 | 170 | #ifndef TM_I2C2_DUTY_CYCLE |
binoit | 0:3adb31fbd547 | 171 | #define TM_I2C2_DUTY_CYCLE I2C_DutyCycle_2 |
binoit | 0:3adb31fbd547 | 172 | #endif |
binoit | 0:3adb31fbd547 | 173 | |
binoit | 0:3adb31fbd547 | 174 | /* I2C3 settings, change them in defines.h project file */ |
binoit | 0:3adb31fbd547 | 175 | #ifndef TM_I2C3_ACKNOWLEDGED_ADDRESS |
binoit | 0:3adb31fbd547 | 176 | #define TM_I2C3_ACKNOWLEDGED_ADDRESS I2C_AcknowledgedAddress_7bit |
binoit | 0:3adb31fbd547 | 177 | #endif |
binoit | 0:3adb31fbd547 | 178 | #ifndef TM_I2C3_MODE |
binoit | 0:3adb31fbd547 | 179 | #define TM_I2C3_MODE I2C_Mode_I2C |
binoit | 0:3adb31fbd547 | 180 | #endif |
binoit | 0:3adb31fbd547 | 181 | #ifndef TM_I2C3_OWN_ADDRESS |
binoit | 0:3adb31fbd547 | 182 | #define TM_I2C3_OWN_ADDRESS 0x00 |
binoit | 0:3adb31fbd547 | 183 | #endif |
binoit | 0:3adb31fbd547 | 184 | #ifndef TM_I2C3_ACK |
binoit | 0:3adb31fbd547 | 185 | #define TM_I2C3_ACK I2C_Ack_Disable |
binoit | 0:3adb31fbd547 | 186 | #endif |
binoit | 0:3adb31fbd547 | 187 | #ifndef TM_I2C3_DUTY_CYCLE |
binoit | 0:3adb31fbd547 | 188 | #define TM_I2C3_DUTY_CYCLE I2C_DutyCycle_2 |
binoit | 0:3adb31fbd547 | 189 | #endif |
binoit | 0:3adb31fbd547 | 190 | |
binoit | 0:3adb31fbd547 | 191 | #define TM_I2C_CLOCK_STANDARD 100000 /*!< I2C Standard speed */ |
binoit | 0:3adb31fbd547 | 192 | #define TM_I2C_CLOCK_FAST_MODE 400000 /*!< I2C Fast mode speed */ |
binoit | 0:3adb31fbd547 | 193 | #define TM_I2C_CLOCK_FAST_MODE_PLUS 1000000 /*!< I2C Fast mode plus speed */ |
binoit | 0:3adb31fbd547 | 194 | #define TM_I2C_CLOCK_HIGH_SPEED 3400000 /*!< I2C High speed */ |
binoit | 0:3adb31fbd547 | 195 | |
binoit | 0:3adb31fbd547 | 196 | /** |
binoit | 0:3adb31fbd547 | 197 | * @} |
binoit | 0:3adb31fbd547 | 198 | */ |
binoit | 0:3adb31fbd547 | 199 | |
binoit | 0:3adb31fbd547 | 200 | /** |
binoit | 0:3adb31fbd547 | 201 | * @defgroup TM_I2C_Typedefs |
binoit | 0:3adb31fbd547 | 202 | * @brief Library Typedefs |
binoit | 0:3adb31fbd547 | 203 | * @{ |
binoit | 0:3adb31fbd547 | 204 | */ |
binoit | 0:3adb31fbd547 | 205 | |
binoit | 0:3adb31fbd547 | 206 | /** |
binoit | 0:3adb31fbd547 | 207 | * @brief I2C pinspack enumeration |
binoit | 0:3adb31fbd547 | 208 | */ |
binoit | 0:3adb31fbd547 | 209 | typedef enum { |
binoit | 0:3adb31fbd547 | 210 | TM_I2C_PinsPack_1, /*!< Use Pinspack1 from Pinout table for I2Cx */ |
binoit | 0:3adb31fbd547 | 211 | TM_I2C_PinsPack_2, /*!< Use Pinspack2 from Pinout table for I2Cx */ |
binoit | 0:3adb31fbd547 | 212 | TM_I2C_PinsPack_3, /*!< Use Pinspack3 from Pinout table for I2Cx */ |
binoit | 0:3adb31fbd547 | 213 | TM_I2C_PinsPack_Custom /*!< Use custom pins for I2Cx */ |
binoit | 0:3adb31fbd547 | 214 | } TM_I2C_PinsPack_t; |
binoit | 0:3adb31fbd547 | 215 | |
binoit | 0:3adb31fbd547 | 216 | /** |
binoit | 0:3adb31fbd547 | 217 | * @} |
binoit | 0:3adb31fbd547 | 218 | */ |
binoit | 0:3adb31fbd547 | 219 | |
binoit | 0:3adb31fbd547 | 220 | /** |
binoit | 0:3adb31fbd547 | 221 | * @defgroup TM_I2C_Functions |
binoit | 0:3adb31fbd547 | 222 | * @brief Library Functions |
binoit | 0:3adb31fbd547 | 223 | * @{ |
binoit | 0:3adb31fbd547 | 224 | */ |
binoit | 0:3adb31fbd547 | 225 | |
binoit | 0:3adb31fbd547 | 226 | /** |
binoit | 0:3adb31fbd547 | 227 | * @brief Initializes I2C |
binoit | 0:3adb31fbd547 | 228 | * @param *I2Cx: I2C used |
binoit | 0:3adb31fbd547 | 229 | * @param pinspack: Pins used. This parameter can have a value of @ref TM_I2C_PinsPack_t enumeration |
binoit | 0:3adb31fbd547 | 230 | * @param clockSpeed: Clock speed for SCL in Hertz |
binoit | 0:3adb31fbd547 | 231 | * @retval None |
binoit | 0:3adb31fbd547 | 232 | */ |
binoit | 0:3adb31fbd547 | 233 | void TM_I2C_Init(I2C_TypeDef* I2Cx, TM_I2C_PinsPack_t pinspack, uint32_t clockSpeed); |
binoit | 0:3adb31fbd547 | 234 | |
binoit | 0:3adb31fbd547 | 235 | /** |
binoit | 0:3adb31fbd547 | 236 | * @brief Reads single byte from slave |
binoit | 0:3adb31fbd547 | 237 | * @param *I2Cx: I2C used |
binoit | 0:3adb31fbd547 | 238 | * @param address: 7 bit slave address, left aligned, bits 7:1 are used, LSB bit is not used |
binoit | 0:3adb31fbd547 | 239 | * @param reg: register to read from |
binoit | 0:3adb31fbd547 | 240 | * @retval Data from slave |
binoit | 0:3adb31fbd547 | 241 | */ |
binoit | 0:3adb31fbd547 | 242 | uint8_t TM_I2C_Read(I2C_TypeDef* I2Cx, uint8_t address, uint8_t reg); |
binoit | 0:3adb31fbd547 | 243 | |
binoit | 0:3adb31fbd547 | 244 | /** |
binoit | 0:3adb31fbd547 | 245 | * @brief Reads multi bytes from slave |
binoit | 0:3adb31fbd547 | 246 | * @param *I2Cx: I2C used |
binoit | 0:3adb31fbd547 | 247 | * @param uint8_t address: 7 bit slave address, left aligned, bits 7:1 are used, LSB bit is not used |
binoit | 0:3adb31fbd547 | 248 | * @param uint8_t reg: register to read from |
binoit | 0:3adb31fbd547 | 249 | * @param uint8_t *data: pointer to data array to store data from slave |
binoit | 0:3adb31fbd547 | 250 | * @param uint8_t count: how many bytes will be read |
binoit | 0:3adb31fbd547 | 251 | * @retval None |
binoit | 0:3adb31fbd547 | 252 | */ |
binoit | 0:3adb31fbd547 | 253 | void TM_I2C_ReadMulti(I2C_TypeDef* I2Cx, uint8_t address, uint8_t reg, uint8_t *data, uint16_t count); |
binoit | 0:3adb31fbd547 | 254 | |
binoit | 0:3adb31fbd547 | 255 | /** |
binoit | 0:3adb31fbd547 | 256 | * @brief Reads byte from slave without specify register address |
binoit | 0:3adb31fbd547 | 257 | * @param *I2Cx: I2C used |
binoit | 0:3adb31fbd547 | 258 | * @param address: 7 bit slave address, left aligned, bits 7:1 are used, LSB bit is not used |
binoit | 0:3adb31fbd547 | 259 | * @retval Data from slave |
binoit | 0:3adb31fbd547 | 260 | */ |
binoit | 0:3adb31fbd547 | 261 | uint8_t TM_I2C_ReadNoRegister(I2C_TypeDef* I2Cx, uint8_t address); |
binoit | 0:3adb31fbd547 | 262 | |
binoit | 0:3adb31fbd547 | 263 | /** |
binoit | 0:3adb31fbd547 | 264 | * @brief Reads multi bytes from slave without setting register from where to start read |
binoit | 0:3adb31fbd547 | 265 | * @param *I2Cx: I2C used |
binoit | 0:3adb31fbd547 | 266 | * @param address: 7 bit slave address, left aligned, bits 7:1 are used, LSB bit is not used |
binoit | 0:3adb31fbd547 | 267 | * @param *data: pointer to data array to store data from slave |
binoit | 0:3adb31fbd547 | 268 | * @param count: how many bytes will be read |
binoit | 0:3adb31fbd547 | 269 | * @retval None |
binoit | 0:3adb31fbd547 | 270 | */ |
binoit | 0:3adb31fbd547 | 271 | void TM_I2C_ReadMultiNoRegister(I2C_TypeDef* I2Cx, uint8_t address, uint8_t* data, uint16_t count); |
binoit | 0:3adb31fbd547 | 272 | |
binoit | 0:3adb31fbd547 | 273 | /** |
binoit | 0:3adb31fbd547 | 274 | * @brief Writes single byte to slave |
binoit | 0:3adb31fbd547 | 275 | * @param *I2Cx: I2C used |
binoit | 0:3adb31fbd547 | 276 | * @param address: 7 bit slave address, left aligned, bits 7:1 are used, LSB bit is not used |
binoit | 0:3adb31fbd547 | 277 | * @param reg: register to write to |
binoit | 0:3adb31fbd547 | 278 | * @param data: data to be written |
binoit | 0:3adb31fbd547 | 279 | * @retval None |
binoit | 0:3adb31fbd547 | 280 | */ |
binoit | 0:3adb31fbd547 | 281 | void TM_I2C_Write(I2C_TypeDef* I2Cx, uint8_t address, uint8_t reg, uint8_t data); |
binoit | 0:3adb31fbd547 | 282 | |
binoit | 0:3adb31fbd547 | 283 | /** |
binoit | 0:3adb31fbd547 | 284 | * @brief Writes multi bytes to slave |
binoit | 0:3adb31fbd547 | 285 | * @param *I2Cx: I2C used |
binoit | 0:3adb31fbd547 | 286 | * @param address: 7 bit slave address, left aligned, bits 7:1 are used, LSB bit is not used |
binoit | 0:3adb31fbd547 | 287 | * @param reg: register to write to |
binoit | 0:3adb31fbd547 | 288 | * @param *data: pointer to data array to write it to slave |
binoit | 0:3adb31fbd547 | 289 | * @param count: how many bytes will be written |
binoit | 0:3adb31fbd547 | 290 | * @retval None |
binoit | 0:3adb31fbd547 | 291 | */ |
binoit | 0:3adb31fbd547 | 292 | void TM_I2C_WriteMulti(I2C_TypeDef* I2Cx, uint8_t address, uint8_t reg, uint8_t *data, uint16_t count); |
binoit | 0:3adb31fbd547 | 293 | |
binoit | 0:3adb31fbd547 | 294 | /** |
binoit | 0:3adb31fbd547 | 295 | * @brief Writes byte to slave without specify register address |
binoit | 0:3adb31fbd547 | 296 | * |
binoit | 0:3adb31fbd547 | 297 | * Useful if you have I2C device to read like that: |
binoit | 0:3adb31fbd547 | 298 | * - I2C START |
binoit | 0:3adb31fbd547 | 299 | * - SEND DEVICE ADDRESS |
binoit | 0:3adb31fbd547 | 300 | * - SEND DATA BYTE |
binoit | 0:3adb31fbd547 | 301 | * - I2C STOP |
binoit | 0:3adb31fbd547 | 302 | * |
binoit | 0:3adb31fbd547 | 303 | * @param *I2Cx: I2C used |
binoit | 0:3adb31fbd547 | 304 | * @param address: 7 bit slave address, left aligned, bits 7:1 are used, LSB bit is not used |
binoit | 0:3adb31fbd547 | 305 | * @param data: data byte which will be send to device |
binoit | 0:3adb31fbd547 | 306 | * @retval None |
binoit | 0:3adb31fbd547 | 307 | */ |
binoit | 0:3adb31fbd547 | 308 | void TM_I2C_WriteNoRegister(I2C_TypeDef* I2Cx, uint8_t address, uint8_t data); |
binoit | 0:3adb31fbd547 | 309 | |
binoit | 0:3adb31fbd547 | 310 | /** |
binoit | 0:3adb31fbd547 | 311 | * @brief Writes multi bytes to slave without setting register from where to start write |
binoit | 0:3adb31fbd547 | 312 | * @param *I2Cx: I2C used |
binoit | 0:3adb31fbd547 | 313 | * @param address: 7 bit slave address, left aligned, bits 7:1 are used, LSB bit is not used |
binoit | 0:3adb31fbd547 | 314 | * @param *data: pointer to data array to write data to slave |
binoit | 0:3adb31fbd547 | 315 | * @param count: how many bytes you want to write |
binoit | 0:3adb31fbd547 | 316 | * @retval None |
binoit | 0:3adb31fbd547 | 317 | */ |
binoit | 0:3adb31fbd547 | 318 | void TM_I2C_WriteMultiNoRegister(I2C_TypeDef* I2Cx, uint8_t address, uint8_t* data, uint16_t count); |
binoit | 0:3adb31fbd547 | 319 | |
binoit | 0:3adb31fbd547 | 320 | /** |
binoit | 0:3adb31fbd547 | 321 | * @brief Checks if device is connected to I2C bus |
binoit | 0:3adb31fbd547 | 322 | * @param *I2Cx: I2C used |
binoit | 0:3adb31fbd547 | 323 | * @param address: 7 bit slave address, left aligned, bits 7:1 are used, LSB bit is not used |
binoit | 0:3adb31fbd547 | 324 | * @retval Device status: |
binoit | 0:3adb31fbd547 | 325 | * - 0: Device is not connected |
binoit | 0:3adb31fbd547 | 326 | * - > 0: Device is connected |
binoit | 0:3adb31fbd547 | 327 | */ |
binoit | 0:3adb31fbd547 | 328 | uint8_t TM_I2C_IsDeviceConnected(I2C_TypeDef* I2Cx, uint8_t address); |
binoit | 0:3adb31fbd547 | 329 | |
binoit | 0:3adb31fbd547 | 330 | /** |
binoit | 0:3adb31fbd547 | 331 | * @brief I2C Start condition |
binoit | 0:3adb31fbd547 | 332 | * @param *I2Cx: I2C used |
binoit | 0:3adb31fbd547 | 333 | * @param address: slave address |
binoit | 0:3adb31fbd547 | 334 | * @param direction: master to slave or slave to master |
binoit | 0:3adb31fbd547 | 335 | * @param ack: ack enabled or disabled |
binoit | 0:3adb31fbd547 | 336 | * @retval Start condition status |
binoit | 0:3adb31fbd547 | 337 | * @note For private use |
binoit | 0:3adb31fbd547 | 338 | */ |
binoit | 0:3adb31fbd547 | 339 | int16_t TM_I2C_Start(I2C_TypeDef* I2Cx, uint8_t address, uint8_t direction, uint8_t ack); |
binoit | 0:3adb31fbd547 | 340 | |
binoit | 0:3adb31fbd547 | 341 | /** |
binoit | 0:3adb31fbd547 | 342 | * @brief Stop condition on I2C |
binoit | 0:3adb31fbd547 | 343 | * @param *I2Cx: I2C used |
binoit | 0:3adb31fbd547 | 344 | * @retval Stop condition status |
binoit | 0:3adb31fbd547 | 345 | * @note For private use |
binoit | 0:3adb31fbd547 | 346 | */ |
binoit | 0:3adb31fbd547 | 347 | uint8_t TM_I2C_Stop(I2C_TypeDef* I2Cx); |
binoit | 0:3adb31fbd547 | 348 | |
binoit | 0:3adb31fbd547 | 349 | /** |
binoit | 0:3adb31fbd547 | 350 | * @brief Reads byte without ack |
binoit | 0:3adb31fbd547 | 351 | * @param *I2Cx: I2C used |
binoit | 0:3adb31fbd547 | 352 | * @retval Byte from slave |
binoit | 0:3adb31fbd547 | 353 | * @note For private use |
binoit | 0:3adb31fbd547 | 354 | */ |
binoit | 0:3adb31fbd547 | 355 | uint8_t TM_I2C_ReadNack(I2C_TypeDef* I2Cx); |
binoit | 0:3adb31fbd547 | 356 | |
binoit | 0:3adb31fbd547 | 357 | /** |
binoit | 0:3adb31fbd547 | 358 | * @brief Reads byte with ack |
binoit | 0:3adb31fbd547 | 359 | * @param *I2Cx: I2C used |
binoit | 0:3adb31fbd547 | 360 | * @retval Byte from slave |
binoit | 0:3adb31fbd547 | 361 | * @note For private use |
binoit | 0:3adb31fbd547 | 362 | */ |
binoit | 0:3adb31fbd547 | 363 | uint8_t TM_I2C_ReadAck(I2C_TypeDef* I2Cx); |
binoit | 0:3adb31fbd547 | 364 | |
binoit | 0:3adb31fbd547 | 365 | /** |
binoit | 0:3adb31fbd547 | 366 | * @brief Writes to slave |
binoit | 0:3adb31fbd547 | 367 | * @param *I2Cx: I2C used |
binoit | 0:3adb31fbd547 | 368 | * @param data: data to be sent |
binoit | 0:3adb31fbd547 | 369 | * @retval None |
binoit | 0:3adb31fbd547 | 370 | * @note For private use |
binoit | 0:3adb31fbd547 | 371 | */ |
binoit | 0:3adb31fbd547 | 372 | void TM_I2C_WriteData(I2C_TypeDef* I2Cx, uint8_t data); |
binoit | 0:3adb31fbd547 | 373 | |
binoit | 0:3adb31fbd547 | 374 | /** |
binoit | 0:3adb31fbd547 | 375 | * @brief Callback for custom pins initialization. |
binoit | 0:3adb31fbd547 | 376 | * |
binoit | 0:3adb31fbd547 | 377 | * When you call TM_I2C_Init() function, and if you pass TM_I2C_PinsPack_Custom to function, |
binoit | 0:3adb31fbd547 | 378 | * then this function will be called where you can initialize custom pins for I2C peripheral. |
binoit | 0:3adb31fbd547 | 379 | * @param *I2Cx: I2C for which initialization will be set |
binoit | 0:3adb31fbd547 | 380 | * @param AlternateFunction: Alternate function which should be used for GPIO initialization |
binoit | 0:3adb31fbd547 | 381 | * @retval None |
binoit | 0:3adb31fbd547 | 382 | * @note With __weak parameter to prevent link errors if not defined by user |
binoit | 0:3adb31fbd547 | 383 | */ |
binoit | 0:3adb31fbd547 | 384 | void TM_I2C_InitCustomPinsCallback(I2C_TypeDef* I2Cx, uint16_t AlternateFunction); |
binoit | 0:3adb31fbd547 | 385 | |
binoit | 0:3adb31fbd547 | 386 | /** |
binoit | 0:3adb31fbd547 | 387 | * @} |
binoit | 0:3adb31fbd547 | 388 | */ |
binoit | 0:3adb31fbd547 | 389 | |
binoit | 0:3adb31fbd547 | 390 | /** |
binoit | 0:3adb31fbd547 | 391 | * @} |
binoit | 0:3adb31fbd547 | 392 | */ |
binoit | 0:3adb31fbd547 | 393 | |
binoit | 0:3adb31fbd547 | 394 | /** |
binoit | 0:3adb31fbd547 | 395 | * @} |
binoit | 0:3adb31fbd547 | 396 | */ |
binoit | 0:3adb31fbd547 | 397 | |
binoit | 0:3adb31fbd547 | 398 | #endif |
binoit | 0:3adb31fbd547 | 399 |