stm32f4xx_ll_i2c.h 69 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908
  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_ll_i2c.h
  4. * @author MCD Application Team
  5. * @brief Header file of I2C LL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  10. *
  11. * Redistribution and use in source and binary forms, with or without modification,
  12. * are permitted provided that the following conditions are met:
  13. * 1. Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  19. * may be used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  25. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  26. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  28. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  29. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  30. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. *
  33. ******************************************************************************
  34. */
  35. /* Define to prevent recursive inclusion -------------------------------------*/
  36. #ifndef __STM32F4xx_LL_I2C_H
  37. #define __STM32F4xx_LL_I2C_H
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. /* Includes ------------------------------------------------------------------*/
  42. #include "stm32f4xx.h"
  43. /** @addtogroup STM32F4xx_LL_Driver
  44. * @{
  45. */
  46. #if defined (I2C1) || defined (I2C2) || defined (I2C3)
  47. /** @defgroup I2C_LL I2C
  48. * @{
  49. */
  50. /* Private types -------------------------------------------------------------*/
  51. /* Private variables ---------------------------------------------------------*/
  52. /* Private constants ---------------------------------------------------------*/
  53. /** @defgroup I2C_LL_Private_Constants I2C Private Constants
  54. * @{
  55. */
  56. /* Defines used to perform compute and check in the macros */
  57. #define LL_I2C_MAX_SPEED_STANDARD 100000U
  58. #define LL_I2C_MAX_SPEED_FAST 400000U
  59. /**
  60. * @}
  61. */
  62. /* Private macros ------------------------------------------------------------*/
  63. #if defined(USE_FULL_LL_DRIVER)
  64. /** @defgroup I2C_LL_Private_Macros I2C Private Macros
  65. * @{
  66. */
  67. /**
  68. * @}
  69. */
  70. #endif /*USE_FULL_LL_DRIVER*/
  71. /* Exported types ------------------------------------------------------------*/
  72. #if defined(USE_FULL_LL_DRIVER)
  73. /** @defgroup I2C_LL_ES_INIT I2C Exported Init structure
  74. * @{
  75. */
  76. typedef struct
  77. {
  78. uint32_t PeripheralMode; /*!< Specifies the peripheral mode.
  79. This parameter can be a value of @ref I2C_LL_EC_PERIPHERAL_MODE
  80. This feature can be modified afterwards using unitary function @ref LL_I2C_SetMode(). */
  81. uint32_t ClockSpeed; /*!< Specifies the clock frequency.
  82. This parameter must be set to a value lower than 400kHz (in Hz)
  83. This feature can be modified afterwards using unitary function @ref LL_I2C_SetClockPeriod()
  84. or @ref LL_I2C_SetDutyCycle() or @ref LL_I2C_SetClockSpeedMode() or @ref LL_I2C_ConfigSpeed(). */
  85. uint32_t DutyCycle; /*!< Specifies the I2C fast mode duty cycle.
  86. This parameter can be a value of @ref I2C_LL_EC_DUTYCYCLE
  87. This feature can be modified afterwards using unitary function @ref LL_I2C_SetDutyCycle(). */
  88. #if defined(I2C_FLTR_ANOFF)&&defined(I2C_FLTR_DNF)
  89. uint32_t AnalogFilter; /*!< Enables or disables analog noise filter.
  90. This parameter can be a value of @ref I2C_LL_EC_ANALOGFILTER_SELECTION
  91. This feature can be modified afterwards using unitary functions @ref LL_I2C_EnableAnalogFilter() or LL_I2C_DisableAnalogFilter(). */
  92. uint32_t DigitalFilter; /*!< Configures the digital noise filter.
  93. This parameter can be a number between Min_Data = 0x00 and Max_Data = 0x0F
  94. This feature can be modified afterwards using unitary function @ref LL_I2C_SetDigitalFilter(). */
  95. #endif
  96. uint32_t OwnAddress1; /*!< Specifies the device own address 1.
  97. This parameter must be a value between Min_Data = 0x00 and Max_Data = 0x3FF
  98. This feature can be modified afterwards using unitary function @ref LL_I2C_SetOwnAddress1(). */
  99. uint32_t TypeAcknowledge; /*!< Specifies the ACKnowledge or Non ACKnowledge condition after the address receive match code or next received byte.
  100. This parameter can be a value of @ref I2C_LL_EC_I2C_ACKNOWLEDGE
  101. This feature can be modified afterwards using unitary function @ref LL_I2C_AcknowledgeNextData(). */
  102. uint32_t OwnAddrSize; /*!< Specifies the device own address 1 size (7-bit or 10-bit).
  103. This parameter can be a value of @ref I2C_LL_EC_OWNADDRESS1
  104. This feature can be modified afterwards using unitary function @ref LL_I2C_SetOwnAddress1(). */
  105. } LL_I2C_InitTypeDef;
  106. /**
  107. * @}
  108. */
  109. #endif /*USE_FULL_LL_DRIVER*/
  110. /* Exported constants --------------------------------------------------------*/
  111. /** @defgroup I2C_LL_Exported_Constants I2C Exported Constants
  112. * @{
  113. */
  114. /** @defgroup I2C_LL_EC_GET_FLAG Get Flags Defines
  115. * @brief Flags defines which can be used with LL_I2C_ReadReg function
  116. * @{
  117. */
  118. #define LL_I2C_SR1_SB I2C_SR1_SB /*!< Start Bit (master mode) */
  119. #define LL_I2C_SR1_ADDR I2C_SR1_ADDR /*!< Address sent (master mode) or
  120. Address matched flag (slave mode) */
  121. #define LL_I2C_SR1_BTF I2C_SR1_BTF /*!< Byte Transfer Finished flag */
  122. #define LL_I2C_SR1_ADD10 I2C_SR1_ADD10 /*!< 10-bit header sent (master mode) */
  123. #define LL_I2C_SR1_STOPF I2C_SR1_STOPF /*!< Stop detection flag (slave mode) */
  124. #define LL_I2C_SR1_RXNE I2C_SR1_RXNE /*!< Data register not empty (receivers) */
  125. #define LL_I2C_SR1_TXE I2C_SR1_TXE /*!< Data register empty (transmitters) */
  126. #define LL_I2C_SR1_BERR I2C_SR1_BERR /*!< Bus error */
  127. #define LL_I2C_SR1_ARLO I2C_SR1_ARLO /*!< Arbitration lost */
  128. #define LL_I2C_SR1_AF I2C_SR1_AF /*!< Acknowledge failure flag */
  129. #define LL_I2C_SR1_OVR I2C_SR1_OVR /*!< Overrun/Underrun */
  130. #define LL_I2C_SR1_PECERR I2C_ISR_PECERR /*!< PEC Error in reception (SMBus mode) */
  131. #define LL_I2C_SR1_TIMEOUT I2C_ISR_TIMEOUT /*!< Timeout detection flag (SMBus mode) */
  132. #define LL_I2C_SR1_SMALERT I2C_ISR_SMALERT /*!< SMBus alert (SMBus mode) */
  133. #define LL_I2C_SR2_MSL I2C_SR2_MSL /*!< Master/Slave flag */
  134. #define LL_I2C_SR2_BUSY I2C_SR2_BUSY /*!< Bus busy flag */
  135. #define LL_I2C_SR2_TRA I2C_SR2_TRA /*!< Transmitter/receiver direction */
  136. #define LL_I2C_SR2_GENCALL I2C_SR2_GENCALL /*!< General call address (Slave mode) */
  137. #define LL_I2C_SR2_SMBDEFAULT I2C_SR2_SMBDEFAULT /*!< SMBus Device default address (Slave mode) */
  138. #define LL_I2C_SR2_SMBHOST I2C_SR2_SMBHOST /*!< SMBus Host address (Slave mode) */
  139. #define LL_I2C_SR2_DUALF I2C_SR2_DUALF /*!< Dual flag (Slave mode) */
  140. /**
  141. * @}
  142. */
  143. /** @defgroup I2C_LL_EC_IT IT Defines
  144. * @brief IT defines which can be used with LL_I2C_ReadReg and LL_I2C_WriteReg functions
  145. * @{
  146. */
  147. #define LL_I2C_CR2_ITEVTEN I2C_CR2_ITEVTEN /*!< Events interrupts enable */
  148. #define LL_I2C_CR2_ITBUFEN I2C_CR2_ITBUFEN /*!< Buffer interrupts enable */
  149. #define LL_I2C_CR2_ITERREN I2C_CR2_ITERREN /*!< Error interrupts enable */
  150. /**
  151. * @}
  152. */
  153. #if defined(I2C_FLTR_ANOFF)
  154. /** @defgroup I2C_LL_EC_ANALOGFILTER_SELECTION Analog Filter Selection
  155. * @{
  156. */
  157. #define LL_I2C_ANALOGFILTER_ENABLE 0x00000000U /*!< Analog filter is enabled. */
  158. #define LL_I2C_ANALOGFILTER_DISABLE I2C_FLTR_ANOFF /*!< Analog filter is disabled.*/
  159. /**
  160. * @}
  161. */
  162. #endif
  163. /** @defgroup I2C_LL_EC_OWNADDRESS1 Own Address 1 Length
  164. * @{
  165. */
  166. #define LL_I2C_OWNADDRESS1_7BIT 0x00004000U /*!< Own address 1 is a 7-bit address. */
  167. #define LL_I2C_OWNADDRESS1_10BIT (uint32_t)(I2C_OAR1_ADDMODE | 0x00004000U) /*!< Own address 1 is a 10-bit address. */
  168. /**
  169. * @}
  170. */
  171. /** @defgroup I2C_LL_EC_DUTYCYCLE Fast Mode Duty Cycle
  172. * @{
  173. */
  174. #define LL_I2C_DUTYCYCLE_2 0x00000000U /*!< I2C fast mode Tlow/Thigh = 2 */
  175. #define LL_I2C_DUTYCYCLE_16_9 I2C_CCR_DUTY /*!< I2C fast mode Tlow/Thigh = 16/9 */
  176. /**
  177. * @}
  178. */
  179. /** @defgroup I2C_LL_EC_CLOCK_SPEED_MODE Master Clock Speed Mode
  180. * @{
  181. */
  182. #define LL_I2C_CLOCK_SPEED_STANDARD_MODE 0x00000000U /*!< Master clock speed range is standard mode */
  183. #define LL_I2C_CLOCK_SPEED_FAST_MODE I2C_CCR_FS /*!< Master clock speed range is fast mode */
  184. /**
  185. * @}
  186. */
  187. /** @defgroup I2C_LL_EC_PERIPHERAL_MODE Peripheral Mode
  188. * @{
  189. */
  190. #define LL_I2C_MODE_I2C 0x00000000U /*!< I2C Master or Slave mode */
  191. #define LL_I2C_MODE_SMBUS_HOST (uint32_t)(I2C_CR1_SMBUS | I2C_CR1_SMBTYPE | I2C_CR1_ENARP) /*!< SMBus Host address acknowledge */
  192. #define LL_I2C_MODE_SMBUS_DEVICE I2C_CR1_SMBUS /*!< SMBus Device default mode (Default address not acknowledge) */
  193. #define LL_I2C_MODE_SMBUS_DEVICE_ARP (uint32_t)(I2C_CR1_SMBUS | I2C_CR1_ENARP) /*!< SMBus Device Default address acknowledge */
  194. /**
  195. * @}
  196. */
  197. /** @defgroup I2C_LL_EC_I2C_ACKNOWLEDGE Acknowledge Generation
  198. * @{
  199. */
  200. #define LL_I2C_ACK I2C_CR1_ACK /*!< ACK is sent after current received byte. */
  201. #define LL_I2C_NACK 0x00000000U /*!< NACK is sent after current received byte.*/
  202. /**
  203. * @}
  204. */
  205. /** @defgroup I2C_LL_EC_DIRECTION Read Write Direction
  206. * @{
  207. */
  208. #define LL_I2C_DIRECTION_WRITE I2C_SR2_TRA /*!< Bus is in write transfer */
  209. #define LL_I2C_DIRECTION_READ 0x00000000U /*!< Bus is in read transfer */
  210. /**
  211. * @}
  212. */
  213. /**
  214. * @}
  215. */
  216. /* Exported macro ------------------------------------------------------------*/
  217. /** @defgroup I2C_LL_Exported_Macros I2C Exported Macros
  218. * @{
  219. */
  220. /** @defgroup I2C_LL_EM_WRITE_READ Common Write and read registers Macros
  221. * @{
  222. */
  223. /**
  224. * @brief Write a value in I2C register
  225. * @param __INSTANCE__ I2C Instance
  226. * @param __REG__ Register to be written
  227. * @param __VALUE__ Value to be written in the register
  228. * @retval None
  229. */
  230. #define LL_I2C_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
  231. /**
  232. * @brief Read a value in I2C register
  233. * @param __INSTANCE__ I2C Instance
  234. * @param __REG__ Register to be read
  235. * @retval Register value
  236. */
  237. #define LL_I2C_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
  238. /**
  239. * @}
  240. */
  241. /** @defgroup I2C_LL_EM_Exported_Macros_Helper Exported_Macros_Helper
  242. * @{
  243. */
  244. /**
  245. * @brief Convert Peripheral Clock Frequency in Mhz.
  246. * @param __PCLK__ This parameter must be a value of peripheral clock (in Hz).
  247. * @retval Value of peripheral clock (in Mhz)
  248. */
  249. #define __LL_I2C_FREQ_HZ_TO_MHZ(__PCLK__) (uint32_t)((__PCLK__)/1000000U)
  250. /**
  251. * @brief Convert Peripheral Clock Frequency in Hz.
  252. * @param __PCLK__ This parameter must be a value of peripheral clock (in Mhz).
  253. * @retval Value of peripheral clock (in Hz)
  254. */
  255. #define __LL_I2C_FREQ_MHZ_TO_HZ(__PCLK__) (uint32_t)((__PCLK__)*1000000U)
  256. /**
  257. * @brief Compute I2C Clock rising time.
  258. * @param __FREQRANGE__ This parameter must be a value of peripheral clock (in Mhz).
  259. * @param __SPEED__ This parameter must be a value lower than 400kHz (in Hz).
  260. * @retval Value between Min_Data=0x02 and Max_Data=0x3F
  261. */
  262. #define __LL_I2C_RISE_TIME(__FREQRANGE__, __SPEED__) (uint32_t)(((__SPEED__) <= LL_I2C_MAX_SPEED_STANDARD) ? ((__FREQRANGE__) + 1U) : ((((__FREQRANGE__) * 300U) / 1000U) + 1U))
  263. /**
  264. * @brief Compute Speed clock range to a Clock Control Register (I2C_CCR_CCR) value.
  265. * @param __PCLK__ This parameter must be a value of peripheral clock (in Hz).
  266. * @param __SPEED__ This parameter must be a value lower than 400kHz (in Hz).
  267. * @param __DUTYCYCLE__ This parameter can be one of the following values:
  268. * @arg @ref LL_I2C_DUTYCYCLE_2
  269. * @arg @ref LL_I2C_DUTYCYCLE_16_9
  270. * @retval Value between Min_Data=0x004 and Max_Data=0xFFF, except in FAST DUTY mode where Min_Data=0x001.
  271. */
  272. #define __LL_I2C_SPEED_TO_CCR(__PCLK__, __SPEED__, __DUTYCYCLE__) (uint32_t)(((__SPEED__) <= LL_I2C_MAX_SPEED_STANDARD)? \
  273. (__LL_I2C_SPEED_STANDARD_TO_CCR((__PCLK__), (__SPEED__))) : \
  274. (__LL_I2C_SPEED_FAST_TO_CCR((__PCLK__), (__SPEED__), (__DUTYCYCLE__))))
  275. /**
  276. * @brief Compute Speed Standard clock range to a Clock Control Register (I2C_CCR_CCR) value.
  277. * @param __PCLK__ This parameter must be a value of peripheral clock (in Hz).
  278. * @param __SPEED__ This parameter must be a value lower than 100kHz (in Hz).
  279. * @retval Value between Min_Data=0x004 and Max_Data=0xFFF.
  280. */
  281. #define __LL_I2C_SPEED_STANDARD_TO_CCR(__PCLK__, __SPEED__) (uint32_t)(((((__PCLK__)/((__SPEED__) << 1U)) & I2C_CCR_CCR) < 4U)? 4U:((__PCLK__) / ((__SPEED__) << 1U)))
  282. /**
  283. * @brief Compute Speed Fast clock range to a Clock Control Register (I2C_CCR_CCR) value.
  284. * @param __PCLK__ This parameter must be a value of peripheral clock (in Hz).
  285. * @param __SPEED__ This parameter must be a value between Min_Data=100Khz and Max_Data=400Khz (in Hz).
  286. * @param __DUTYCYCLE__ This parameter can be one of the following values:
  287. * @arg @ref LL_I2C_DUTYCYCLE_2
  288. * @arg @ref LL_I2C_DUTYCYCLE_16_9
  289. * @retval Value between Min_Data=0x001 and Max_Data=0xFFF
  290. */
  291. #define __LL_I2C_SPEED_FAST_TO_CCR(__PCLK__, __SPEED__, __DUTYCYCLE__) (uint32_t)(((__DUTYCYCLE__) == LL_I2C_DUTYCYCLE_2)? \
  292. (((((__PCLK__) / ((__SPEED__) * 3U)) & I2C_CCR_CCR) == 0U)? 1U:((__PCLK__) / ((__SPEED__) * 3U))) : \
  293. (((((__PCLK__) / ((__SPEED__) * 25U)) & I2C_CCR_CCR) == 0U)? 1U:((__PCLK__) / ((__SPEED__) * 25U))))
  294. /**
  295. * @brief Get the Least significant bits of a 10-Bits address.
  296. * @param __ADDRESS__ This parameter must be a value of a 10-Bits slave address.
  297. * @retval Value between Min_Data=0x00 and Max_Data=0xFF
  298. */
  299. #define __LL_I2C_10BIT_ADDRESS(__ADDRESS__) ((uint8_t)((uint16_t)((__ADDRESS__) & (uint16_t)(0x00FF))))
  300. /**
  301. * @brief Convert a 10-Bits address to a 10-Bits header with Write direction.
  302. * @param __ADDRESS__ This parameter must be a value of a 10-Bits slave address.
  303. * @retval Value between Min_Data=0xF0 and Max_Data=0xF6
  304. */
  305. #define __LL_I2C_10BIT_HEADER_WRITE(__ADDRESS__) ((uint8_t)((uint16_t)((uint16_t)(((uint16_t)((__ADDRESS__) & (uint16_t)(0x0300))) >> 7) | (uint16_t)(0xF0))))
  306. /**
  307. * @brief Convert a 10-Bits address to a 10-Bits header with Read direction.
  308. * @param __ADDRESS__ This parameter must be a value of a 10-Bits slave address.
  309. * @retval Value between Min_Data=0xF1 and Max_Data=0xF7
  310. */
  311. #define __LL_I2C_10BIT_HEADER_READ(__ADDRESS__) ((uint8_t)((uint16_t)((uint16_t)(((uint16_t)((__ADDRESS__) & (uint16_t)(0x0300))) >> 7) | (uint16_t)(0xF1))))
  312. /**
  313. * @}
  314. */
  315. /**
  316. * @}
  317. */
  318. /* Exported functions --------------------------------------------------------*/
  319. /** @defgroup I2C_LL_Exported_Functions I2C Exported Functions
  320. * @{
  321. */
  322. /** @defgroup I2C_LL_EF_Configuration Configuration
  323. * @{
  324. */
  325. /**
  326. * @brief Enable I2C peripheral (PE = 1).
  327. * @rmtoll CR1 PE LL_I2C_Enable
  328. * @param I2Cx I2C Instance.
  329. * @retval None
  330. */
  331. __STATIC_INLINE void LL_I2C_Enable(I2C_TypeDef *I2Cx)
  332. {
  333. SET_BIT(I2Cx->CR1, I2C_CR1_PE);
  334. }
  335. /**
  336. * @brief Disable I2C peripheral (PE = 0).
  337. * @rmtoll CR1 PE LL_I2C_Disable
  338. * @param I2Cx I2C Instance.
  339. * @retval None
  340. */
  341. __STATIC_INLINE void LL_I2C_Disable(I2C_TypeDef *I2Cx)
  342. {
  343. CLEAR_BIT(I2Cx->CR1, I2C_CR1_PE);
  344. }
  345. /**
  346. * @brief Check if the I2C peripheral is enabled or disabled.
  347. * @rmtoll CR1 PE LL_I2C_IsEnabled
  348. * @param I2Cx I2C Instance.
  349. * @retval State of bit (1 or 0).
  350. */
  351. __STATIC_INLINE uint32_t LL_I2C_IsEnabled(I2C_TypeDef *I2Cx)
  352. {
  353. return (READ_BIT(I2Cx->CR1, I2C_CR1_PE) == (I2C_CR1_PE));
  354. }
  355. #if defined(I2C_FLTR_ANOFF)&&defined(I2C_FLTR_DNF)
  356. /**
  357. * @brief Configure Noise Filters (Analog and Digital).
  358. * @note If the analog filter is also enabled, the digital filter is added to analog filter.
  359. * The filters can only be programmed when the I2C is disabled (PE = 0).
  360. * @rmtoll FLTR ANOFF LL_I2C_ConfigFilters\n
  361. * FLTR DNF LL_I2C_ConfigFilters
  362. * @param I2Cx I2C Instance.
  363. * @param AnalogFilter This parameter can be one of the following values:
  364. * @arg @ref LL_I2C_ANALOGFILTER_ENABLE
  365. * @arg @ref LL_I2C_ANALOGFILTER_DISABLE
  366. * @param DigitalFilter This parameter must be a value between Min_Data=0x00 (Digital filter disabled) and Max_Data=0x0F (Digital filter enabled and filtering capability up to 15*TPCLK1)
  367. * This parameter is used to configure the digital noise filter on SDA and SCL input. The digital filter will suppress the spikes with a length of up to DNF[3:0]*TPCLK1.
  368. * @retval None
  369. */
  370. __STATIC_INLINE void LL_I2C_ConfigFilters(I2C_TypeDef *I2Cx, uint32_t AnalogFilter, uint32_t DigitalFilter)
  371. {
  372. MODIFY_REG(I2Cx->FLTR, I2C_FLTR_ANOFF | I2C_FLTR_DNF, AnalogFilter | DigitalFilter);
  373. }
  374. #endif
  375. #if defined(I2C_FLTR_DNF)
  376. /**
  377. * @brief Configure Digital Noise Filter.
  378. * @note If the analog filter is also enabled, the digital filter is added to analog filter.
  379. * This filter can only be programmed when the I2C is disabled (PE = 0).
  380. * @rmtoll FLTR DNF LL_I2C_SetDigitalFilter
  381. * @param I2Cx I2C Instance.
  382. * @param DigitalFilter This parameter must be a value between Min_Data=0x00 (Digital filter disabled) and Max_Data=0x0F (Digital filter enabled and filtering capability up to 15*TPCLK1)
  383. * This parameter is used to configure the digital noise filter on SDA and SCL input. The digital filter will suppress the spikes with a length of up to DNF[3:0]*TPCLK1.
  384. * @retval None
  385. */
  386. __STATIC_INLINE void LL_I2C_SetDigitalFilter(I2C_TypeDef *I2Cx, uint32_t DigitalFilter)
  387. {
  388. MODIFY_REG(I2Cx->FLTR, I2C_FLTR_DNF, DigitalFilter);
  389. }
  390. /**
  391. * @brief Get the current Digital Noise Filter configuration.
  392. * @rmtoll FLTR DNF LL_I2C_GetDigitalFilter
  393. * @param I2Cx I2C Instance.
  394. * @retval Value between Min_Data=0x0 and Max_Data=0xF
  395. */
  396. __STATIC_INLINE uint32_t LL_I2C_GetDigitalFilter(I2C_TypeDef *I2Cx)
  397. {
  398. return (uint32_t)(READ_BIT(I2Cx->FLTR, I2C_FLTR_DNF));
  399. }
  400. #endif
  401. #if defined(I2C_FLTR_ANOFF)
  402. /**
  403. * @brief Enable Analog Noise Filter.
  404. * @note This filter can only be programmed when the I2C is disabled (PE = 0).
  405. * @rmtoll FLTR ANOFF LL_I2C_EnableAnalogFilter
  406. * @param I2Cx I2C Instance.
  407. * @retval None
  408. */
  409. __STATIC_INLINE void LL_I2C_EnableAnalogFilter(I2C_TypeDef *I2Cx)
  410. {
  411. CLEAR_BIT(I2Cx->FLTR, I2C_FLTR_ANOFF);
  412. }
  413. /**
  414. * @brief Disable Analog Noise Filter.
  415. * @note This filter can only be programmed when the I2C is disabled (PE = 0).
  416. * @rmtoll FLTR ANOFF LL_I2C_DisableAnalogFilter
  417. * @param I2Cx I2C Instance.
  418. * @retval None
  419. */
  420. __STATIC_INLINE void LL_I2C_DisableAnalogFilter(I2C_TypeDef *I2Cx)
  421. {
  422. SET_BIT(I2Cx->FLTR, I2C_FLTR_ANOFF);
  423. }
  424. /**
  425. * @brief Check if Analog Noise Filter is enabled or disabled.
  426. * @rmtoll FLTR ANOFF LL_I2C_IsEnabledAnalogFilter
  427. * @param I2Cx I2C Instance.
  428. * @retval State of bit (1 or 0).
  429. */
  430. __STATIC_INLINE uint32_t LL_I2C_IsEnabledAnalogFilter(I2C_TypeDef *I2Cx)
  431. {
  432. return (READ_BIT(I2Cx->FLTR, I2C_FLTR_ANOFF) == (I2C_FLTR_ANOFF));
  433. }
  434. #endif
  435. /**
  436. * @brief Enable DMA transmission requests.
  437. * @rmtoll CR2 DMAEN LL_I2C_EnableDMAReq_TX
  438. * @param I2Cx I2C Instance.
  439. * @retval None
  440. */
  441. __STATIC_INLINE void LL_I2C_EnableDMAReq_TX(I2C_TypeDef *I2Cx)
  442. {
  443. SET_BIT(I2Cx->CR2, I2C_CR2_DMAEN);
  444. }
  445. /**
  446. * @brief Disable DMA transmission requests.
  447. * @rmtoll CR2 DMAEN LL_I2C_DisableDMAReq_TX
  448. * @param I2Cx I2C Instance.
  449. * @retval None
  450. */
  451. __STATIC_INLINE void LL_I2C_DisableDMAReq_TX(I2C_TypeDef *I2Cx)
  452. {
  453. CLEAR_BIT(I2Cx->CR2, I2C_CR2_DMAEN);
  454. }
  455. /**
  456. * @brief Check if DMA transmission requests are enabled or disabled.
  457. * @rmtoll CR2 DMAEN LL_I2C_IsEnabledDMAReq_TX
  458. * @param I2Cx I2C Instance.
  459. * @retval State of bit (1 or 0).
  460. */
  461. __STATIC_INLINE uint32_t LL_I2C_IsEnabledDMAReq_TX(I2C_TypeDef *I2Cx)
  462. {
  463. return (READ_BIT(I2Cx->CR2, I2C_CR2_DMAEN) == (I2C_CR2_DMAEN));
  464. }
  465. /**
  466. * @brief Enable DMA reception requests.
  467. * @rmtoll CR2 DMAEN LL_I2C_EnableDMAReq_RX
  468. * @param I2Cx I2C Instance.
  469. * @retval None
  470. */
  471. __STATIC_INLINE void LL_I2C_EnableDMAReq_RX(I2C_TypeDef *I2Cx)
  472. {
  473. SET_BIT(I2Cx->CR2, I2C_CR2_DMAEN);
  474. }
  475. /**
  476. * @brief Disable DMA reception requests.
  477. * @rmtoll CR2 DMAEN LL_I2C_DisableDMAReq_RX
  478. * @param I2Cx I2C Instance.
  479. * @retval None
  480. */
  481. __STATIC_INLINE void LL_I2C_DisableDMAReq_RX(I2C_TypeDef *I2Cx)
  482. {
  483. CLEAR_BIT(I2Cx->CR2, I2C_CR2_DMAEN);
  484. }
  485. /**
  486. * @brief Check if DMA reception requests are enabled or disabled.
  487. * @rmtoll CR2 DMAEN LL_I2C_IsEnabledDMAReq_RX
  488. * @param I2Cx I2C Instance.
  489. * @retval State of bit (1 or 0).
  490. */
  491. __STATIC_INLINE uint32_t LL_I2C_IsEnabledDMAReq_RX(I2C_TypeDef *I2Cx)
  492. {
  493. return (READ_BIT(I2Cx->CR2, I2C_CR2_DMAEN) == (I2C_CR2_DMAEN));
  494. }
  495. /**
  496. * @brief Get the data register address used for DMA transfer.
  497. * @rmtoll DR DR LL_I2C_DMA_GetRegAddr
  498. * @param I2Cx I2C Instance.
  499. * @retval Address of data register
  500. */
  501. __STATIC_INLINE uint32_t LL_I2C_DMA_GetRegAddr(I2C_TypeDef *I2Cx)
  502. {
  503. return (uint32_t) & (I2Cx->DR);
  504. }
  505. /**
  506. * @brief Enable Clock stretching.
  507. * @note This bit can only be programmed when the I2C is disabled (PE = 0).
  508. * @rmtoll CR1 NOSTRETCH LL_I2C_EnableClockStretching
  509. * @param I2Cx I2C Instance.
  510. * @retval None
  511. */
  512. __STATIC_INLINE void LL_I2C_EnableClockStretching(I2C_TypeDef *I2Cx)
  513. {
  514. CLEAR_BIT(I2Cx->CR1, I2C_CR1_NOSTRETCH);
  515. }
  516. /**
  517. * @brief Disable Clock stretching.
  518. * @note This bit can only be programmed when the I2C is disabled (PE = 0).
  519. * @rmtoll CR1 NOSTRETCH LL_I2C_DisableClockStretching
  520. * @param I2Cx I2C Instance.
  521. * @retval None
  522. */
  523. __STATIC_INLINE void LL_I2C_DisableClockStretching(I2C_TypeDef *I2Cx)
  524. {
  525. SET_BIT(I2Cx->CR1, I2C_CR1_NOSTRETCH);
  526. }
  527. /**
  528. * @brief Check if Clock stretching is enabled or disabled.
  529. * @rmtoll CR1 NOSTRETCH LL_I2C_IsEnabledClockStretching
  530. * @param I2Cx I2C Instance.
  531. * @retval State of bit (1 or 0).
  532. */
  533. __STATIC_INLINE uint32_t LL_I2C_IsEnabledClockStretching(I2C_TypeDef *I2Cx)
  534. {
  535. return (READ_BIT(I2Cx->CR1, I2C_CR1_NOSTRETCH) != (I2C_CR1_NOSTRETCH));
  536. }
  537. /**
  538. * @brief Enable General Call.
  539. * @note When enabled the Address 0x00 is ACKed.
  540. * @rmtoll CR1 ENGC LL_I2C_EnableGeneralCall
  541. * @param I2Cx I2C Instance.
  542. * @retval None
  543. */
  544. __STATIC_INLINE void LL_I2C_EnableGeneralCall(I2C_TypeDef *I2Cx)
  545. {
  546. SET_BIT(I2Cx->CR1, I2C_CR1_ENGC);
  547. }
  548. /**
  549. * @brief Disable General Call.
  550. * @note When disabled the Address 0x00 is NACKed.
  551. * @rmtoll CR1 ENGC LL_I2C_DisableGeneralCall
  552. * @param I2Cx I2C Instance.
  553. * @retval None
  554. */
  555. __STATIC_INLINE void LL_I2C_DisableGeneralCall(I2C_TypeDef *I2Cx)
  556. {
  557. CLEAR_BIT(I2Cx->CR1, I2C_CR1_ENGC);
  558. }
  559. /**
  560. * @brief Check if General Call is enabled or disabled.
  561. * @rmtoll CR1 ENGC LL_I2C_IsEnabledGeneralCall
  562. * @param I2Cx I2C Instance.
  563. * @retval State of bit (1 or 0).
  564. */
  565. __STATIC_INLINE uint32_t LL_I2C_IsEnabledGeneralCall(I2C_TypeDef *I2Cx)
  566. {
  567. return (READ_BIT(I2Cx->CR1, I2C_CR1_ENGC) == (I2C_CR1_ENGC));
  568. }
  569. /**
  570. * @brief Set the Own Address1.
  571. * @rmtoll OAR1 ADD0 LL_I2C_SetOwnAddress1\n
  572. * OAR1 ADD1_7 LL_I2C_SetOwnAddress1\n
  573. * OAR1 ADD8_9 LL_I2C_SetOwnAddress1\n
  574. * OAR1 ADDMODE LL_I2C_SetOwnAddress1
  575. * @param I2Cx I2C Instance.
  576. * @param OwnAddress1 This parameter must be a value between Min_Data=0 and Max_Data=0x3FF.
  577. * @param OwnAddrSize This parameter can be one of the following values:
  578. * @arg @ref LL_I2C_OWNADDRESS1_7BIT
  579. * @arg @ref LL_I2C_OWNADDRESS1_10BIT
  580. * @retval None
  581. */
  582. __STATIC_INLINE void LL_I2C_SetOwnAddress1(I2C_TypeDef *I2Cx, uint32_t OwnAddress1, uint32_t OwnAddrSize)
  583. {
  584. MODIFY_REG(I2Cx->OAR1, I2C_OAR1_ADD0 | I2C_OAR1_ADD1_7 | I2C_OAR1_ADD8_9 | I2C_OAR1_ADDMODE, OwnAddress1 | OwnAddrSize);
  585. }
  586. /**
  587. * @brief Set the 7bits Own Address2.
  588. * @note This action has no effect if own address2 is enabled.
  589. * @rmtoll OAR2 ADD2 LL_I2C_SetOwnAddress2
  590. * @param I2Cx I2C Instance.
  591. * @param OwnAddress2 This parameter must be a value between Min_Data=0 and Max_Data=0x7F.
  592. * @retval None
  593. */
  594. __STATIC_INLINE void LL_I2C_SetOwnAddress2(I2C_TypeDef *I2Cx, uint32_t OwnAddress2)
  595. {
  596. MODIFY_REG(I2Cx->OAR2, I2C_OAR2_ADD2, OwnAddress2);
  597. }
  598. /**
  599. * @brief Enable acknowledge on Own Address2 match address.
  600. * @rmtoll OAR2 ENDUAL LL_I2C_EnableOwnAddress2
  601. * @param I2Cx I2C Instance.
  602. * @retval None
  603. */
  604. __STATIC_INLINE void LL_I2C_EnableOwnAddress2(I2C_TypeDef *I2Cx)
  605. {
  606. SET_BIT(I2Cx->OAR2, I2C_OAR2_ENDUAL);
  607. }
  608. /**
  609. * @brief Disable acknowledge on Own Address2 match address.
  610. * @rmtoll OAR2 ENDUAL LL_I2C_DisableOwnAddress2
  611. * @param I2Cx I2C Instance.
  612. * @retval None
  613. */
  614. __STATIC_INLINE void LL_I2C_DisableOwnAddress2(I2C_TypeDef *I2Cx)
  615. {
  616. CLEAR_BIT(I2Cx->OAR2, I2C_OAR2_ENDUAL);
  617. }
  618. /**
  619. * @brief Check if Own Address1 acknowledge is enabled or disabled.
  620. * @rmtoll OAR2 ENDUAL LL_I2C_IsEnabledOwnAddress2
  621. * @param I2Cx I2C Instance.
  622. * @retval State of bit (1 or 0).
  623. */
  624. __STATIC_INLINE uint32_t LL_I2C_IsEnabledOwnAddress2(I2C_TypeDef *I2Cx)
  625. {
  626. return (READ_BIT(I2Cx->OAR2, I2C_OAR2_ENDUAL) == (I2C_OAR2_ENDUAL));
  627. }
  628. /**
  629. * @brief Configure the Peripheral clock frequency.
  630. * @rmtoll CR2 FREQ LL_I2C_SetPeriphClock
  631. * @param I2Cx I2C Instance.
  632. * @param PeriphClock Peripheral Clock (in Hz)
  633. * @retval None
  634. */
  635. __STATIC_INLINE void LL_I2C_SetPeriphClock(I2C_TypeDef *I2Cx, uint32_t PeriphClock)
  636. {
  637. MODIFY_REG(I2Cx->CR2, I2C_CR2_FREQ, __LL_I2C_FREQ_HZ_TO_MHZ(PeriphClock));
  638. }
  639. /**
  640. * @brief Get the Peripheral clock frequency.
  641. * @rmtoll CR2 FREQ LL_I2C_GetPeriphClock
  642. * @param I2Cx I2C Instance.
  643. * @retval Value of Peripheral Clock (in Hz)
  644. */
  645. __STATIC_INLINE uint32_t LL_I2C_GetPeriphClock(I2C_TypeDef *I2Cx)
  646. {
  647. return (uint32_t)(__LL_I2C_FREQ_MHZ_TO_HZ(READ_BIT(I2Cx->CR2, I2C_CR2_FREQ)));
  648. }
  649. /**
  650. * @brief Configure the Duty cycle (Fast mode only).
  651. * @rmtoll CCR DUTY LL_I2C_SetDutyCycle
  652. * @param I2Cx I2C Instance.
  653. * @param DutyCycle This parameter can be one of the following values:
  654. * @arg @ref LL_I2C_DUTYCYCLE_2
  655. * @arg @ref LL_I2C_DUTYCYCLE_16_9
  656. * @retval None
  657. */
  658. __STATIC_INLINE void LL_I2C_SetDutyCycle(I2C_TypeDef *I2Cx, uint32_t DutyCycle)
  659. {
  660. MODIFY_REG(I2Cx->CCR, I2C_CCR_DUTY, DutyCycle);
  661. }
  662. /**
  663. * @brief Get the Duty cycle (Fast mode only).
  664. * @rmtoll CCR DUTY LL_I2C_GetDutyCycle
  665. * @param I2Cx I2C Instance.
  666. * @retval Returned value can be one of the following values:
  667. * @arg @ref LL_I2C_DUTYCYCLE_2
  668. * @arg @ref LL_I2C_DUTYCYCLE_16_9
  669. */
  670. __STATIC_INLINE uint32_t LL_I2C_GetDutyCycle(I2C_TypeDef *I2Cx)
  671. {
  672. return (uint32_t)(READ_BIT(I2Cx->CCR, I2C_CCR_DUTY));
  673. }
  674. /**
  675. * @brief Configure the I2C master clock speed mode.
  676. * @rmtoll CCR FS LL_I2C_SetClockSpeedMode
  677. * @param I2Cx I2C Instance.
  678. * @param ClockSpeedMode This parameter can be one of the following values:
  679. * @arg @ref LL_I2C_CLOCK_SPEED_STANDARD_MODE
  680. * @arg @ref LL_I2C_CLOCK_SPEED_FAST_MODE
  681. * @retval None
  682. */
  683. __STATIC_INLINE void LL_I2C_SetClockSpeedMode(I2C_TypeDef *I2Cx, uint32_t ClockSpeedMode)
  684. {
  685. MODIFY_REG(I2Cx->CCR, I2C_CCR_FS, ClockSpeedMode);
  686. }
  687. /**
  688. * @brief Get the the I2C master speed mode.
  689. * @rmtoll CCR FS LL_I2C_GetClockSpeedMode
  690. * @param I2Cx I2C Instance.
  691. * @retval Returned value can be one of the following values:
  692. * @arg @ref LL_I2C_CLOCK_SPEED_STANDARD_MODE
  693. * @arg @ref LL_I2C_CLOCK_SPEED_FAST_MODE
  694. */
  695. __STATIC_INLINE uint32_t LL_I2C_GetClockSpeedMode(I2C_TypeDef *I2Cx)
  696. {
  697. return (uint32_t)(READ_BIT(I2Cx->CCR, I2C_CCR_FS));
  698. }
  699. /**
  700. * @brief Configure the SCL, SDA rising time.
  701. * @note This bit can only be programmed when the I2C is disabled (PE = 0).
  702. * @rmtoll TRISE TRISE LL_I2C_SetRiseTime
  703. * @param I2Cx I2C Instance.
  704. * @param RiseTime This parameter must be a value between Min_Data=0x02 and Max_Data=0x3F.
  705. * @retval None
  706. */
  707. __STATIC_INLINE void LL_I2C_SetRiseTime(I2C_TypeDef *I2Cx, uint32_t RiseTime)
  708. {
  709. MODIFY_REG(I2Cx->TRISE, I2C_TRISE_TRISE, RiseTime);
  710. }
  711. /**
  712. * @brief Get the SCL, SDA rising time.
  713. * @rmtoll TRISE TRISE LL_I2C_GetRiseTime
  714. * @param I2Cx I2C Instance.
  715. * @retval Value between Min_Data=0x02 and Max_Data=0x3F
  716. */
  717. __STATIC_INLINE uint32_t LL_I2C_GetRiseTime(I2C_TypeDef *I2Cx)
  718. {
  719. return (uint32_t)(READ_BIT(I2Cx->TRISE, I2C_TRISE_TRISE));
  720. }
  721. /**
  722. * @brief Configure the SCL high and low period.
  723. * @note This bit can only be programmed when the I2C is disabled (PE = 0).
  724. * @rmtoll CCR CCR LL_I2C_SetClockPeriod
  725. * @param I2Cx I2C Instance.
  726. * @param ClockPeriod This parameter must be a value between Min_Data=0x004 and Max_Data=0xFFF, except in FAST DUTY mode where Min_Data=0x001.
  727. * @retval None
  728. */
  729. __STATIC_INLINE void LL_I2C_SetClockPeriod(I2C_TypeDef *I2Cx, uint32_t ClockPeriod)
  730. {
  731. MODIFY_REG(I2Cx->CCR, I2C_CCR_CCR, ClockPeriod);
  732. }
  733. /**
  734. * @brief Get the SCL high and low period.
  735. * @rmtoll CCR CCR LL_I2C_GetClockPeriod
  736. * @param I2Cx I2C Instance.
  737. * @retval Value between Min_Data=0x004 and Max_Data=0xFFF, except in FAST DUTY mode where Min_Data=0x001.
  738. */
  739. __STATIC_INLINE uint32_t LL_I2C_GetClockPeriod(I2C_TypeDef *I2Cx)
  740. {
  741. return (uint32_t)(READ_BIT(I2Cx->CCR, I2C_CCR_CCR));
  742. }
  743. /**
  744. * @brief Configure the SCL speed.
  745. * @note This bit can only be programmed when the I2C is disabled (PE = 0).
  746. * @rmtoll CR2 FREQ LL_I2C_ConfigSpeed\n
  747. * TRISE TRISE LL_I2C_ConfigSpeed\n
  748. * CCR FS LL_I2C_ConfigSpeed\n
  749. * CCR DUTY LL_I2C_ConfigSpeed\n
  750. * CCR CCR LL_I2C_ConfigSpeed
  751. * @param I2Cx I2C Instance.
  752. * @param PeriphClock Peripheral Clock (in Hz)
  753. * @param ClockSpeed This parameter must be a value lower than 400kHz (in Hz).
  754. * @param DutyCycle This parameter can be one of the following values:
  755. * @arg @ref LL_I2C_DUTYCYCLE_2
  756. * @arg @ref LL_I2C_DUTYCYCLE_16_9
  757. * @retval None
  758. */
  759. __STATIC_INLINE void LL_I2C_ConfigSpeed(I2C_TypeDef *I2Cx, uint32_t PeriphClock, uint32_t ClockSpeed,
  760. uint32_t DutyCycle)
  761. {
  762. register uint32_t freqrange = 0x0U;
  763. register uint32_t clockconfig = 0x0U;
  764. /* Compute frequency range */
  765. freqrange = __LL_I2C_FREQ_HZ_TO_MHZ(PeriphClock);
  766. /* Configure I2Cx: Frequency range register */
  767. MODIFY_REG(I2Cx->CR2, I2C_CR2_FREQ, freqrange);
  768. /* Configure I2Cx: Rise Time register */
  769. MODIFY_REG(I2Cx->TRISE, I2C_TRISE_TRISE, __LL_I2C_RISE_TIME(freqrange, ClockSpeed));
  770. /* Configure Speed mode, Duty Cycle and Clock control register value */
  771. if (ClockSpeed > LL_I2C_MAX_SPEED_STANDARD)
  772. {
  773. /* Set Speed mode at fast and duty cycle for Clock Speed request in fast clock range */
  774. clockconfig = LL_I2C_CLOCK_SPEED_FAST_MODE | \
  775. __LL_I2C_SPEED_FAST_TO_CCR(PeriphClock, ClockSpeed, DutyCycle) | \
  776. DutyCycle;
  777. }
  778. else
  779. {
  780. /* Set Speed mode at standard for Clock Speed request in standard clock range */
  781. clockconfig = LL_I2C_CLOCK_SPEED_STANDARD_MODE | \
  782. __LL_I2C_SPEED_STANDARD_TO_CCR(PeriphClock, ClockSpeed);
  783. }
  784. /* Configure I2Cx: Clock control register */
  785. MODIFY_REG(I2Cx->CCR, (I2C_CCR_FS | I2C_CCR_DUTY | I2C_CCR_CCR), clockconfig);
  786. }
  787. /**
  788. * @brief Configure peripheral mode.
  789. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  790. * SMBus feature is supported by the I2Cx Instance.
  791. * @rmtoll CR1 SMBUS LL_I2C_SetMode\n
  792. * CR1 SMBTYPE LL_I2C_SetMode\n
  793. * CR1 ENARP LL_I2C_SetMode
  794. * @param I2Cx I2C Instance.
  795. * @param PeripheralMode This parameter can be one of the following values:
  796. * @arg @ref LL_I2C_MODE_I2C
  797. * @arg @ref LL_I2C_MODE_SMBUS_HOST
  798. * @arg @ref LL_I2C_MODE_SMBUS_DEVICE
  799. * @arg @ref LL_I2C_MODE_SMBUS_DEVICE_ARP
  800. * @retval None
  801. */
  802. __STATIC_INLINE void LL_I2C_SetMode(I2C_TypeDef *I2Cx, uint32_t PeripheralMode)
  803. {
  804. MODIFY_REG(I2Cx->CR1, I2C_CR1_SMBUS | I2C_CR1_SMBTYPE | I2C_CR1_ENARP, PeripheralMode);
  805. }
  806. /**
  807. * @brief Get peripheral mode.
  808. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  809. * SMBus feature is supported by the I2Cx Instance.
  810. * @rmtoll CR1 SMBUS LL_I2C_GetMode\n
  811. * CR1 SMBTYPE LL_I2C_GetMode\n
  812. * CR1 ENARP LL_I2C_GetMode
  813. * @param I2Cx I2C Instance.
  814. * @retval Returned value can be one of the following values:
  815. * @arg @ref LL_I2C_MODE_I2C
  816. * @arg @ref LL_I2C_MODE_SMBUS_HOST
  817. * @arg @ref LL_I2C_MODE_SMBUS_DEVICE
  818. * @arg @ref LL_I2C_MODE_SMBUS_DEVICE_ARP
  819. */
  820. __STATIC_INLINE uint32_t LL_I2C_GetMode(I2C_TypeDef *I2Cx)
  821. {
  822. return (uint32_t)(READ_BIT(I2Cx->CR1, I2C_CR1_SMBUS | I2C_CR1_SMBTYPE | I2C_CR1_ENARP));
  823. }
  824. /**
  825. * @brief Enable SMBus alert (Host or Device mode)
  826. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  827. * SMBus feature is supported by the I2Cx Instance.
  828. * @note SMBus Device mode:
  829. * - SMBus Alert pin is drived low and
  830. * Alert Response Address Header acknowledge is enabled.
  831. * SMBus Host mode:
  832. * - SMBus Alert pin management is supported.
  833. * @rmtoll CR1 ALERT LL_I2C_EnableSMBusAlert
  834. * @param I2Cx I2C Instance.
  835. * @retval None
  836. */
  837. __STATIC_INLINE void LL_I2C_EnableSMBusAlert(I2C_TypeDef *I2Cx)
  838. {
  839. SET_BIT(I2Cx->CR1, I2C_CR1_ALERT);
  840. }
  841. /**
  842. * @brief Disable SMBus alert (Host or Device mode)
  843. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  844. * SMBus feature is supported by the I2Cx Instance.
  845. * @note SMBus Device mode:
  846. * - SMBus Alert pin is not drived (can be used as a standard GPIO) and
  847. * Alert Response Address Header acknowledge is disabled.
  848. * SMBus Host mode:
  849. * - SMBus Alert pin management is not supported.
  850. * @rmtoll CR1 ALERT LL_I2C_DisableSMBusAlert
  851. * @param I2Cx I2C Instance.
  852. * @retval None
  853. */
  854. __STATIC_INLINE void LL_I2C_DisableSMBusAlert(I2C_TypeDef *I2Cx)
  855. {
  856. CLEAR_BIT(I2Cx->CR1, I2C_CR1_ALERT);
  857. }
  858. /**
  859. * @brief Check if SMBus alert (Host or Device mode) is enabled or disabled.
  860. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  861. * SMBus feature is supported by the I2Cx Instance.
  862. * @rmtoll CR1 ALERT LL_I2C_IsEnabledSMBusAlert
  863. * @param I2Cx I2C Instance.
  864. * @retval State of bit (1 or 0).
  865. */
  866. __STATIC_INLINE uint32_t LL_I2C_IsEnabledSMBusAlert(I2C_TypeDef *I2Cx)
  867. {
  868. return (READ_BIT(I2Cx->CR1, I2C_CR1_ALERT) == (I2C_CR1_ALERT));
  869. }
  870. /**
  871. * @brief Enable SMBus Packet Error Calculation (PEC).
  872. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  873. * SMBus feature is supported by the I2Cx Instance.
  874. * @rmtoll CR1 ENPEC LL_I2C_EnableSMBusPEC
  875. * @param I2Cx I2C Instance.
  876. * @retval None
  877. */
  878. __STATIC_INLINE void LL_I2C_EnableSMBusPEC(I2C_TypeDef *I2Cx)
  879. {
  880. SET_BIT(I2Cx->CR1, I2C_CR1_ENPEC);
  881. }
  882. /**
  883. * @brief Disable SMBus Packet Error Calculation (PEC).
  884. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  885. * SMBus feature is supported by the I2Cx Instance.
  886. * @rmtoll CR1 ENPEC LL_I2C_DisableSMBusPEC
  887. * @param I2Cx I2C Instance.
  888. * @retval None
  889. */
  890. __STATIC_INLINE void LL_I2C_DisableSMBusPEC(I2C_TypeDef *I2Cx)
  891. {
  892. CLEAR_BIT(I2Cx->CR1, I2C_CR1_ENPEC);
  893. }
  894. /**
  895. * @brief Check if SMBus Packet Error Calculation (PEC) is enabled or disabled.
  896. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  897. * SMBus feature is supported by the I2Cx Instance.
  898. * @rmtoll CR1 ENPEC LL_I2C_IsEnabledSMBusPEC
  899. * @param I2Cx I2C Instance.
  900. * @retval State of bit (1 or 0).
  901. */
  902. __STATIC_INLINE uint32_t LL_I2C_IsEnabledSMBusPEC(I2C_TypeDef *I2Cx)
  903. {
  904. return (READ_BIT(I2Cx->CR1, I2C_CR1_ENPEC) == (I2C_CR1_ENPEC));
  905. }
  906. /**
  907. * @}
  908. */
  909. /** @defgroup I2C_LL_EF_IT_Management IT_Management
  910. * @{
  911. */
  912. /**
  913. * @brief Enable TXE interrupt.
  914. * @rmtoll CR2 ITEVTEN LL_I2C_EnableIT_TX\n
  915. * CR2 ITBUFEN LL_I2C_EnableIT_TX
  916. * @param I2Cx I2C Instance.
  917. * @retval None
  918. */
  919. __STATIC_INLINE void LL_I2C_EnableIT_TX(I2C_TypeDef *I2Cx)
  920. {
  921. SET_BIT(I2Cx->CR2, I2C_CR2_ITEVTEN | I2C_CR2_ITBUFEN);
  922. }
  923. /**
  924. * @brief Disable TXE interrupt.
  925. * @rmtoll CR2 ITEVTEN LL_I2C_DisableIT_TX\n
  926. * CR2 ITBUFEN LL_I2C_DisableIT_TX
  927. * @param I2Cx I2C Instance.
  928. * @retval None
  929. */
  930. __STATIC_INLINE void LL_I2C_DisableIT_TX(I2C_TypeDef *I2Cx)
  931. {
  932. CLEAR_BIT(I2Cx->CR2, I2C_CR2_ITEVTEN | I2C_CR2_ITBUFEN);
  933. }
  934. /**
  935. * @brief Check if the TXE Interrupt is enabled or disabled.
  936. * @rmtoll CR2 ITEVTEN LL_I2C_IsEnabledIT_TX\n
  937. * CR2 ITBUFEN LL_I2C_IsEnabledIT_TX
  938. * @param I2Cx I2C Instance.
  939. * @retval State of bit (1 or 0).
  940. */
  941. __STATIC_INLINE uint32_t LL_I2C_IsEnabledIT_TX(I2C_TypeDef *I2Cx)
  942. {
  943. return (READ_BIT(I2Cx->CR2, I2C_CR2_ITEVTEN | I2C_CR2_ITBUFEN) == (I2C_CR2_ITEVTEN | I2C_CR2_ITBUFEN));
  944. }
  945. /**
  946. * @brief Enable RXNE interrupt.
  947. * @rmtoll CR2 ITEVTEN LL_I2C_EnableIT_RX\n
  948. * CR2 ITBUFEN LL_I2C_EnableIT_RX
  949. * @param I2Cx I2C Instance.
  950. * @retval None
  951. */
  952. __STATIC_INLINE void LL_I2C_EnableIT_RX(I2C_TypeDef *I2Cx)
  953. {
  954. SET_BIT(I2Cx->CR2, I2C_CR2_ITEVTEN | I2C_CR2_ITBUFEN);
  955. }
  956. /**
  957. * @brief Disable RXNE interrupt.
  958. * @rmtoll CR2 ITEVTEN LL_I2C_DisableIT_RX\n
  959. * CR2 ITBUFEN LL_I2C_DisableIT_RX
  960. * @param I2Cx I2C Instance.
  961. * @retval None
  962. */
  963. __STATIC_INLINE void LL_I2C_DisableIT_RX(I2C_TypeDef *I2Cx)
  964. {
  965. CLEAR_BIT(I2Cx->CR2, I2C_CR2_ITEVTEN | I2C_CR2_ITBUFEN);
  966. }
  967. /**
  968. * @brief Check if the RXNE Interrupt is enabled or disabled.
  969. * @rmtoll CR2 ITEVTEN LL_I2C_IsEnabledIT_RX\n
  970. * CR2 ITBUFEN LL_I2C_IsEnabledIT_RX
  971. * @param I2Cx I2C Instance.
  972. * @retval State of bit (1 or 0).
  973. */
  974. __STATIC_INLINE uint32_t LL_I2C_IsEnabledIT_RX(I2C_TypeDef *I2Cx)
  975. {
  976. return (READ_BIT(I2Cx->CR2, I2C_CR2_ITEVTEN | I2C_CR2_ITBUFEN) == (I2C_CR2_ITEVTEN | I2C_CR2_ITBUFEN));
  977. }
  978. /**
  979. * @brief Enable Events interrupts.
  980. * @note Any of these events will generate interrupt :
  981. * Start Bit (SB)
  982. * Address sent, Address matched (ADDR)
  983. * 10-bit header sent (ADD10)
  984. * Stop detection (STOPF)
  985. * Byte transfer finished (BTF)
  986. *
  987. * @note Any of these events will generate interrupt if Buffer interrupts are enabled too(using unitary function @ref LL_I2C_EnableIT_BUF()) :
  988. * Receive buffer not empty (RXNE)
  989. * Transmit buffer empty (TXE)
  990. * @rmtoll CR2 ITEVTEN LL_I2C_EnableIT_EVT
  991. * @param I2Cx I2C Instance.
  992. * @retval None
  993. */
  994. __STATIC_INLINE void LL_I2C_EnableIT_EVT(I2C_TypeDef *I2Cx)
  995. {
  996. SET_BIT(I2Cx->CR2, I2C_CR2_ITEVTEN);
  997. }
  998. /**
  999. * @brief Disable Events interrupts.
  1000. * @note Any of these events will generate interrupt :
  1001. * Start Bit (SB)
  1002. * Address sent, Address matched (ADDR)
  1003. * 10-bit header sent (ADD10)
  1004. * Stop detection (STOPF)
  1005. * Byte transfer finished (BTF)
  1006. * Receive buffer not empty (RXNE)
  1007. * Transmit buffer empty (TXE)
  1008. * @rmtoll CR2 ITEVTEN LL_I2C_DisableIT_EVT
  1009. * @param I2Cx I2C Instance.
  1010. * @retval None
  1011. */
  1012. __STATIC_INLINE void LL_I2C_DisableIT_EVT(I2C_TypeDef *I2Cx)
  1013. {
  1014. CLEAR_BIT(I2Cx->CR2, I2C_CR2_ITEVTEN);
  1015. }
  1016. /**
  1017. * @brief Check if Events interrupts are enabled or disabled.
  1018. * @rmtoll CR2 ITEVTEN LL_I2C_IsEnabledIT_EVT
  1019. * @param I2Cx I2C Instance.
  1020. * @retval State of bit (1 or 0).
  1021. */
  1022. __STATIC_INLINE uint32_t LL_I2C_IsEnabledIT_EVT(I2C_TypeDef *I2Cx)
  1023. {
  1024. return (READ_BIT(I2Cx->CR2, I2C_CR2_ITEVTEN) == (I2C_CR2_ITEVTEN));
  1025. }
  1026. /**
  1027. * @brief Enable Buffer interrupts.
  1028. * @note Any of these Buffer events will generate interrupt if Events interrupts are enabled too(using unitary function @ref LL_I2C_EnableIT_EVT()) :
  1029. * Receive buffer not empty (RXNE)
  1030. * Transmit buffer empty (TXE)
  1031. * @rmtoll CR2 ITBUFEN LL_I2C_EnableIT_BUF
  1032. * @param I2Cx I2C Instance.
  1033. * @retval None
  1034. */
  1035. __STATIC_INLINE void LL_I2C_EnableIT_BUF(I2C_TypeDef *I2Cx)
  1036. {
  1037. SET_BIT(I2Cx->CR2, I2C_CR2_ITBUFEN);
  1038. }
  1039. /**
  1040. * @brief Disable Buffer interrupts.
  1041. * @note Any of these Buffer events will generate interrupt :
  1042. * Receive buffer not empty (RXNE)
  1043. * Transmit buffer empty (TXE)
  1044. * @rmtoll CR2 ITBUFEN LL_I2C_DisableIT_BUF
  1045. * @param I2Cx I2C Instance.
  1046. * @retval None
  1047. */
  1048. __STATIC_INLINE void LL_I2C_DisableIT_BUF(I2C_TypeDef *I2Cx)
  1049. {
  1050. CLEAR_BIT(I2Cx->CR2, I2C_CR2_ITBUFEN);
  1051. }
  1052. /**
  1053. * @brief Check if Buffer interrupts are enabled or disabled.
  1054. * @rmtoll CR2 ITBUFEN LL_I2C_IsEnabledIT_BUF
  1055. * @param I2Cx I2C Instance.
  1056. * @retval State of bit (1 or 0).
  1057. */
  1058. __STATIC_INLINE uint32_t LL_I2C_IsEnabledIT_BUF(I2C_TypeDef *I2Cx)
  1059. {
  1060. return (READ_BIT(I2Cx->CR2, I2C_CR2_ITBUFEN) == (I2C_CR2_ITBUFEN));
  1061. }
  1062. /**
  1063. * @brief Enable Error interrupts.
  1064. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1065. * SMBus feature is supported by the I2Cx Instance.
  1066. * @note Any of these errors will generate interrupt :
  1067. * Bus Error detection (BERR)
  1068. * Arbitration Loss (ARLO)
  1069. * Acknowledge Failure(AF)
  1070. * Overrun/Underrun (OVR)
  1071. * SMBus Timeout detection (TIMEOUT)
  1072. * SMBus PEC error detection (PECERR)
  1073. * SMBus Alert pin event detection (SMBALERT)
  1074. * @rmtoll CR2 ITERREN LL_I2C_EnableIT_ERR
  1075. * @param I2Cx I2C Instance.
  1076. * @retval None
  1077. */
  1078. __STATIC_INLINE void LL_I2C_EnableIT_ERR(I2C_TypeDef *I2Cx)
  1079. {
  1080. SET_BIT(I2Cx->CR2, I2C_CR2_ITERREN);
  1081. }
  1082. /**
  1083. * @brief Disable Error interrupts.
  1084. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1085. * SMBus feature is supported by the I2Cx Instance.
  1086. * @note Any of these errors will generate interrupt :
  1087. * Bus Error detection (BERR)
  1088. * Arbitration Loss (ARLO)
  1089. * Acknowledge Failure(AF)
  1090. * Overrun/Underrun (OVR)
  1091. * SMBus Timeout detection (TIMEOUT)
  1092. * SMBus PEC error detection (PECERR)
  1093. * SMBus Alert pin event detection (SMBALERT)
  1094. * @rmtoll CR2 ITERREN LL_I2C_DisableIT_ERR
  1095. * @param I2Cx I2C Instance.
  1096. * @retval None
  1097. */
  1098. __STATIC_INLINE void LL_I2C_DisableIT_ERR(I2C_TypeDef *I2Cx)
  1099. {
  1100. CLEAR_BIT(I2Cx->CR2, I2C_CR2_ITERREN);
  1101. }
  1102. /**
  1103. * @brief Check if Error interrupts are enabled or disabled.
  1104. * @rmtoll CR2 ITERREN LL_I2C_IsEnabledIT_ERR
  1105. * @param I2Cx I2C Instance.
  1106. * @retval State of bit (1 or 0).
  1107. */
  1108. __STATIC_INLINE uint32_t LL_I2C_IsEnabledIT_ERR(I2C_TypeDef *I2Cx)
  1109. {
  1110. return (READ_BIT(I2Cx->CR2, I2C_CR2_ITERREN) == (I2C_CR2_ITERREN));
  1111. }
  1112. /**
  1113. * @}
  1114. */
  1115. /** @defgroup I2C_LL_EF_FLAG_management FLAG_management
  1116. * @{
  1117. */
  1118. /**
  1119. * @brief Indicate the status of Transmit data register empty flag.
  1120. * @note RESET: When next data is written in Transmit data register.
  1121. * SET: When Transmit data register is empty.
  1122. * @rmtoll SR1 TXE LL_I2C_IsActiveFlag_TXE
  1123. * @param I2Cx I2C Instance.
  1124. * @retval State of bit (1 or 0).
  1125. */
  1126. __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_TXE(I2C_TypeDef *I2Cx)
  1127. {
  1128. return (READ_BIT(I2Cx->SR1, I2C_SR1_TXE) == (I2C_SR1_TXE));
  1129. }
  1130. /**
  1131. * @brief Indicate the status of Byte Transfer Finished flag.
  1132. * RESET: When Data byte transfer not done.
  1133. * SET: When Data byte transfer succeeded.
  1134. * @rmtoll SR1 BTF LL_I2C_IsActiveFlag_BTF
  1135. * @param I2Cx I2C Instance.
  1136. * @retval State of bit (1 or 0).
  1137. */
  1138. __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_BTF(I2C_TypeDef *I2Cx)
  1139. {
  1140. return (READ_BIT(I2Cx->SR1, I2C_SR1_BTF) == (I2C_SR1_BTF));
  1141. }
  1142. /**
  1143. * @brief Indicate the status of Receive data register not empty flag.
  1144. * @note RESET: When Receive data register is read.
  1145. * SET: When the received data is copied in Receive data register.
  1146. * @rmtoll SR1 RXNE LL_I2C_IsActiveFlag_RXNE
  1147. * @param I2Cx I2C Instance.
  1148. * @retval State of bit (1 or 0).
  1149. */
  1150. __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_RXNE(I2C_TypeDef *I2Cx)
  1151. {
  1152. return (READ_BIT(I2Cx->SR1, I2C_SR1_RXNE) == (I2C_SR1_RXNE));
  1153. }
  1154. /**
  1155. * @brief Indicate the status of Start Bit (master mode).
  1156. * @note RESET: When No Start condition.
  1157. * SET: When Start condition is generated.
  1158. * @rmtoll SR1 SB LL_I2C_IsActiveFlag_SB
  1159. * @param I2Cx I2C Instance.
  1160. * @retval State of bit (1 or 0).
  1161. */
  1162. __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_SB(I2C_TypeDef *I2Cx)
  1163. {
  1164. return (READ_BIT(I2Cx->SR1, I2C_SR1_SB) == (I2C_SR1_SB));
  1165. }
  1166. /**
  1167. * @brief Indicate the status of Address sent (master mode) or Address matched flag (slave mode).
  1168. * @note RESET: Clear default value.
  1169. * SET: When the address is fully sent (master mode) or when the received slave address matched with one of the enabled slave address (slave mode).
  1170. * @rmtoll SR1 ADDR LL_I2C_IsActiveFlag_ADDR
  1171. * @param I2Cx I2C Instance.
  1172. * @retval State of bit (1 or 0).
  1173. */
  1174. __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_ADDR(I2C_TypeDef *I2Cx)
  1175. {
  1176. return (READ_BIT(I2Cx->SR1, I2C_SR1_ADDR) == (I2C_SR1_ADDR));
  1177. }
  1178. /**
  1179. * @brief Indicate the status of 10-bit header sent (master mode).
  1180. * @note RESET: When no ADD10 event occured.
  1181. * SET: When the master has sent the first address byte (header).
  1182. * @rmtoll SR1 ADD10 LL_I2C_IsActiveFlag_ADD10
  1183. * @param I2Cx I2C Instance.
  1184. * @retval State of bit (1 or 0).
  1185. */
  1186. __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_ADD10(I2C_TypeDef *I2Cx)
  1187. {
  1188. return (READ_BIT(I2Cx->SR1, I2C_SR1_ADD10) == (I2C_SR1_ADD10));
  1189. }
  1190. /**
  1191. * @brief Indicate the status of Acknowledge failure flag.
  1192. * @note RESET: No acknowledge failure.
  1193. * SET: When an acknowledge failure is received after a byte transmission.
  1194. * @rmtoll SR1 AF LL_I2C_IsActiveFlag_AF
  1195. * @param I2Cx I2C Instance.
  1196. * @retval State of bit (1 or 0).
  1197. */
  1198. __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_AF(I2C_TypeDef *I2Cx)
  1199. {
  1200. return (READ_BIT(I2Cx->SR1, I2C_SR1_AF) == (I2C_SR1_AF));
  1201. }
  1202. /**
  1203. * @brief Indicate the status of Stop detection flag (slave mode).
  1204. * @note RESET: Clear default value.
  1205. * SET: When a Stop condition is detected.
  1206. * @rmtoll SR1 STOPF LL_I2C_IsActiveFlag_STOP
  1207. * @param I2Cx I2C Instance.
  1208. * @retval State of bit (1 or 0).
  1209. */
  1210. __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_STOP(I2C_TypeDef *I2Cx)
  1211. {
  1212. return (READ_BIT(I2Cx->SR1, I2C_SR1_STOPF) == (I2C_SR1_STOPF));
  1213. }
  1214. /**
  1215. * @brief Indicate the status of Bus error flag.
  1216. * @note RESET: Clear default value.
  1217. * SET: When a misplaced Start or Stop condition is detected.
  1218. * @rmtoll SR1 BERR LL_I2C_IsActiveFlag_BERR
  1219. * @param I2Cx I2C Instance.
  1220. * @retval State of bit (1 or 0).
  1221. */
  1222. __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_BERR(I2C_TypeDef *I2Cx)
  1223. {
  1224. return (READ_BIT(I2Cx->SR1, I2C_SR1_BERR) == (I2C_SR1_BERR));
  1225. }
  1226. /**
  1227. * @brief Indicate the status of Arbitration lost flag.
  1228. * @note RESET: Clear default value.
  1229. * SET: When arbitration lost.
  1230. * @rmtoll SR1 ARLO LL_I2C_IsActiveFlag_ARLO
  1231. * @param I2Cx I2C Instance.
  1232. * @retval State of bit (1 or 0).
  1233. */
  1234. __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_ARLO(I2C_TypeDef *I2Cx)
  1235. {
  1236. return (READ_BIT(I2Cx->SR1, I2C_SR1_ARLO) == (I2C_SR1_ARLO));
  1237. }
  1238. /**
  1239. * @brief Indicate the status of Overrun/Underrun flag.
  1240. * @note RESET: Clear default value.
  1241. * SET: When an overrun/underrun error occurs (Clock Stretching Disabled).
  1242. * @rmtoll SR1 OVR LL_I2C_IsActiveFlag_OVR
  1243. * @param I2Cx I2C Instance.
  1244. * @retval State of bit (1 or 0).
  1245. */
  1246. __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_OVR(I2C_TypeDef *I2Cx)
  1247. {
  1248. return (READ_BIT(I2Cx->SR1, I2C_SR1_OVR) == (I2C_SR1_OVR));
  1249. }
  1250. /**
  1251. * @brief Indicate the status of SMBus PEC error flag in reception.
  1252. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1253. * SMBus feature is supported by the I2Cx Instance.
  1254. * @rmtoll SR1 PECERR LL_I2C_IsActiveSMBusFlag_PECERR
  1255. * @param I2Cx I2C Instance.
  1256. * @retval State of bit (1 or 0).
  1257. */
  1258. __STATIC_INLINE uint32_t LL_I2C_IsActiveSMBusFlag_PECERR(I2C_TypeDef *I2Cx)
  1259. {
  1260. return (READ_BIT(I2Cx->SR1, I2C_SR1_PECERR) == (I2C_SR1_PECERR));
  1261. }
  1262. /**
  1263. * @brief Indicate the status of SMBus Timeout detection flag.
  1264. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1265. * SMBus feature is supported by the I2Cx Instance.
  1266. * @rmtoll SR1 TIMEOUT LL_I2C_IsActiveSMBusFlag_TIMEOUT
  1267. * @param I2Cx I2C Instance.
  1268. * @retval State of bit (1 or 0).
  1269. */
  1270. __STATIC_INLINE uint32_t LL_I2C_IsActiveSMBusFlag_TIMEOUT(I2C_TypeDef *I2Cx)
  1271. {
  1272. return (READ_BIT(I2Cx->SR1, I2C_SR1_TIMEOUT) == (I2C_SR1_TIMEOUT));
  1273. }
  1274. /**
  1275. * @brief Indicate the status of SMBus alert flag.
  1276. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1277. * SMBus feature is supported by the I2Cx Instance.
  1278. * @rmtoll SR1 SMBALERT LL_I2C_IsActiveSMBusFlag_ALERT
  1279. * @param I2Cx I2C Instance.
  1280. * @retval State of bit (1 or 0).
  1281. */
  1282. __STATIC_INLINE uint32_t LL_I2C_IsActiveSMBusFlag_ALERT(I2C_TypeDef *I2Cx)
  1283. {
  1284. return (READ_BIT(I2Cx->SR1, I2C_SR1_SMBALERT) == (I2C_SR1_SMBALERT));
  1285. }
  1286. /**
  1287. * @brief Indicate the status of Bus Busy flag.
  1288. * @note RESET: Clear default value.
  1289. * SET: When a Start condition is detected.
  1290. * @rmtoll SR2 BUSY LL_I2C_IsActiveFlag_BUSY
  1291. * @param I2Cx I2C Instance.
  1292. * @retval State of bit (1 or 0).
  1293. */
  1294. __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_BUSY(I2C_TypeDef *I2Cx)
  1295. {
  1296. return (READ_BIT(I2Cx->SR2, I2C_SR2_BUSY) == (I2C_SR2_BUSY));
  1297. }
  1298. /**
  1299. * @brief Indicate the status of Dual flag.
  1300. * @note RESET: Received address matched with OAR1.
  1301. * SET: Received address matched with OAR2.
  1302. * @rmtoll SR2 DUALF LL_I2C_IsActiveFlag_DUAL
  1303. * @param I2Cx I2C Instance.
  1304. * @retval State of bit (1 or 0).
  1305. */
  1306. __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_DUAL(I2C_TypeDef *I2Cx)
  1307. {
  1308. return (READ_BIT(I2Cx->SR2, I2C_SR2_DUALF) == (I2C_SR2_DUALF));
  1309. }
  1310. /**
  1311. * @brief Indicate the status of SMBus Host address reception (Slave mode).
  1312. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1313. * SMBus feature is supported by the I2Cx Instance.
  1314. * @note RESET: No SMBus Host address
  1315. * SET: SMBus Host address received.
  1316. * @note This status is cleared by hardware after a STOP condition or repeated START condition.
  1317. * @rmtoll SR2 SMBHOST LL_I2C_IsActiveSMBusFlag_SMBHOST
  1318. * @param I2Cx I2C Instance.
  1319. * @retval State of bit (1 or 0).
  1320. */
  1321. __STATIC_INLINE uint32_t LL_I2C_IsActiveSMBusFlag_SMBHOST(I2C_TypeDef *I2Cx)
  1322. {
  1323. return (READ_BIT(I2Cx->SR2, I2C_SR2_SMBHOST) == (I2C_SR2_SMBHOST));
  1324. }
  1325. /**
  1326. * @brief Indicate the status of SMBus Device default address reception (Slave mode).
  1327. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1328. * SMBus feature is supported by the I2Cx Instance.
  1329. * @note RESET: No SMBus Device default address
  1330. * SET: SMBus Device default address received.
  1331. * @note This status is cleared by hardware after a STOP condition or repeated START condition.
  1332. * @rmtoll SR2 SMBDEFAULT LL_I2C_IsActiveSMBusFlag_SMBDEFAULT
  1333. * @param I2Cx I2C Instance.
  1334. * @retval State of bit (1 or 0).
  1335. */
  1336. __STATIC_INLINE uint32_t LL_I2C_IsActiveSMBusFlag_SMBDEFAULT(I2C_TypeDef *I2Cx)
  1337. {
  1338. return (READ_BIT(I2Cx->SR2, I2C_SR2_SMBDEFAULT) == (I2C_SR2_SMBDEFAULT));
  1339. }
  1340. /**
  1341. * @brief Indicate the status of General call address reception (Slave mode).
  1342. * @note RESET: No Generall call address
  1343. * SET: General call address received.
  1344. * @note This status is cleared by hardware after a STOP condition or repeated START condition.
  1345. * @rmtoll SR2 GENCALL LL_I2C_IsActiveFlag_GENCALL
  1346. * @param I2Cx I2C Instance.
  1347. * @retval State of bit (1 or 0).
  1348. */
  1349. __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_GENCALL(I2C_TypeDef *I2Cx)
  1350. {
  1351. return (READ_BIT(I2Cx->SR2, I2C_SR2_GENCALL) == (I2C_SR2_GENCALL));
  1352. }
  1353. /**
  1354. * @brief Indicate the status of Master/Slave flag.
  1355. * @note RESET: Slave Mode.
  1356. * SET: Master Mode.
  1357. * @rmtoll SR2 MSL LL_I2C_IsActiveFlag_MSL
  1358. * @param I2Cx I2C Instance.
  1359. * @retval State of bit (1 or 0).
  1360. */
  1361. __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_MSL(I2C_TypeDef *I2Cx)
  1362. {
  1363. return (READ_BIT(I2Cx->SR2, I2C_SR2_MSL) == (I2C_SR2_MSL));
  1364. }
  1365. /**
  1366. * @brief Clear Address Matched flag.
  1367. * @note Clearing this flag is done by a read access to the I2Cx_SR1
  1368. * register followed by a read access to the I2Cx_SR2 register.
  1369. * @rmtoll SR1 ADDR LL_I2C_ClearFlag_ADDR
  1370. * @param I2Cx I2C Instance.
  1371. * @retval None
  1372. */
  1373. __STATIC_INLINE void LL_I2C_ClearFlag_ADDR(I2C_TypeDef *I2Cx)
  1374. {
  1375. __IO uint32_t tmpreg;
  1376. tmpreg = I2Cx->SR1;
  1377. (void) tmpreg;
  1378. tmpreg = I2Cx->SR2;
  1379. (void) tmpreg;
  1380. }
  1381. /**
  1382. * @brief Clear Acknowledge failure flag.
  1383. * @rmtoll SR1 AF LL_I2C_ClearFlag_AF
  1384. * @param I2Cx I2C Instance.
  1385. * @retval None
  1386. */
  1387. __STATIC_INLINE void LL_I2C_ClearFlag_AF(I2C_TypeDef *I2Cx)
  1388. {
  1389. CLEAR_BIT(I2Cx->SR1, I2C_SR1_AF);
  1390. }
  1391. /**
  1392. * @brief Clear Stop detection flag.
  1393. * @note Clearing this flag is done by a read access to the I2Cx_SR1
  1394. * register followed by a write access to I2Cx_CR1 register.
  1395. * @rmtoll SR1 STOPF LL_I2C_ClearFlag_STOP\n
  1396. * CR1 PE LL_I2C_ClearFlag_STOP
  1397. * @param I2Cx I2C Instance.
  1398. * @retval None
  1399. */
  1400. __STATIC_INLINE void LL_I2C_ClearFlag_STOP(I2C_TypeDef *I2Cx)
  1401. {
  1402. __IO uint32_t tmpreg;
  1403. tmpreg = I2Cx->SR1;
  1404. (void) tmpreg;
  1405. SET_BIT(I2Cx->CR1, I2C_CR1_PE);
  1406. }
  1407. /**
  1408. * @brief Clear Bus error flag.
  1409. * @rmtoll SR1 BERR LL_I2C_ClearFlag_BERR
  1410. * @param I2Cx I2C Instance.
  1411. * @retval None
  1412. */
  1413. __STATIC_INLINE void LL_I2C_ClearFlag_BERR(I2C_TypeDef *I2Cx)
  1414. {
  1415. CLEAR_BIT(I2Cx->SR1, I2C_SR1_BERR);
  1416. }
  1417. /**
  1418. * @brief Clear Arbitration lost flag.
  1419. * @rmtoll SR1 ARLO LL_I2C_ClearFlag_ARLO
  1420. * @param I2Cx I2C Instance.
  1421. * @retval None
  1422. */
  1423. __STATIC_INLINE void LL_I2C_ClearFlag_ARLO(I2C_TypeDef *I2Cx)
  1424. {
  1425. CLEAR_BIT(I2Cx->SR1, I2C_SR1_ARLO);
  1426. }
  1427. /**
  1428. * @brief Clear Overrun/Underrun flag.
  1429. * @rmtoll SR1 OVR LL_I2C_ClearFlag_OVR
  1430. * @param I2Cx I2C Instance.
  1431. * @retval None
  1432. */
  1433. __STATIC_INLINE void LL_I2C_ClearFlag_OVR(I2C_TypeDef *I2Cx)
  1434. {
  1435. CLEAR_BIT(I2Cx->SR1, I2C_SR1_OVR);
  1436. }
  1437. /**
  1438. * @brief Clear SMBus PEC error flag.
  1439. * @rmtoll SR1 PECERR LL_I2C_ClearSMBusFlag_PECERR
  1440. * @param I2Cx I2C Instance.
  1441. * @retval None
  1442. */
  1443. __STATIC_INLINE void LL_I2C_ClearSMBusFlag_PECERR(I2C_TypeDef *I2Cx)
  1444. {
  1445. CLEAR_BIT(I2Cx->SR1, I2C_SR1_PECERR);
  1446. }
  1447. /**
  1448. * @brief Clear SMBus Timeout detection flag.
  1449. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1450. * SMBus feature is supported by the I2Cx Instance.
  1451. * @rmtoll SR1 TIMEOUT LL_I2C_ClearSMBusFlag_TIMEOUT
  1452. * @param I2Cx I2C Instance.
  1453. * @retval None
  1454. */
  1455. __STATIC_INLINE void LL_I2C_ClearSMBusFlag_TIMEOUT(I2C_TypeDef *I2Cx)
  1456. {
  1457. CLEAR_BIT(I2Cx->SR1, I2C_SR1_TIMEOUT);
  1458. }
  1459. /**
  1460. * @brief Clear SMBus Alert flag.
  1461. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1462. * SMBus feature is supported by the I2Cx Instance.
  1463. * @rmtoll SR1 SMBALERT LL_I2C_ClearSMBusFlag_ALERT
  1464. * @param I2Cx I2C Instance.
  1465. * @retval None
  1466. */
  1467. __STATIC_INLINE void LL_I2C_ClearSMBusFlag_ALERT(I2C_TypeDef *I2Cx)
  1468. {
  1469. CLEAR_BIT(I2Cx->SR1, I2C_SR1_SMBALERT);
  1470. }
  1471. /**
  1472. * @}
  1473. */
  1474. /** @defgroup I2C_LL_EF_Data_Management Data_Management
  1475. * @{
  1476. */
  1477. /**
  1478. * @brief Enable Reset of I2C peripheral.
  1479. * @rmtoll CR1 SWRST LL_I2C_EnableReset
  1480. * @param I2Cx I2C Instance.
  1481. * @retval None
  1482. */
  1483. __STATIC_INLINE void LL_I2C_EnableReset(I2C_TypeDef *I2Cx)
  1484. {
  1485. SET_BIT(I2Cx->CR1, I2C_CR1_SWRST);
  1486. }
  1487. /**
  1488. * @brief Disable Reset of I2C peripheral.
  1489. * @rmtoll CR1 SWRST LL_I2C_DisableReset
  1490. * @param I2Cx I2C Instance.
  1491. * @retval None
  1492. */
  1493. __STATIC_INLINE void LL_I2C_DisableReset(I2C_TypeDef *I2Cx)
  1494. {
  1495. CLEAR_BIT(I2Cx->CR1, I2C_CR1_SWRST);
  1496. }
  1497. /**
  1498. * @brief Check if the I2C peripheral is under reset state or not.
  1499. * @rmtoll CR1 SWRST LL_I2C_IsResetEnabled
  1500. * @param I2Cx I2C Instance.
  1501. * @retval State of bit (1 or 0).
  1502. */
  1503. __STATIC_INLINE uint32_t LL_I2C_IsResetEnabled(I2C_TypeDef *I2Cx)
  1504. {
  1505. return (READ_BIT(I2Cx->CR1, I2C_CR1_SWRST) == (I2C_CR1_SWRST));
  1506. }
  1507. /**
  1508. * @brief Prepare the generation of a ACKnowledge or Non ACKnowledge condition after the address receive match code or next received byte.
  1509. * @note Usage in Slave or Master mode.
  1510. * @rmtoll CR1 ACK LL_I2C_AcknowledgeNextData
  1511. * @param I2Cx I2C Instance.
  1512. * @param TypeAcknowledge This parameter can be one of the following values:
  1513. * @arg @ref LL_I2C_ACK
  1514. * @arg @ref LL_I2C_NACK
  1515. * @retval None
  1516. */
  1517. __STATIC_INLINE void LL_I2C_AcknowledgeNextData(I2C_TypeDef *I2Cx, uint32_t TypeAcknowledge)
  1518. {
  1519. MODIFY_REG(I2Cx->CR1, I2C_CR1_ACK, TypeAcknowledge);
  1520. }
  1521. /**
  1522. * @brief Generate a START or RESTART condition
  1523. * @note The START bit can be set even if bus is BUSY or I2C is in slave mode.
  1524. * This action has no effect when RELOAD is set.
  1525. * @rmtoll CR1 START LL_I2C_GenerateStartCondition
  1526. * @param I2Cx I2C Instance.
  1527. * @retval None
  1528. */
  1529. __STATIC_INLINE void LL_I2C_GenerateStartCondition(I2C_TypeDef *I2Cx)
  1530. {
  1531. SET_BIT(I2Cx->CR1, I2C_CR1_START);
  1532. }
  1533. /**
  1534. * @brief Generate a STOP condition after the current byte transfer (master mode).
  1535. * @rmtoll CR1 STOP LL_I2C_GenerateStopCondition
  1536. * @param I2Cx I2C Instance.
  1537. * @retval None
  1538. */
  1539. __STATIC_INLINE void LL_I2C_GenerateStopCondition(I2C_TypeDef *I2Cx)
  1540. {
  1541. SET_BIT(I2Cx->CR1, I2C_CR1_STOP);
  1542. }
  1543. /**
  1544. * @brief Enable bit POS (master/host mode).
  1545. * @note In that case, the ACK bit controls the (N)ACK of the next byte received or the PEC bit indicates that the next byte in shift register is a PEC.
  1546. * @rmtoll CR1 POS LL_I2C_EnableBitPOS
  1547. * @param I2Cx I2C Instance.
  1548. * @retval None
  1549. */
  1550. __STATIC_INLINE void LL_I2C_EnableBitPOS(I2C_TypeDef *I2Cx)
  1551. {
  1552. SET_BIT(I2Cx->CR1, I2C_CR1_POS);
  1553. }
  1554. /**
  1555. * @brief Disable bit POS (master/host mode).
  1556. * @note In that case, the ACK bit controls the (N)ACK of the current byte received or the PEC bit indicates that the current byte in shift register is a PEC.
  1557. * @rmtoll CR1 POS LL_I2C_DisableBitPOS
  1558. * @param I2Cx I2C Instance.
  1559. * @retval None
  1560. */
  1561. __STATIC_INLINE void LL_I2C_DisableBitPOS(I2C_TypeDef *I2Cx)
  1562. {
  1563. CLEAR_BIT(I2Cx->CR1, I2C_CR1_POS);
  1564. }
  1565. /**
  1566. * @brief Check if bit POS is enabled or disabled.
  1567. * @rmtoll CR1 POS LL_I2C_IsEnabledBitPOS
  1568. * @param I2Cx I2C Instance.
  1569. * @retval State of bit (1 or 0).
  1570. */
  1571. __STATIC_INLINE uint32_t LL_I2C_IsEnabledBitPOS(I2C_TypeDef *I2Cx)
  1572. {
  1573. return (READ_BIT(I2Cx->CR1, I2C_CR1_POS) == (I2C_CR1_POS));
  1574. }
  1575. /**
  1576. * @brief Indicate the value of transfer direction.
  1577. * @note RESET: Bus is in read transfer (peripheral point of view).
  1578. * SET: Bus is in write transfer (peripheral point of view).
  1579. * @rmtoll SR2 TRA LL_I2C_GetTransferDirection
  1580. * @param I2Cx I2C Instance.
  1581. * @retval Returned value can be one of the following values:
  1582. * @arg @ref LL_I2C_DIRECTION_WRITE
  1583. * @arg @ref LL_I2C_DIRECTION_READ
  1584. */
  1585. __STATIC_INLINE uint32_t LL_I2C_GetTransferDirection(I2C_TypeDef *I2Cx)
  1586. {
  1587. return (uint32_t)(READ_BIT(I2Cx->SR2, I2C_SR2_TRA));
  1588. }
  1589. /**
  1590. * @brief Enable DMA last transfer.
  1591. * @note This action mean that next DMA EOT is the last transfer.
  1592. * @rmtoll CR2 LAST LL_I2C_EnableLastDMA
  1593. * @param I2Cx I2C Instance.
  1594. * @retval None
  1595. */
  1596. __STATIC_INLINE void LL_I2C_EnableLastDMA(I2C_TypeDef *I2Cx)
  1597. {
  1598. SET_BIT(I2Cx->CR2, I2C_CR2_LAST);
  1599. }
  1600. /**
  1601. * @brief Disable DMA last transfer.
  1602. * @note This action mean that next DMA EOT is not the last transfer.
  1603. * @rmtoll CR2 LAST LL_I2C_DisableLastDMA
  1604. * @param I2Cx I2C Instance.
  1605. * @retval None
  1606. */
  1607. __STATIC_INLINE void LL_I2C_DisableLastDMA(I2C_TypeDef *I2Cx)
  1608. {
  1609. CLEAR_BIT(I2Cx->CR2, I2C_CR2_LAST);
  1610. }
  1611. /**
  1612. * @brief Check if DMA last transfer is enabled or disabled.
  1613. * @rmtoll CR2 LAST LL_I2C_IsEnabledLastDMA
  1614. * @param I2Cx I2C Instance.
  1615. * @retval State of bit (1 or 0).
  1616. */
  1617. __STATIC_INLINE uint32_t LL_I2C_IsEnabledLastDMA(I2C_TypeDef *I2Cx)
  1618. {
  1619. return (READ_BIT(I2Cx->CR2, I2C_CR2_LAST) == (I2C_CR2_LAST));
  1620. }
  1621. /**
  1622. * @brief Enable transfer or internal comparison of the SMBus Packet Error byte (transmission or reception mode).
  1623. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1624. * SMBus feature is supported by the I2Cx Instance.
  1625. * @note This feature is cleared by hardware when the PEC byte is transferred or compared,
  1626. * or by a START or STOP condition, it is also cleared by software.
  1627. * @rmtoll CR1 PEC LL_I2C_EnableSMBusPECCompare
  1628. * @param I2Cx I2C Instance.
  1629. * @retval None
  1630. */
  1631. __STATIC_INLINE void LL_I2C_EnableSMBusPECCompare(I2C_TypeDef *I2Cx)
  1632. {
  1633. SET_BIT(I2Cx->CR1, I2C_CR1_PEC);
  1634. }
  1635. /**
  1636. * @brief Disable transfer or internal comparison of the SMBus Packet Error byte (transmission or reception mode).
  1637. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1638. * SMBus feature is supported by the I2Cx Instance.
  1639. * @rmtoll CR1 PEC LL_I2C_DisableSMBusPECCompare
  1640. * @param I2Cx I2C Instance.
  1641. * @retval None
  1642. */
  1643. __STATIC_INLINE void LL_I2C_DisableSMBusPECCompare(I2C_TypeDef *I2Cx)
  1644. {
  1645. CLEAR_BIT(I2Cx->CR1, I2C_CR1_PEC);
  1646. }
  1647. /**
  1648. * @brief Check if the SMBus Packet Error byte transfer or internal comparison is requested or not.
  1649. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1650. * SMBus feature is supported by the I2Cx Instance.
  1651. * @rmtoll CR1 PEC LL_I2C_IsEnabledSMBusPECCompare
  1652. * @param I2Cx I2C Instance.
  1653. * @retval State of bit (1 or 0).
  1654. */
  1655. __STATIC_INLINE uint32_t LL_I2C_IsEnabledSMBusPECCompare(I2C_TypeDef *I2Cx)
  1656. {
  1657. return (READ_BIT(I2Cx->CR1, I2C_CR1_PEC) == (I2C_CR1_PEC));
  1658. }
  1659. /**
  1660. * @brief Get the SMBus Packet Error byte calculated.
  1661. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1662. * SMBus feature is supported by the I2Cx Instance.
  1663. * @rmtoll SR2 PEC LL_I2C_GetSMBusPEC
  1664. * @param I2Cx I2C Instance.
  1665. * @retval Value between Min_Data=0x00 and Max_Data=0xFF
  1666. */
  1667. __STATIC_INLINE uint32_t LL_I2C_GetSMBusPEC(I2C_TypeDef *I2Cx)
  1668. {
  1669. return (uint32_t)(READ_BIT(I2Cx->SR2, I2C_SR2_PEC) >> I2C_SR2_PEC_Pos);
  1670. }
  1671. /**
  1672. * @brief Read Receive Data register.
  1673. * @rmtoll DR DR LL_I2C_ReceiveData8
  1674. * @param I2Cx I2C Instance.
  1675. * @retval Value between Min_Data=0x0 and Max_Data=0xFF
  1676. */
  1677. __STATIC_INLINE uint8_t LL_I2C_ReceiveData8(I2C_TypeDef *I2Cx)
  1678. {
  1679. return (uint8_t)(READ_BIT(I2Cx->DR, I2C_DR_DR));
  1680. }
  1681. /**
  1682. * @brief Write in Transmit Data Register .
  1683. * @rmtoll DR DR LL_I2C_TransmitData8
  1684. * @param I2Cx I2C Instance.
  1685. * @param Data Value between Min_Data=0x0 and Max_Data=0xFF
  1686. * @retval None
  1687. */
  1688. __STATIC_INLINE void LL_I2C_TransmitData8(I2C_TypeDef *I2Cx, uint8_t Data)
  1689. {
  1690. MODIFY_REG(I2Cx->DR, I2C_DR_DR, Data);
  1691. }
  1692. /**
  1693. * @}
  1694. */
  1695. #if defined(USE_FULL_LL_DRIVER)
  1696. /** @defgroup I2C_LL_EF_Init Initialization and de-initialization functions
  1697. * @{
  1698. */
  1699. uint32_t LL_I2C_Init(I2C_TypeDef *I2Cx, LL_I2C_InitTypeDef *I2C_InitStruct);
  1700. uint32_t LL_I2C_DeInit(I2C_TypeDef *I2Cx);
  1701. void LL_I2C_StructInit(LL_I2C_InitTypeDef *I2C_InitStruct);
  1702. /**
  1703. * @}
  1704. */
  1705. #endif /* USE_FULL_LL_DRIVER */
  1706. /**
  1707. * @}
  1708. */
  1709. /**
  1710. * @}
  1711. */
  1712. #endif /* I2C1 || I2C2 || I2C3 */
  1713. /**
  1714. * @}
  1715. */
  1716. #ifdef __cplusplus
  1717. }
  1718. #endif
  1719. #endif /* __STM32F4xx_LL_I2C_H */
  1720. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/