stm32l4xx_ll_i2c.h 84 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244
  1. /**
  2. ******************************************************************************
  3. * @file stm32l4xx_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 __STM32L4xx_LL_I2C_H
  37. #define __STM32L4xx_LL_I2C_H
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. /* Includes ------------------------------------------------------------------*/
  42. #include "stm32l4xx.h"
  43. /** @addtogroup STM32L4xx_LL_Driver
  44. * @{
  45. */
  46. #if defined (I2C1) || defined (I2C2) || defined (I2C3) || defined (I2C4)
  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. /**
  57. * @}
  58. */
  59. /* Private macros ------------------------------------------------------------*/
  60. #if defined(USE_FULL_LL_DRIVER)
  61. /** @defgroup I2C_LL_Private_Macros I2C Private Macros
  62. * @{
  63. */
  64. /**
  65. * @}
  66. */
  67. #endif /*USE_FULL_LL_DRIVER*/
  68. /* Exported types ------------------------------------------------------------*/
  69. #if defined(USE_FULL_LL_DRIVER)
  70. /** @defgroup I2C_LL_ES_INIT I2C Exported Init structure
  71. * @{
  72. */
  73. typedef struct
  74. {
  75. uint32_t PeripheralMode; /*!< Specifies the peripheral mode.
  76. This parameter can be a value of @ref I2C_LL_EC_PERIPHERAL_MODE
  77. This feature can be modified afterwards using unitary function @ref LL_I2C_SetMode(). */
  78. uint32_t Timing; /*!< Specifies the SDA setup, hold time and the SCL high, low period values.
  79. This parameter must be set by referring to the STM32CubeMX Tool and
  80. the helper macro @ref __LL_I2C_CONVERT_TIMINGS()
  81. This feature can be modified afterwards using unitary function @ref LL_I2C_SetTiming(). */
  82. uint32_t AnalogFilter; /*!< Enables or disables analog noise filter.
  83. This parameter can be a value of @ref I2C_LL_EC_ANALOGFILTER_SELECTION
  84. This feature can be modified afterwards using unitary functions @ref LL_I2C_EnableAnalogFilter() or LL_I2C_DisableAnalogFilter(). */
  85. uint32_t DigitalFilter; /*!< Configures the digital noise filter.
  86. This parameter can be a number between Min_Data = 0x00 and Max_Data = 0x0F
  87. This feature can be modified afterwards using unitary function @ref LL_I2C_SetDigitalFilter(). */
  88. uint32_t OwnAddress1; /*!< Specifies the device own address 1.
  89. This parameter must be a value between Min_Data = 0x00 and Max_Data = 0x3FF
  90. This feature can be modified afterwards using unitary function @ref LL_I2C_SetOwnAddress1(). */
  91. uint32_t TypeAcknowledge; /*!< Specifies the ACKnowledge or Non ACKnowledge condition after the address receive match code or next received byte.
  92. This parameter can be a value of @ref I2C_LL_EC_I2C_ACKNOWLEDGE
  93. This feature can be modified afterwards using unitary function @ref LL_I2C_AcknowledgeNextData(). */
  94. uint32_t OwnAddrSize; /*!< Specifies the device own address 1 size (7-bit or 10-bit).
  95. This parameter can be a value of @ref I2C_LL_EC_OWNADDRESS1
  96. This feature can be modified afterwards using unitary function @ref LL_I2C_SetOwnAddress1(). */
  97. } LL_I2C_InitTypeDef;
  98. /**
  99. * @}
  100. */
  101. #endif /*USE_FULL_LL_DRIVER*/
  102. /* Exported constants --------------------------------------------------------*/
  103. /** @defgroup I2C_LL_Exported_Constants I2C Exported Constants
  104. * @{
  105. */
  106. /** @defgroup I2C_LL_EC_CLEAR_FLAG Clear Flags Defines
  107. * @brief Flags defines which can be used with LL_I2C_WriteReg function
  108. * @{
  109. */
  110. #define LL_I2C_ICR_ADDRCF I2C_ICR_ADDRCF /*!< Address Matched flag */
  111. #define LL_I2C_ICR_NACKCF I2C_ICR_NACKCF /*!< Not Acknowledge flag */
  112. #define LL_I2C_ICR_STOPCF I2C_ICR_STOPCF /*!< Stop detection flag */
  113. #define LL_I2C_ICR_BERRCF I2C_ICR_BERRCF /*!< Bus error flag */
  114. #define LL_I2C_ICR_ARLOCF I2C_ICR_ARLOCF /*!< Arbitration Lost flag */
  115. #define LL_I2C_ICR_OVRCF I2C_ICR_OVRCF /*!< Overrun/Underrun flag */
  116. #define LL_I2C_ICR_PECCF I2C_ICR_PECCF /*!< PEC error flag */
  117. #define LL_I2C_ICR_TIMOUTCF I2C_ICR_TIMOUTCF /*!< Timeout detection flag */
  118. #define LL_I2C_ICR_ALERTCF I2C_ICR_ALERTCF /*!< Alert flag */
  119. /**
  120. * @}
  121. */
  122. /** @defgroup I2C_LL_EC_GET_FLAG Get Flags Defines
  123. * @brief Flags defines which can be used with LL_I2C_ReadReg function
  124. * @{
  125. */
  126. #define LL_I2C_ISR_TXE I2C_ISR_TXE /*!< Transmit data register empty */
  127. #define LL_I2C_ISR_TXIS I2C_ISR_TXIS /*!< Transmit interrupt status */
  128. #define LL_I2C_ISR_RXNE I2C_ISR_RXNE /*!< Receive data register not empty */
  129. #define LL_I2C_ISR_ADDR I2C_ISR_ADDR /*!< Address matched (slave mode) */
  130. #define LL_I2C_ISR_NACKF I2C_ISR_NACKF /*!< Not Acknowledge received flag */
  131. #define LL_I2C_ISR_STOPF I2C_ISR_STOPF /*!< Stop detection flag */
  132. #define LL_I2C_ISR_TC I2C_ISR_TC /*!< Transfer Complete (master mode) */
  133. #define LL_I2C_ISR_TCR I2C_ISR_TCR /*!< Transfer Complete Reload */
  134. #define LL_I2C_ISR_BERR I2C_ISR_BERR /*!< Bus error */
  135. #define LL_I2C_ISR_ARLO I2C_ISR_ARLO /*!< Arbitration lost */
  136. #define LL_I2C_ISR_OVR I2C_ISR_OVR /*!< Overrun/Underrun (slave mode) */
  137. #define LL_I2C_ISR_PECERR I2C_ISR_PECERR /*!< PEC Error in reception (SMBus mode) */
  138. #define LL_I2C_ISR_TIMEOUT I2C_ISR_TIMEOUT /*!< Timeout detection flag (SMBus mode) */
  139. #define LL_I2C_ISR_ALERT I2C_ISR_ALERT /*!< SMBus alert (SMBus mode) */
  140. #define LL_I2C_ISR_BUSY I2C_ISR_BUSY /*!< Bus busy */
  141. /**
  142. * @}
  143. */
  144. /** @defgroup I2C_LL_EC_IT IT Defines
  145. * @brief IT defines which can be used with LL_I2C_ReadReg and LL_I2C_WriteReg functions
  146. * @{
  147. */
  148. #define LL_I2C_CR1_TXIE I2C_CR1_TXIE /*!< TX Interrupt enable */
  149. #define LL_I2C_CR1_RXIE I2C_CR1_RXIE /*!< RX Interrupt enable */
  150. #define LL_I2C_CR1_ADDRIE I2C_CR1_ADDRIE /*!< Address match Interrupt enable (slave only) */
  151. #define LL_I2C_CR1_NACKIE I2C_CR1_NACKIE /*!< Not acknowledge received Interrupt enable */
  152. #define LL_I2C_CR1_STOPIE I2C_CR1_STOPIE /*!< STOP detection Interrupt enable */
  153. #define LL_I2C_CR1_TCIE I2C_CR1_TCIE /*!< Transfer Complete interrupt enable */
  154. #define LL_I2C_CR1_ERRIE I2C_CR1_ERRIE /*!< Error interrupts enable */
  155. /**
  156. * @}
  157. */
  158. /** @defgroup I2C_LL_EC_PERIPHERAL_MODE Peripheral Mode
  159. * @{
  160. */
  161. #define LL_I2C_MODE_I2C 0x00000000U /*!< I2C Master or Slave mode */
  162. #define LL_I2C_MODE_SMBUS_HOST I2C_CR1_SMBHEN /*!< SMBus Host address acknowledge */
  163. #define LL_I2C_MODE_SMBUS_DEVICE 0x00000000U /*!< SMBus Device default mode (Default address not acknowledge) */
  164. #define LL_I2C_MODE_SMBUS_DEVICE_ARP I2C_CR1_SMBDEN /*!< SMBus Device Default address acknowledge */
  165. /**
  166. * @}
  167. */
  168. /** @defgroup I2C_LL_EC_ANALOGFILTER_SELECTION Analog Filter Selection
  169. * @{
  170. */
  171. #define LL_I2C_ANALOGFILTER_ENABLE 0x00000000U /*!< Analog filter is enabled. */
  172. #define LL_I2C_ANALOGFILTER_DISABLE I2C_CR1_ANFOFF /*!< Analog filter is disabled. */
  173. /**
  174. * @}
  175. */
  176. /** @defgroup I2C_LL_EC_ADDRESSING_MODE Master Addressing Mode
  177. * @{
  178. */
  179. #define LL_I2C_ADDRESSING_MODE_7BIT 0x00000000U /*!< Master operates in 7-bit addressing mode. */
  180. #define LL_I2C_ADDRESSING_MODE_10BIT I2C_CR2_ADD10 /*!< Master operates in 10-bit addressing mode.*/
  181. /**
  182. * @}
  183. */
  184. /** @defgroup I2C_LL_EC_OWNADDRESS1 Own Address 1 Length
  185. * @{
  186. */
  187. #define LL_I2C_OWNADDRESS1_7BIT 0x00000000U /*!< Own address 1 is a 7-bit address. */
  188. #define LL_I2C_OWNADDRESS1_10BIT I2C_OAR1_OA1MODE /*!< Own address 1 is a 10-bit address.*/
  189. /**
  190. * @}
  191. */
  192. /** @defgroup I2C_LL_EC_OWNADDRESS2 Own Address 2 Masks
  193. * @{
  194. */
  195. #define LL_I2C_OWNADDRESS2_NOMASK I2C_OAR2_OA2NOMASK /*!< Own Address2 No mask. */
  196. #define LL_I2C_OWNADDRESS2_MASK01 I2C_OAR2_OA2MASK01 /*!< Only Address2 bits[7:2] are compared. */
  197. #define LL_I2C_OWNADDRESS2_MASK02 I2C_OAR2_OA2MASK02 /*!< Only Address2 bits[7:3] are compared. */
  198. #define LL_I2C_OWNADDRESS2_MASK03 I2C_OAR2_OA2MASK03 /*!< Only Address2 bits[7:4] are compared. */
  199. #define LL_I2C_OWNADDRESS2_MASK04 I2C_OAR2_OA2MASK04 /*!< Only Address2 bits[7:5] are compared. */
  200. #define LL_I2C_OWNADDRESS2_MASK05 I2C_OAR2_OA2MASK05 /*!< Only Address2 bits[7:6] are compared. */
  201. #define LL_I2C_OWNADDRESS2_MASK06 I2C_OAR2_OA2MASK06 /*!< Only Address2 bits[7] are compared. */
  202. #define LL_I2C_OWNADDRESS2_MASK07 I2C_OAR2_OA2MASK07 /*!< No comparison is done. All Address2 are acknowledged.*/
  203. /**
  204. * @}
  205. */
  206. /** @defgroup I2C_LL_EC_I2C_ACKNOWLEDGE Acknowledge Generation
  207. * @{
  208. */
  209. #define LL_I2C_ACK 0x00000000U /*!< ACK is sent after current received byte. */
  210. #define LL_I2C_NACK I2C_CR2_NACK /*!< NACK is sent after current received byte.*/
  211. /**
  212. * @}
  213. */
  214. /** @defgroup I2C_LL_EC_ADDRSLAVE Slave Address Length
  215. * @{
  216. */
  217. #define LL_I2C_ADDRSLAVE_7BIT 0x00000000U /*!< Slave Address in 7-bit. */
  218. #define LL_I2C_ADDRSLAVE_10BIT I2C_CR2_ADD10 /*!< Slave Address in 10-bit.*/
  219. /**
  220. * @}
  221. */
  222. /** @defgroup I2C_LL_EC_REQUEST Transfer Request Direction
  223. * @{
  224. */
  225. #define LL_I2C_REQUEST_WRITE 0x00000000U /*!< Master request a write transfer. */
  226. #define LL_I2C_REQUEST_READ I2C_CR2_RD_WRN /*!< Master request a read transfer. */
  227. /**
  228. * @}
  229. */
  230. /** @defgroup I2C_LL_EC_MODE Transfer End Mode
  231. * @{
  232. */
  233. #define LL_I2C_MODE_RELOAD I2C_CR2_RELOAD /*!< Enable I2C Reload mode. */
  234. #define LL_I2C_MODE_AUTOEND I2C_CR2_AUTOEND /*!< Enable I2C Automatic end mode with no HW PEC comparison. */
  235. #define LL_I2C_MODE_SOFTEND 0x00000000U /*!< Enable I2C Software end mode with no HW PEC comparison. */
  236. #define LL_I2C_MODE_SMBUS_RELOAD LL_I2C_MODE_RELOAD /*!< Enable SMBUS Automatic end mode with HW PEC comparison. */
  237. #define LL_I2C_MODE_SMBUS_AUTOEND_NO_PEC LL_I2C_MODE_AUTOEND /*!< Enable SMBUS Automatic end mode with HW PEC comparison. */
  238. #define LL_I2C_MODE_SMBUS_SOFTEND_NO_PEC LL_I2C_MODE_SOFTEND /*!< Enable SMBUS Software end mode with HW PEC comparison. */
  239. #define LL_I2C_MODE_SMBUS_AUTOEND_WITH_PEC (uint32_t)(LL_I2C_MODE_AUTOEND | I2C_CR2_PECBYTE) /*!< Enable SMBUS Automatic end mode with HW PEC comparison. */
  240. #define LL_I2C_MODE_SMBUS_SOFTEND_WITH_PEC (uint32_t)(LL_I2C_MODE_SOFTEND | I2C_CR2_PECBYTE) /*!< Enable SMBUS Software end mode with HW PEC comparison. */
  241. /**
  242. * @}
  243. */
  244. /** @defgroup I2C_LL_EC_GENERATE Start And Stop Generation
  245. * @{
  246. */
  247. #define LL_I2C_GENERATE_NOSTARTSTOP 0x00000000U /*!< Don't Generate Stop and Start condition. */
  248. #define LL_I2C_GENERATE_STOP (uint32_t)(0x80000000U | I2C_CR2_STOP) /*!< Generate Stop condition (Size should be set to 0). */
  249. #define LL_I2C_GENERATE_START_READ (uint32_t)(0x80000000U | I2C_CR2_START | I2C_CR2_RD_WRN) /*!< Generate Start for read request. */
  250. #define LL_I2C_GENERATE_START_WRITE (uint32_t)(0x80000000U | I2C_CR2_START) /*!< Generate Start for write request. */
  251. #define LL_I2C_GENERATE_RESTART_7BIT_READ (uint32_t)(0x80000000U | I2C_CR2_START | I2C_CR2_RD_WRN) /*!< Generate Restart for read request, slave 7Bit address. */
  252. #define LL_I2C_GENERATE_RESTART_7BIT_WRITE (uint32_t)(0x80000000U | I2C_CR2_START) /*!< Generate Restart for write request, slave 7Bit address. */
  253. #define LL_I2C_GENERATE_RESTART_10BIT_READ (uint32_t)(0x80000000U | I2C_CR2_START | I2C_CR2_RD_WRN | I2C_CR2_HEAD10R) /*!< Generate Restart for read request, slave 10Bit address. */
  254. #define LL_I2C_GENERATE_RESTART_10BIT_WRITE (uint32_t)(0x80000000U | I2C_CR2_START) /*!< Generate Restart for write request, slave 10Bit address.*/
  255. /**
  256. * @}
  257. */
  258. /** @defgroup I2C_LL_EC_DIRECTION Read Write Direction
  259. * @{
  260. */
  261. #define LL_I2C_DIRECTION_WRITE 0x00000000U /*!< Write transfer request by master, slave enters receiver mode. */
  262. #define LL_I2C_DIRECTION_READ I2C_ISR_DIR /*!< Read transfer request by master, slave enters transmitter mode.*/
  263. /**
  264. * @}
  265. */
  266. /** @defgroup I2C_LL_EC_DMA_REG_DATA DMA Register Data
  267. * @{
  268. */
  269. #define LL_I2C_DMA_REG_DATA_TRANSMIT 0x00000000U /*!< Get address of data register used for transmission */
  270. #define LL_I2C_DMA_REG_DATA_RECEIVE 0x00000001U /*!< Get address of data register used for reception */
  271. /**
  272. * @}
  273. */
  274. /** @defgroup I2C_LL_EC_SMBUS_TIMEOUTA_MODE SMBus TimeoutA Mode SCL SDA Timeout
  275. * @{
  276. */
  277. #define LL_I2C_SMBUS_TIMEOUTA_MODE_SCL_LOW 0x00000000U /*!< TimeoutA is used to detect SCL low level timeout. */
  278. #define LL_I2C_SMBUS_TIMEOUTA_MODE_SDA_SCL_HIGH I2C_TIMEOUTR_TIDLE /*!< TimeoutA is used to detect both SCL and SDA high level timeout.*/
  279. /**
  280. * @}
  281. */
  282. /** @defgroup I2C_LL_EC_SMBUS_TIMEOUT_SELECTION SMBus Timeout Selection
  283. * @{
  284. */
  285. #define LL_I2C_SMBUS_TIMEOUTA I2C_TIMEOUTR_TIMOUTEN /*!< TimeoutA enable bit */
  286. #define LL_I2C_SMBUS_TIMEOUTB I2C_TIMEOUTR_TEXTEN /*!< TimeoutB (extended clock) enable bit */
  287. #define LL_I2C_SMBUS_ALL_TIMEOUT (uint32_t)(I2C_TIMEOUTR_TIMOUTEN | I2C_TIMEOUTR_TEXTEN) /*!< TimeoutA and TimeoutB (extended clock) enable bits */
  288. /**
  289. * @}
  290. */
  291. /**
  292. * @}
  293. */
  294. /* Exported macro ------------------------------------------------------------*/
  295. /** @defgroup I2C_LL_Exported_Macros I2C Exported Macros
  296. * @{
  297. */
  298. /** @defgroup I2C_LL_EM_WRITE_READ Common Write and read registers Macros
  299. * @{
  300. */
  301. /**
  302. * @brief Write a value in I2C register
  303. * @param __INSTANCE__ I2C Instance
  304. * @param __REG__ Register to be written
  305. * @param __VALUE__ Value to be written in the register
  306. * @retval None
  307. */
  308. #define LL_I2C_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
  309. /**
  310. * @brief Read a value in I2C register
  311. * @param __INSTANCE__ I2C Instance
  312. * @param __REG__ Register to be read
  313. * @retval Register value
  314. */
  315. #define LL_I2C_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
  316. /**
  317. * @}
  318. */
  319. /** @defgroup I2C_LL_EM_CONVERT_TIMINGS Convert SDA SCL timings
  320. * @{
  321. */
  322. /**
  323. * @brief Configure the SDA setup, hold time and the SCL high, low period.
  324. * @param __PRESCALER__ This parameter must be a value between Min_Data=0 and Max_Data=0xF.
  325. * @param __DATA_SETUP_TIME__ This parameter must be a value between Min_Data=0 and Max_Data=0xF. (tscldel = (SCLDEL+1)xtpresc)
  326. * @param __DATA_HOLD_TIME__ This parameter must be a value between Min_Data=0 and Max_Data=0xF. (tsdadel = SDADELxtpresc)
  327. * @param __CLOCK_HIGH_PERIOD__ This parameter must be a value between Min_Data=0 and Max_Data=0xFF. (tsclh = (SCLH+1)xtpresc)
  328. * @param __CLOCK_LOW_PERIOD__ This parameter must be a value between Min_Data=0 and Max_Data=0xFF. (tscll = (SCLL+1)xtpresc)
  329. * @retval Value between Min_Data=0 and Max_Data=0xFFFFFFFF
  330. */
  331. #define __LL_I2C_CONVERT_TIMINGS(__PRESCALER__, __DATA_SETUP_TIME__, __DATA_HOLD_TIME__, __CLOCK_HIGH_PERIOD__, __CLOCK_LOW_PERIOD__) \
  332. ((((uint32_t)(__PRESCALER__) << I2C_TIMINGR_PRESC_Pos) & I2C_TIMINGR_PRESC) | \
  333. (((uint32_t)(__DATA_SETUP_TIME__) << I2C_TIMINGR_SCLDEL_Pos) & I2C_TIMINGR_SCLDEL) | \
  334. (((uint32_t)(__DATA_HOLD_TIME__) << I2C_TIMINGR_SDADEL_Pos) & I2C_TIMINGR_SDADEL) | \
  335. (((uint32_t)(__CLOCK_HIGH_PERIOD__) << I2C_TIMINGR_SCLH_Pos) & I2C_TIMINGR_SCLH) | \
  336. (((uint32_t)(__CLOCK_LOW_PERIOD__) << I2C_TIMINGR_SCLL_Pos) & I2C_TIMINGR_SCLL))
  337. /**
  338. * @}
  339. */
  340. /**
  341. * @}
  342. */
  343. /* Exported functions --------------------------------------------------------*/
  344. /** @defgroup I2C_LL_Exported_Functions I2C Exported Functions
  345. * @{
  346. */
  347. /** @defgroup I2C_LL_EF_Configuration Configuration
  348. * @{
  349. */
  350. /**
  351. * @brief Enable I2C peripheral (PE = 1).
  352. * @rmtoll CR1 PE LL_I2C_Enable
  353. * @param I2Cx I2C Instance.
  354. * @retval None
  355. */
  356. __STATIC_INLINE void LL_I2C_Enable(I2C_TypeDef *I2Cx)
  357. {
  358. SET_BIT(I2Cx->CR1, I2C_CR1_PE);
  359. }
  360. /**
  361. * @brief Disable I2C peripheral (PE = 0).
  362. * @note When PE = 0, the I2C SCL and SDA lines are released.
  363. * Internal state machines and status bits are put back to their reset value.
  364. * When cleared, PE must be kept low for at least 3 APB clock cycles.
  365. * @rmtoll CR1 PE LL_I2C_Disable
  366. * @param I2Cx I2C Instance.
  367. * @retval None
  368. */
  369. __STATIC_INLINE void LL_I2C_Disable(I2C_TypeDef *I2Cx)
  370. {
  371. CLEAR_BIT(I2Cx->CR1, I2C_CR1_PE);
  372. }
  373. /**
  374. * @brief Check if the I2C peripheral is enabled or disabled.
  375. * @rmtoll CR1 PE LL_I2C_IsEnabled
  376. * @param I2Cx I2C Instance.
  377. * @retval State of bit (1 or 0).
  378. */
  379. __STATIC_INLINE uint32_t LL_I2C_IsEnabled(I2C_TypeDef *I2Cx)
  380. {
  381. return (READ_BIT(I2Cx->CR1, I2C_CR1_PE) == (I2C_CR1_PE));
  382. }
  383. /**
  384. * @brief Configure Noise Filters (Analog and Digital).
  385. * @note If the analog filter is also enabled, the digital filter is added to analog filter.
  386. * The filters can only be programmed when the I2C is disabled (PE = 0).
  387. * @rmtoll CR1 ANFOFF LL_I2C_ConfigFilters\n
  388. * CR1 DNF LL_I2C_ConfigFilters
  389. * @param I2Cx I2C Instance.
  390. * @param AnalogFilter This parameter can be one of the following values:
  391. * @arg @ref LL_I2C_ANALOGFILTER_ENABLE
  392. * @arg @ref LL_I2C_ANALOGFILTER_DISABLE
  393. * @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*ti2cclk).
  394. * This parameter is used to configure the digital noise filter on SDA and SCL input.
  395. * The digital filter will filter spikes with a length of up to DNF[3:0]*ti2cclk.
  396. * @retval None
  397. */
  398. __STATIC_INLINE void LL_I2C_ConfigFilters(I2C_TypeDef *I2Cx, uint32_t AnalogFilter, uint32_t DigitalFilter)
  399. {
  400. MODIFY_REG(I2Cx->CR1, I2C_CR1_ANFOFF | I2C_CR1_DNF, AnalogFilter | (DigitalFilter << I2C_CR1_DNF_Pos));
  401. }
  402. /**
  403. * @brief Configure Digital Noise Filter.
  404. * @note If the analog filter is also enabled, the digital filter is added to analog filter.
  405. * This filter can only be programmed when the I2C is disabled (PE = 0).
  406. * @rmtoll CR1 DNF LL_I2C_SetDigitalFilter
  407. * @param I2Cx I2C Instance.
  408. * @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*ti2cclk).
  409. * This parameter is used to configure the digital noise filter on SDA and SCL input.
  410. * The digital filter will filter spikes with a length of up to DNF[3:0]*ti2cclk.
  411. * @retval None
  412. */
  413. __STATIC_INLINE void LL_I2C_SetDigitalFilter(I2C_TypeDef *I2Cx, uint32_t DigitalFilter)
  414. {
  415. MODIFY_REG(I2Cx->CR1, I2C_CR1_DNF, DigitalFilter << I2C_CR1_DNF_Pos);
  416. }
  417. /**
  418. * @brief Get the current Digital Noise Filter configuration.
  419. * @rmtoll CR1 DNF LL_I2C_GetDigitalFilter
  420. * @param I2Cx I2C Instance.
  421. * @retval Value between Min_Data=0x0 and Max_Data=0xF
  422. */
  423. __STATIC_INLINE uint32_t LL_I2C_GetDigitalFilter(I2C_TypeDef *I2Cx)
  424. {
  425. return (uint32_t)(READ_BIT(I2Cx->CR1, I2C_CR1_DNF) >> I2C_CR1_DNF_Pos);
  426. }
  427. /**
  428. * @brief Enable Analog Noise Filter.
  429. * @note This filter can only be programmed when the I2C is disabled (PE = 0).
  430. * @rmtoll CR1 ANFOFF LL_I2C_EnableAnalogFilter
  431. * @param I2Cx I2C Instance.
  432. * @retval None
  433. */
  434. __STATIC_INLINE void LL_I2C_EnableAnalogFilter(I2C_TypeDef *I2Cx)
  435. {
  436. CLEAR_BIT(I2Cx->CR1, I2C_CR1_ANFOFF);
  437. }
  438. /**
  439. * @brief Disable Analog Noise Filter.
  440. * @note This filter can only be programmed when the I2C is disabled (PE = 0).
  441. * @rmtoll CR1 ANFOFF LL_I2C_DisableAnalogFilter
  442. * @param I2Cx I2C Instance.
  443. * @retval None
  444. */
  445. __STATIC_INLINE void LL_I2C_DisableAnalogFilter(I2C_TypeDef *I2Cx)
  446. {
  447. SET_BIT(I2Cx->CR1, I2C_CR1_ANFOFF);
  448. }
  449. /**
  450. * @brief Check if Analog Noise Filter is enabled or disabled.
  451. * @rmtoll CR1 ANFOFF LL_I2C_IsEnabledAnalogFilter
  452. * @param I2Cx I2C Instance.
  453. * @retval State of bit (1 or 0).
  454. */
  455. __STATIC_INLINE uint32_t LL_I2C_IsEnabledAnalogFilter(I2C_TypeDef *I2Cx)
  456. {
  457. return (READ_BIT(I2Cx->CR1, I2C_CR1_ANFOFF) != (I2C_CR1_ANFOFF));
  458. }
  459. /**
  460. * @brief Enable DMA transmission requests.
  461. * @rmtoll CR1 TXDMAEN LL_I2C_EnableDMAReq_TX
  462. * @param I2Cx I2C Instance.
  463. * @retval None
  464. */
  465. __STATIC_INLINE void LL_I2C_EnableDMAReq_TX(I2C_TypeDef *I2Cx)
  466. {
  467. SET_BIT(I2Cx->CR1, I2C_CR1_TXDMAEN);
  468. }
  469. /**
  470. * @brief Disable DMA transmission requests.
  471. * @rmtoll CR1 TXDMAEN LL_I2C_DisableDMAReq_TX
  472. * @param I2Cx I2C Instance.
  473. * @retval None
  474. */
  475. __STATIC_INLINE void LL_I2C_DisableDMAReq_TX(I2C_TypeDef *I2Cx)
  476. {
  477. CLEAR_BIT(I2Cx->CR1, I2C_CR1_TXDMAEN);
  478. }
  479. /**
  480. * @brief Check if DMA transmission requests are enabled or disabled.
  481. * @rmtoll CR1 TXDMAEN LL_I2C_IsEnabledDMAReq_TX
  482. * @param I2Cx I2C Instance.
  483. * @retval State of bit (1 or 0).
  484. */
  485. __STATIC_INLINE uint32_t LL_I2C_IsEnabledDMAReq_TX(I2C_TypeDef *I2Cx)
  486. {
  487. return (READ_BIT(I2Cx->CR1, I2C_CR1_TXDMAEN) == (I2C_CR1_TXDMAEN));
  488. }
  489. /**
  490. * @brief Enable DMA reception requests.
  491. * @rmtoll CR1 RXDMAEN LL_I2C_EnableDMAReq_RX
  492. * @param I2Cx I2C Instance.
  493. * @retval None
  494. */
  495. __STATIC_INLINE void LL_I2C_EnableDMAReq_RX(I2C_TypeDef *I2Cx)
  496. {
  497. SET_BIT(I2Cx->CR1, I2C_CR1_RXDMAEN);
  498. }
  499. /**
  500. * @brief Disable DMA reception requests.
  501. * @rmtoll CR1 RXDMAEN LL_I2C_DisableDMAReq_RX
  502. * @param I2Cx I2C Instance.
  503. * @retval None
  504. */
  505. __STATIC_INLINE void LL_I2C_DisableDMAReq_RX(I2C_TypeDef *I2Cx)
  506. {
  507. CLEAR_BIT(I2Cx->CR1, I2C_CR1_RXDMAEN);
  508. }
  509. /**
  510. * @brief Check if DMA reception requests are enabled or disabled.
  511. * @rmtoll CR1 RXDMAEN LL_I2C_IsEnabledDMAReq_RX
  512. * @param I2Cx I2C Instance.
  513. * @retval State of bit (1 or 0).
  514. */
  515. __STATIC_INLINE uint32_t LL_I2C_IsEnabledDMAReq_RX(I2C_TypeDef *I2Cx)
  516. {
  517. return (READ_BIT(I2Cx->CR1, I2C_CR1_RXDMAEN) == (I2C_CR1_RXDMAEN));
  518. }
  519. /**
  520. * @brief Get the data register address used for DMA transfer
  521. * @rmtoll TXDR TXDATA LL_I2C_DMA_GetRegAddr\n
  522. * RXDR RXDATA LL_I2C_DMA_GetRegAddr
  523. * @param I2Cx I2C Instance
  524. * @param Direction This parameter can be one of the following values:
  525. * @arg @ref LL_I2C_DMA_REG_DATA_TRANSMIT
  526. * @arg @ref LL_I2C_DMA_REG_DATA_RECEIVE
  527. * @retval Address of data register
  528. */
  529. __STATIC_INLINE uint32_t LL_I2C_DMA_GetRegAddr(I2C_TypeDef *I2Cx, uint32_t Direction)
  530. {
  531. register uint32_t data_reg_addr = 0U;
  532. if (Direction == LL_I2C_DMA_REG_DATA_TRANSMIT)
  533. {
  534. /* return address of TXDR register */
  535. data_reg_addr = (uint32_t) & (I2Cx->TXDR);
  536. }
  537. else
  538. {
  539. /* return address of RXDR register */
  540. data_reg_addr = (uint32_t) & (I2Cx->RXDR);
  541. }
  542. return data_reg_addr;
  543. }
  544. /**
  545. * @brief Enable Clock stretching.
  546. * @note This bit can only be programmed when the I2C is disabled (PE = 0).
  547. * @rmtoll CR1 NOSTRETCH LL_I2C_EnableClockStretching
  548. * @param I2Cx I2C Instance.
  549. * @retval None
  550. */
  551. __STATIC_INLINE void LL_I2C_EnableClockStretching(I2C_TypeDef *I2Cx)
  552. {
  553. CLEAR_BIT(I2Cx->CR1, I2C_CR1_NOSTRETCH);
  554. }
  555. /**
  556. * @brief Disable Clock stretching.
  557. * @note This bit can only be programmed when the I2C is disabled (PE = 0).
  558. * @rmtoll CR1 NOSTRETCH LL_I2C_DisableClockStretching
  559. * @param I2Cx I2C Instance.
  560. * @retval None
  561. */
  562. __STATIC_INLINE void LL_I2C_DisableClockStretching(I2C_TypeDef *I2Cx)
  563. {
  564. SET_BIT(I2Cx->CR1, I2C_CR1_NOSTRETCH);
  565. }
  566. /**
  567. * @brief Check if Clock stretching is enabled or disabled.
  568. * @rmtoll CR1 NOSTRETCH LL_I2C_IsEnabledClockStretching
  569. * @param I2Cx I2C Instance.
  570. * @retval State of bit (1 or 0).
  571. */
  572. __STATIC_INLINE uint32_t LL_I2C_IsEnabledClockStretching(I2C_TypeDef *I2Cx)
  573. {
  574. return (READ_BIT(I2Cx->CR1, I2C_CR1_NOSTRETCH) != (I2C_CR1_NOSTRETCH));
  575. }
  576. /**
  577. * @brief Enable hardware byte control in slave mode.
  578. * @rmtoll CR1 SBC LL_I2C_EnableSlaveByteControl
  579. * @param I2Cx I2C Instance.
  580. * @retval None
  581. */
  582. __STATIC_INLINE void LL_I2C_EnableSlaveByteControl(I2C_TypeDef *I2Cx)
  583. {
  584. SET_BIT(I2Cx->CR1, I2C_CR1_SBC);
  585. }
  586. /**
  587. * @brief Disable hardware byte control in slave mode.
  588. * @rmtoll CR1 SBC LL_I2C_DisableSlaveByteControl
  589. * @param I2Cx I2C Instance.
  590. * @retval None
  591. */
  592. __STATIC_INLINE void LL_I2C_DisableSlaveByteControl(I2C_TypeDef *I2Cx)
  593. {
  594. CLEAR_BIT(I2Cx->CR1, I2C_CR1_SBC);
  595. }
  596. /**
  597. * @brief Check if hardware byte control in slave mode is enabled or disabled.
  598. * @rmtoll CR1 SBC LL_I2C_IsEnabledSlaveByteControl
  599. * @param I2Cx I2C Instance.
  600. * @retval State of bit (1 or 0).
  601. */
  602. __STATIC_INLINE uint32_t LL_I2C_IsEnabledSlaveByteControl(I2C_TypeDef *I2Cx)
  603. {
  604. return (READ_BIT(I2Cx->CR1, I2C_CR1_SBC) == (I2C_CR1_SBC));
  605. }
  606. /**
  607. * @brief Enable Wakeup from STOP.
  608. * @note Macro @ref IS_I2C_WAKEUP_FROMSTOP_INSTANCE(I2Cx) can be used to check whether or not
  609. * WakeUpFromStop feature is supported by the I2Cx Instance.
  610. * @note This bit can only be programmed when Digital Filter is disabled.
  611. * @rmtoll CR1 WUPEN LL_I2C_EnableWakeUpFromStop
  612. * @param I2Cx I2C Instance.
  613. * @retval None
  614. */
  615. __STATIC_INLINE void LL_I2C_EnableWakeUpFromStop(I2C_TypeDef *I2Cx)
  616. {
  617. SET_BIT(I2Cx->CR1, I2C_CR1_WUPEN);
  618. }
  619. /**
  620. * @brief Disable Wakeup from STOP.
  621. * @note Macro @ref IS_I2C_WAKEUP_FROMSTOP_INSTANCE(I2Cx) can be used to check whether or not
  622. * WakeUpFromStop feature is supported by the I2Cx Instance.
  623. * @rmtoll CR1 WUPEN LL_I2C_DisableWakeUpFromStop
  624. * @param I2Cx I2C Instance.
  625. * @retval None
  626. */
  627. __STATIC_INLINE void LL_I2C_DisableWakeUpFromStop(I2C_TypeDef *I2Cx)
  628. {
  629. CLEAR_BIT(I2Cx->CR1, I2C_CR1_WUPEN);
  630. }
  631. /**
  632. * @brief Check if Wakeup from STOP is enabled or disabled.
  633. * @note Macro @ref IS_I2C_WAKEUP_FROMSTOP_INSTANCE(I2Cx) can be used to check whether or not
  634. * WakeUpFromStop feature is supported by the I2Cx Instance.
  635. * @rmtoll CR1 WUPEN LL_I2C_IsEnabledWakeUpFromStop
  636. * @param I2Cx I2C Instance.
  637. * @retval State of bit (1 or 0).
  638. */
  639. __STATIC_INLINE uint32_t LL_I2C_IsEnabledWakeUpFromStop(I2C_TypeDef *I2Cx)
  640. {
  641. return (READ_BIT(I2Cx->CR1, I2C_CR1_WUPEN) == (I2C_CR1_WUPEN));
  642. }
  643. /**
  644. * @brief Enable General Call.
  645. * @note When enabled the Address 0x00 is ACKed.
  646. * @rmtoll CR1 GCEN LL_I2C_EnableGeneralCall
  647. * @param I2Cx I2C Instance.
  648. * @retval None
  649. */
  650. __STATIC_INLINE void LL_I2C_EnableGeneralCall(I2C_TypeDef *I2Cx)
  651. {
  652. SET_BIT(I2Cx->CR1, I2C_CR1_GCEN);
  653. }
  654. /**
  655. * @brief Disable General Call.
  656. * @note When disabled the Address 0x00 is NACKed.
  657. * @rmtoll CR1 GCEN LL_I2C_DisableGeneralCall
  658. * @param I2Cx I2C Instance.
  659. * @retval None
  660. */
  661. __STATIC_INLINE void LL_I2C_DisableGeneralCall(I2C_TypeDef *I2Cx)
  662. {
  663. CLEAR_BIT(I2Cx->CR1, I2C_CR1_GCEN);
  664. }
  665. /**
  666. * @brief Check if General Call is enabled or disabled.
  667. * @rmtoll CR1 GCEN LL_I2C_IsEnabledGeneralCall
  668. * @param I2Cx I2C Instance.
  669. * @retval State of bit (1 or 0).
  670. */
  671. __STATIC_INLINE uint32_t LL_I2C_IsEnabledGeneralCall(I2C_TypeDef *I2Cx)
  672. {
  673. return (READ_BIT(I2Cx->CR1, I2C_CR1_GCEN) == (I2C_CR1_GCEN));
  674. }
  675. /**
  676. * @brief Configure the Master to operate in 7-bit or 10-bit addressing mode.
  677. * @note Changing this bit is not allowed, when the START bit is set.
  678. * @rmtoll CR2 ADD10 LL_I2C_SetMasterAddressingMode
  679. * @param I2Cx I2C Instance.
  680. * @param AddressingMode This parameter can be one of the following values:
  681. * @arg @ref LL_I2C_ADDRESSING_MODE_7BIT
  682. * @arg @ref LL_I2C_ADDRESSING_MODE_10BIT
  683. * @retval None
  684. */
  685. __STATIC_INLINE void LL_I2C_SetMasterAddressingMode(I2C_TypeDef *I2Cx, uint32_t AddressingMode)
  686. {
  687. MODIFY_REG(I2Cx->CR2, I2C_CR2_ADD10, AddressingMode);
  688. }
  689. /**
  690. * @brief Get the Master addressing mode.
  691. * @rmtoll CR2 ADD10 LL_I2C_GetMasterAddressingMode
  692. * @param I2Cx I2C Instance.
  693. * @retval Returned value can be one of the following values:
  694. * @arg @ref LL_I2C_ADDRESSING_MODE_7BIT
  695. * @arg @ref LL_I2C_ADDRESSING_MODE_10BIT
  696. */
  697. __STATIC_INLINE uint32_t LL_I2C_GetMasterAddressingMode(I2C_TypeDef *I2Cx)
  698. {
  699. return (uint32_t)(READ_BIT(I2Cx->CR2, I2C_CR2_ADD10));
  700. }
  701. /**
  702. * @brief Set the Own Address1.
  703. * @rmtoll OAR1 OA1 LL_I2C_SetOwnAddress1\n
  704. * OAR1 OA1MODE LL_I2C_SetOwnAddress1
  705. * @param I2Cx I2C Instance.
  706. * @param OwnAddress1 This parameter must be a value between Min_Data=0 and Max_Data=0x3FF.
  707. * @param OwnAddrSize This parameter can be one of the following values:
  708. * @arg @ref LL_I2C_OWNADDRESS1_7BIT
  709. * @arg @ref LL_I2C_OWNADDRESS1_10BIT
  710. * @retval None
  711. */
  712. __STATIC_INLINE void LL_I2C_SetOwnAddress1(I2C_TypeDef *I2Cx, uint32_t OwnAddress1, uint32_t OwnAddrSize)
  713. {
  714. MODIFY_REG(I2Cx->OAR1, I2C_OAR1_OA1 | I2C_OAR1_OA1MODE, OwnAddress1 | OwnAddrSize);
  715. }
  716. /**
  717. * @brief Enable acknowledge on Own Address1 match address.
  718. * @rmtoll OAR1 OA1EN LL_I2C_EnableOwnAddress1
  719. * @param I2Cx I2C Instance.
  720. * @retval None
  721. */
  722. __STATIC_INLINE void LL_I2C_EnableOwnAddress1(I2C_TypeDef *I2Cx)
  723. {
  724. SET_BIT(I2Cx->OAR1, I2C_OAR1_OA1EN);
  725. }
  726. /**
  727. * @brief Disable acknowledge on Own Address1 match address.
  728. * @rmtoll OAR1 OA1EN LL_I2C_DisableOwnAddress1
  729. * @param I2Cx I2C Instance.
  730. * @retval None
  731. */
  732. __STATIC_INLINE void LL_I2C_DisableOwnAddress1(I2C_TypeDef *I2Cx)
  733. {
  734. CLEAR_BIT(I2Cx->OAR1, I2C_OAR1_OA1EN);
  735. }
  736. /**
  737. * @brief Check if Own Address1 acknowledge is enabled or disabled.
  738. * @rmtoll OAR1 OA1EN LL_I2C_IsEnabledOwnAddress1
  739. * @param I2Cx I2C Instance.
  740. * @retval State of bit (1 or 0).
  741. */
  742. __STATIC_INLINE uint32_t LL_I2C_IsEnabledOwnAddress1(I2C_TypeDef *I2Cx)
  743. {
  744. return (READ_BIT(I2Cx->OAR1, I2C_OAR1_OA1EN) == (I2C_OAR1_OA1EN));
  745. }
  746. /**
  747. * @brief Set the 7bits Own Address2.
  748. * @note This action has no effect if own address2 is enabled.
  749. * @rmtoll OAR2 OA2 LL_I2C_SetOwnAddress2\n
  750. * OAR2 OA2MSK LL_I2C_SetOwnAddress2
  751. * @param I2Cx I2C Instance.
  752. * @param OwnAddress2 Value between Min_Data=0 and Max_Data=0x7F.
  753. * @param OwnAddrMask This parameter can be one of the following values:
  754. * @arg @ref LL_I2C_OWNADDRESS2_NOMASK
  755. * @arg @ref LL_I2C_OWNADDRESS2_MASK01
  756. * @arg @ref LL_I2C_OWNADDRESS2_MASK02
  757. * @arg @ref LL_I2C_OWNADDRESS2_MASK03
  758. * @arg @ref LL_I2C_OWNADDRESS2_MASK04
  759. * @arg @ref LL_I2C_OWNADDRESS2_MASK05
  760. * @arg @ref LL_I2C_OWNADDRESS2_MASK06
  761. * @arg @ref LL_I2C_OWNADDRESS2_MASK07
  762. * @retval None
  763. */
  764. __STATIC_INLINE void LL_I2C_SetOwnAddress2(I2C_TypeDef *I2Cx, uint32_t OwnAddress2, uint32_t OwnAddrMask)
  765. {
  766. MODIFY_REG(I2Cx->OAR2, I2C_OAR2_OA2 | I2C_OAR2_OA2MSK, OwnAddress2 | OwnAddrMask);
  767. }
  768. /**
  769. * @brief Enable acknowledge on Own Address2 match address.
  770. * @rmtoll OAR2 OA2EN LL_I2C_EnableOwnAddress2
  771. * @param I2Cx I2C Instance.
  772. * @retval None
  773. */
  774. __STATIC_INLINE void LL_I2C_EnableOwnAddress2(I2C_TypeDef *I2Cx)
  775. {
  776. SET_BIT(I2Cx->OAR2, I2C_OAR2_OA2EN);
  777. }
  778. /**
  779. * @brief Disable acknowledge on Own Address2 match address.
  780. * @rmtoll OAR2 OA2EN LL_I2C_DisableOwnAddress2
  781. * @param I2Cx I2C Instance.
  782. * @retval None
  783. */
  784. __STATIC_INLINE void LL_I2C_DisableOwnAddress2(I2C_TypeDef *I2Cx)
  785. {
  786. CLEAR_BIT(I2Cx->OAR2, I2C_OAR2_OA2EN);
  787. }
  788. /**
  789. * @brief Check if Own Address1 acknowledge is enabled or disabled.
  790. * @rmtoll OAR2 OA2EN LL_I2C_IsEnabledOwnAddress2
  791. * @param I2Cx I2C Instance.
  792. * @retval State of bit (1 or 0).
  793. */
  794. __STATIC_INLINE uint32_t LL_I2C_IsEnabledOwnAddress2(I2C_TypeDef *I2Cx)
  795. {
  796. return (READ_BIT(I2Cx->OAR2, I2C_OAR2_OA2EN) == (I2C_OAR2_OA2EN));
  797. }
  798. /**
  799. * @brief Configure the SDA setup, hold time and the SCL high, low period.
  800. * @note This bit can only be programmed when the I2C is disabled (PE = 0).
  801. * @rmtoll TIMINGR TIMINGR LL_I2C_SetTiming
  802. * @param I2Cx I2C Instance.
  803. * @param Timing This parameter must be a value between Min_Data=0 and Max_Data=0xFFFFFFFF.
  804. * @note This parameter is computed with the STM32CubeMX Tool.
  805. * @retval None
  806. */
  807. __STATIC_INLINE void LL_I2C_SetTiming(I2C_TypeDef *I2Cx, uint32_t Timing)
  808. {
  809. WRITE_REG(I2Cx->TIMINGR, Timing);
  810. }
  811. /**
  812. * @brief Get the Timing Prescaler setting.
  813. * @rmtoll TIMINGR PRESC LL_I2C_GetTimingPrescaler
  814. * @param I2Cx I2C Instance.
  815. * @retval Value between Min_Data=0x0 and Max_Data=0xF
  816. */
  817. __STATIC_INLINE uint32_t LL_I2C_GetTimingPrescaler(I2C_TypeDef *I2Cx)
  818. {
  819. return (uint32_t)(READ_BIT(I2Cx->TIMINGR, I2C_TIMINGR_PRESC) >> I2C_TIMINGR_PRESC_Pos);
  820. }
  821. /**
  822. * @brief Get the SCL low period setting.
  823. * @rmtoll TIMINGR SCLL LL_I2C_GetClockLowPeriod
  824. * @param I2Cx I2C Instance.
  825. * @retval Value between Min_Data=0x00 and Max_Data=0xFF
  826. */
  827. __STATIC_INLINE uint32_t LL_I2C_GetClockLowPeriod(I2C_TypeDef *I2Cx)
  828. {
  829. return (uint32_t)(READ_BIT(I2Cx->TIMINGR, I2C_TIMINGR_SCLL) >> I2C_TIMINGR_SCLL_Pos);
  830. }
  831. /**
  832. * @brief Get the SCL high period setting.
  833. * @rmtoll TIMINGR SCLH LL_I2C_GetClockHighPeriod
  834. * @param I2Cx I2C Instance.
  835. * @retval Value between Min_Data=0x00 and Max_Data=0xFF
  836. */
  837. __STATIC_INLINE uint32_t LL_I2C_GetClockHighPeriod(I2C_TypeDef *I2Cx)
  838. {
  839. return (uint32_t)(READ_BIT(I2Cx->TIMINGR, I2C_TIMINGR_SCLH) >> I2C_TIMINGR_SCLH_Pos);
  840. }
  841. /**
  842. * @brief Get the SDA hold time.
  843. * @rmtoll TIMINGR SDADEL LL_I2C_GetDataHoldTime
  844. * @param I2Cx I2C Instance.
  845. * @retval Value between Min_Data=0x0 and Max_Data=0xF
  846. */
  847. __STATIC_INLINE uint32_t LL_I2C_GetDataHoldTime(I2C_TypeDef *I2Cx)
  848. {
  849. return (uint32_t)(READ_BIT(I2Cx->TIMINGR, I2C_TIMINGR_SDADEL) >> I2C_TIMINGR_SDADEL_Pos);
  850. }
  851. /**
  852. * @brief Get the SDA setup time.
  853. * @rmtoll TIMINGR SCLDEL LL_I2C_GetDataSetupTime
  854. * @param I2Cx I2C Instance.
  855. * @retval Value between Min_Data=0x0 and Max_Data=0xF
  856. */
  857. __STATIC_INLINE uint32_t LL_I2C_GetDataSetupTime(I2C_TypeDef *I2Cx)
  858. {
  859. return (uint32_t)(READ_BIT(I2Cx->TIMINGR, I2C_TIMINGR_SCLDEL) >> I2C_TIMINGR_SCLDEL_Pos);
  860. }
  861. /**
  862. * @brief Configure peripheral mode.
  863. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  864. * SMBus feature is supported by the I2Cx Instance.
  865. * @rmtoll CR1 SMBHEN LL_I2C_SetMode\n
  866. * CR1 SMBDEN LL_I2C_SetMode
  867. * @param I2Cx I2C Instance.
  868. * @param PeripheralMode This parameter can be one of the following values:
  869. * @arg @ref LL_I2C_MODE_I2C
  870. * @arg @ref LL_I2C_MODE_SMBUS_HOST
  871. * @arg @ref LL_I2C_MODE_SMBUS_DEVICE
  872. * @arg @ref LL_I2C_MODE_SMBUS_DEVICE_ARP
  873. * @retval None
  874. */
  875. __STATIC_INLINE void LL_I2C_SetMode(I2C_TypeDef *I2Cx, uint32_t PeripheralMode)
  876. {
  877. MODIFY_REG(I2Cx->CR1, I2C_CR1_SMBHEN | I2C_CR1_SMBDEN, PeripheralMode);
  878. }
  879. /**
  880. * @brief Get peripheral mode.
  881. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  882. * SMBus feature is supported by the I2Cx Instance.
  883. * @rmtoll CR1 SMBHEN LL_I2C_GetMode\n
  884. * CR1 SMBDEN LL_I2C_GetMode
  885. * @param I2Cx I2C Instance.
  886. * @retval Returned value can be one of the following values:
  887. * @arg @ref LL_I2C_MODE_I2C
  888. * @arg @ref LL_I2C_MODE_SMBUS_HOST
  889. * @arg @ref LL_I2C_MODE_SMBUS_DEVICE
  890. * @arg @ref LL_I2C_MODE_SMBUS_DEVICE_ARP
  891. */
  892. __STATIC_INLINE uint32_t LL_I2C_GetMode(I2C_TypeDef *I2Cx)
  893. {
  894. return (uint32_t)(READ_BIT(I2Cx->CR1, I2C_CR1_SMBHEN | I2C_CR1_SMBDEN));
  895. }
  896. /**
  897. * @brief Enable SMBus alert (Host or Device mode)
  898. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  899. * SMBus feature is supported by the I2Cx Instance.
  900. * @note SMBus Device mode:
  901. * - SMBus Alert pin is drived low and
  902. * Alert Response Address Header acknowledge is enabled.
  903. * SMBus Host mode:
  904. * - SMBus Alert pin management is supported.
  905. * @rmtoll CR1 ALERTEN LL_I2C_EnableSMBusAlert
  906. * @param I2Cx I2C Instance.
  907. * @retval None
  908. */
  909. __STATIC_INLINE void LL_I2C_EnableSMBusAlert(I2C_TypeDef *I2Cx)
  910. {
  911. SET_BIT(I2Cx->CR1, I2C_CR1_ALERTEN);
  912. }
  913. /**
  914. * @brief Disable SMBus alert (Host or Device mode)
  915. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  916. * SMBus feature is supported by the I2Cx Instance.
  917. * @note SMBus Device mode:
  918. * - SMBus Alert pin is not drived (can be used as a standard GPIO) and
  919. * Alert Response Address Header acknowledge is disabled.
  920. * SMBus Host mode:
  921. * - SMBus Alert pin management is not supported.
  922. * @rmtoll CR1 ALERTEN LL_I2C_DisableSMBusAlert
  923. * @param I2Cx I2C Instance.
  924. * @retval None
  925. */
  926. __STATIC_INLINE void LL_I2C_DisableSMBusAlert(I2C_TypeDef *I2Cx)
  927. {
  928. CLEAR_BIT(I2Cx->CR1, I2C_CR1_ALERTEN);
  929. }
  930. /**
  931. * @brief Check if SMBus alert (Host or Device mode) is enabled or disabled.
  932. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  933. * SMBus feature is supported by the I2Cx Instance.
  934. * @rmtoll CR1 ALERTEN LL_I2C_IsEnabledSMBusAlert
  935. * @param I2Cx I2C Instance.
  936. * @retval State of bit (1 or 0).
  937. */
  938. __STATIC_INLINE uint32_t LL_I2C_IsEnabledSMBusAlert(I2C_TypeDef *I2Cx)
  939. {
  940. return (READ_BIT(I2Cx->CR1, I2C_CR1_ALERTEN) == (I2C_CR1_ALERTEN));
  941. }
  942. /**
  943. * @brief Enable SMBus Packet Error Calculation (PEC).
  944. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  945. * SMBus feature is supported by the I2Cx Instance.
  946. * @rmtoll CR1 PECEN LL_I2C_EnableSMBusPEC
  947. * @param I2Cx I2C Instance.
  948. * @retval None
  949. */
  950. __STATIC_INLINE void LL_I2C_EnableSMBusPEC(I2C_TypeDef *I2Cx)
  951. {
  952. SET_BIT(I2Cx->CR1, I2C_CR1_PECEN);
  953. }
  954. /**
  955. * @brief Disable SMBus Packet Error Calculation (PEC).
  956. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  957. * SMBus feature is supported by the I2Cx Instance.
  958. * @rmtoll CR1 PECEN LL_I2C_DisableSMBusPEC
  959. * @param I2Cx I2C Instance.
  960. * @retval None
  961. */
  962. __STATIC_INLINE void LL_I2C_DisableSMBusPEC(I2C_TypeDef *I2Cx)
  963. {
  964. CLEAR_BIT(I2Cx->CR1, I2C_CR1_PECEN);
  965. }
  966. /**
  967. * @brief Check if SMBus Packet Error Calculation (PEC) is enabled or disabled.
  968. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  969. * SMBus feature is supported by the I2Cx Instance.
  970. * @rmtoll CR1 PECEN LL_I2C_IsEnabledSMBusPEC
  971. * @param I2Cx I2C Instance.
  972. * @retval State of bit (1 or 0).
  973. */
  974. __STATIC_INLINE uint32_t LL_I2C_IsEnabledSMBusPEC(I2C_TypeDef *I2Cx)
  975. {
  976. return (READ_BIT(I2Cx->CR1, I2C_CR1_PECEN) == (I2C_CR1_PECEN));
  977. }
  978. /**
  979. * @brief Configure the SMBus Clock Timeout.
  980. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  981. * SMBus feature is supported by the I2Cx Instance.
  982. * @note This configuration can only be programmed when associated Timeout is disabled (TimeoutA and/orTimeoutB).
  983. * @rmtoll TIMEOUTR TIMEOUTA LL_I2C_ConfigSMBusTimeout\n
  984. * TIMEOUTR TIDLE LL_I2C_ConfigSMBusTimeout\n
  985. * TIMEOUTR TIMEOUTB LL_I2C_ConfigSMBusTimeout
  986. * @param I2Cx I2C Instance.
  987. * @param TimeoutA This parameter must be a value between Min_Data=0 and Max_Data=0xFFF.
  988. * @param TimeoutAMode This parameter can be one of the following values:
  989. * @arg @ref LL_I2C_SMBUS_TIMEOUTA_MODE_SCL_LOW
  990. * @arg @ref LL_I2C_SMBUS_TIMEOUTA_MODE_SDA_SCL_HIGH
  991. * @param TimeoutB
  992. * @retval None
  993. */
  994. __STATIC_INLINE void LL_I2C_ConfigSMBusTimeout(I2C_TypeDef *I2Cx, uint32_t TimeoutA, uint32_t TimeoutAMode,
  995. uint32_t TimeoutB)
  996. {
  997. MODIFY_REG(I2Cx->TIMEOUTR, I2C_TIMEOUTR_TIMEOUTA | I2C_TIMEOUTR_TIDLE | I2C_TIMEOUTR_TIMEOUTB,
  998. TimeoutA | TimeoutAMode | (TimeoutB << I2C_TIMEOUTR_TIMEOUTB_Pos));
  999. }
  1000. /**
  1001. * @brief Configure the SMBus Clock TimeoutA (SCL low timeout or SCL and SDA high timeout depends on TimeoutA mode).
  1002. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1003. * SMBus feature is supported by the I2Cx Instance.
  1004. * @note These bits can only be programmed when TimeoutA is disabled.
  1005. * @rmtoll TIMEOUTR TIMEOUTA LL_I2C_SetSMBusTimeoutA
  1006. * @param I2Cx I2C Instance.
  1007. * @param TimeoutA This parameter must be a value between Min_Data=0 and Max_Data=0xFFF.
  1008. * @retval None
  1009. */
  1010. __STATIC_INLINE void LL_I2C_SetSMBusTimeoutA(I2C_TypeDef *I2Cx, uint32_t TimeoutA)
  1011. {
  1012. WRITE_REG(I2Cx->TIMEOUTR, TimeoutA);
  1013. }
  1014. /**
  1015. * @brief Get the SMBus Clock TimeoutA setting.
  1016. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1017. * SMBus feature is supported by the I2Cx Instance.
  1018. * @rmtoll TIMEOUTR TIMEOUTA LL_I2C_GetSMBusTimeoutA
  1019. * @param I2Cx I2C Instance.
  1020. * @retval Value between Min_Data=0 and Max_Data=0xFFF
  1021. */
  1022. __STATIC_INLINE uint32_t LL_I2C_GetSMBusTimeoutA(I2C_TypeDef *I2Cx)
  1023. {
  1024. return (uint32_t)(READ_BIT(I2Cx->TIMEOUTR, I2C_TIMEOUTR_TIMEOUTA));
  1025. }
  1026. /**
  1027. * @brief Set the SMBus Clock TimeoutA mode.
  1028. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1029. * SMBus feature is supported by the I2Cx Instance.
  1030. * @note This bit can only be programmed when TimeoutA is disabled.
  1031. * @rmtoll TIMEOUTR TIDLE LL_I2C_SetSMBusTimeoutAMode
  1032. * @param I2Cx I2C Instance.
  1033. * @param TimeoutAMode This parameter can be one of the following values:
  1034. * @arg @ref LL_I2C_SMBUS_TIMEOUTA_MODE_SCL_LOW
  1035. * @arg @ref LL_I2C_SMBUS_TIMEOUTA_MODE_SDA_SCL_HIGH
  1036. * @retval None
  1037. */
  1038. __STATIC_INLINE void LL_I2C_SetSMBusTimeoutAMode(I2C_TypeDef *I2Cx, uint32_t TimeoutAMode)
  1039. {
  1040. WRITE_REG(I2Cx->TIMEOUTR, TimeoutAMode);
  1041. }
  1042. /**
  1043. * @brief Get the SMBus Clock TimeoutA mode.
  1044. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1045. * SMBus feature is supported by the I2Cx Instance.
  1046. * @rmtoll TIMEOUTR TIDLE LL_I2C_GetSMBusTimeoutAMode
  1047. * @param I2Cx I2C Instance.
  1048. * @retval Returned value can be one of the following values:
  1049. * @arg @ref LL_I2C_SMBUS_TIMEOUTA_MODE_SCL_LOW
  1050. * @arg @ref LL_I2C_SMBUS_TIMEOUTA_MODE_SDA_SCL_HIGH
  1051. */
  1052. __STATIC_INLINE uint32_t LL_I2C_GetSMBusTimeoutAMode(I2C_TypeDef *I2Cx)
  1053. {
  1054. return (uint32_t)(READ_BIT(I2Cx->TIMEOUTR, I2C_TIMEOUTR_TIDLE));
  1055. }
  1056. /**
  1057. * @brief Configure the SMBus Extended Cumulative Clock TimeoutB (Master or Slave mode).
  1058. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1059. * SMBus feature is supported by the I2Cx Instance.
  1060. * @note These bits can only be programmed when TimeoutB is disabled.
  1061. * @rmtoll TIMEOUTR TIMEOUTB LL_I2C_SetSMBusTimeoutB
  1062. * @param I2Cx I2C Instance.
  1063. * @param TimeoutB This parameter must be a value between Min_Data=0 and Max_Data=0xFFF.
  1064. * @retval None
  1065. */
  1066. __STATIC_INLINE void LL_I2C_SetSMBusTimeoutB(I2C_TypeDef *I2Cx, uint32_t TimeoutB)
  1067. {
  1068. WRITE_REG(I2Cx->TIMEOUTR, TimeoutB << I2C_TIMEOUTR_TIMEOUTB_Pos);
  1069. }
  1070. /**
  1071. * @brief Get the SMBus Extented Cumulative Clock TimeoutB setting.
  1072. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1073. * SMBus feature is supported by the I2Cx Instance.
  1074. * @rmtoll TIMEOUTR TIMEOUTB LL_I2C_GetSMBusTimeoutB
  1075. * @param I2Cx I2C Instance.
  1076. * @retval Value between Min_Data=0 and Max_Data=0xFFF
  1077. */
  1078. __STATIC_INLINE uint32_t LL_I2C_GetSMBusTimeoutB(I2C_TypeDef *I2Cx)
  1079. {
  1080. return (uint32_t)(READ_BIT(I2Cx->TIMEOUTR, I2C_TIMEOUTR_TIMEOUTB) >> I2C_TIMEOUTR_TIMEOUTB_Pos);
  1081. }
  1082. /**
  1083. * @brief Enable the SMBus Clock Timeout.
  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. * @rmtoll TIMEOUTR TIMOUTEN LL_I2C_EnableSMBusTimeout\n
  1087. * TIMEOUTR TEXTEN LL_I2C_EnableSMBusTimeout
  1088. * @param I2Cx I2C Instance.
  1089. * @param ClockTimeout This parameter can be one of the following values:
  1090. * @arg @ref LL_I2C_SMBUS_TIMEOUTA
  1091. * @arg @ref LL_I2C_SMBUS_TIMEOUTB
  1092. * @arg @ref LL_I2C_SMBUS_ALL_TIMEOUT
  1093. * @retval None
  1094. */
  1095. __STATIC_INLINE void LL_I2C_EnableSMBusTimeout(I2C_TypeDef *I2Cx, uint32_t ClockTimeout)
  1096. {
  1097. SET_BIT(I2Cx->TIMEOUTR, ClockTimeout);
  1098. }
  1099. /**
  1100. * @brief Disable the SMBus Clock Timeout.
  1101. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1102. * SMBus feature is supported by the I2Cx Instance.
  1103. * @rmtoll TIMEOUTR TIMOUTEN LL_I2C_DisableSMBusTimeout\n
  1104. * TIMEOUTR TEXTEN LL_I2C_DisableSMBusTimeout
  1105. * @param I2Cx I2C Instance.
  1106. * @param ClockTimeout This parameter can be one of the following values:
  1107. * @arg @ref LL_I2C_SMBUS_TIMEOUTA
  1108. * @arg @ref LL_I2C_SMBUS_TIMEOUTB
  1109. * @arg @ref LL_I2C_SMBUS_ALL_TIMEOUT
  1110. * @retval None
  1111. */
  1112. __STATIC_INLINE void LL_I2C_DisableSMBusTimeout(I2C_TypeDef *I2Cx, uint32_t ClockTimeout)
  1113. {
  1114. CLEAR_BIT(I2Cx->TIMEOUTR, ClockTimeout);
  1115. }
  1116. /**
  1117. * @brief Check if the SMBus Clock Timeout is enabled or disabled.
  1118. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1119. * SMBus feature is supported by the I2Cx Instance.
  1120. * @rmtoll TIMEOUTR TIMOUTEN LL_I2C_IsEnabledSMBusTimeout\n
  1121. * TIMEOUTR TEXTEN LL_I2C_IsEnabledSMBusTimeout
  1122. * @param I2Cx I2C Instance.
  1123. * @param ClockTimeout This parameter can be one of the following values:
  1124. * @arg @ref LL_I2C_SMBUS_TIMEOUTA
  1125. * @arg @ref LL_I2C_SMBUS_TIMEOUTB
  1126. * @arg @ref LL_I2C_SMBUS_ALL_TIMEOUT
  1127. * @retval State of bit (1 or 0).
  1128. */
  1129. __STATIC_INLINE uint32_t LL_I2C_IsEnabledSMBusTimeout(I2C_TypeDef *I2Cx, uint32_t ClockTimeout)
  1130. {
  1131. return (READ_BIT(I2Cx->TIMEOUTR, (I2C_TIMEOUTR_TIMOUTEN | I2C_TIMEOUTR_TEXTEN)) == (ClockTimeout));
  1132. }
  1133. /**
  1134. * @}
  1135. */
  1136. /** @defgroup I2C_LL_EF_IT_Management IT_Management
  1137. * @{
  1138. */
  1139. /**
  1140. * @brief Enable TXIS interrupt.
  1141. * @rmtoll CR1 TXIE LL_I2C_EnableIT_TX
  1142. * @param I2Cx I2C Instance.
  1143. * @retval None
  1144. */
  1145. __STATIC_INLINE void LL_I2C_EnableIT_TX(I2C_TypeDef *I2Cx)
  1146. {
  1147. SET_BIT(I2Cx->CR1, I2C_CR1_TXIE);
  1148. }
  1149. /**
  1150. * @brief Disable TXIS interrupt.
  1151. * @rmtoll CR1 TXIE LL_I2C_DisableIT_TX
  1152. * @param I2Cx I2C Instance.
  1153. * @retval None
  1154. */
  1155. __STATIC_INLINE void LL_I2C_DisableIT_TX(I2C_TypeDef *I2Cx)
  1156. {
  1157. CLEAR_BIT(I2Cx->CR1, I2C_CR1_TXIE);
  1158. }
  1159. /**
  1160. * @brief Check if the TXIS Interrupt is enabled or disabled.
  1161. * @rmtoll CR1 TXIE LL_I2C_IsEnabledIT_TX
  1162. * @param I2Cx I2C Instance.
  1163. * @retval State of bit (1 or 0).
  1164. */
  1165. __STATIC_INLINE uint32_t LL_I2C_IsEnabledIT_TX(I2C_TypeDef *I2Cx)
  1166. {
  1167. return (READ_BIT(I2Cx->CR1, I2C_CR1_TXIE) == (I2C_CR1_TXIE));
  1168. }
  1169. /**
  1170. * @brief Enable RXNE interrupt.
  1171. * @rmtoll CR1 RXIE LL_I2C_EnableIT_RX
  1172. * @param I2Cx I2C Instance.
  1173. * @retval None
  1174. */
  1175. __STATIC_INLINE void LL_I2C_EnableIT_RX(I2C_TypeDef *I2Cx)
  1176. {
  1177. SET_BIT(I2Cx->CR1, I2C_CR1_RXIE);
  1178. }
  1179. /**
  1180. * @brief Disable RXNE interrupt.
  1181. * @rmtoll CR1 RXIE LL_I2C_DisableIT_RX
  1182. * @param I2Cx I2C Instance.
  1183. * @retval None
  1184. */
  1185. __STATIC_INLINE void LL_I2C_DisableIT_RX(I2C_TypeDef *I2Cx)
  1186. {
  1187. CLEAR_BIT(I2Cx->CR1, I2C_CR1_RXIE);
  1188. }
  1189. /**
  1190. * @brief Check if the RXNE Interrupt is enabled or disabled.
  1191. * @rmtoll CR1 RXIE LL_I2C_IsEnabledIT_RX
  1192. * @param I2Cx I2C Instance.
  1193. * @retval State of bit (1 or 0).
  1194. */
  1195. __STATIC_INLINE uint32_t LL_I2C_IsEnabledIT_RX(I2C_TypeDef *I2Cx)
  1196. {
  1197. return (READ_BIT(I2Cx->CR1, I2C_CR1_RXIE) == (I2C_CR1_RXIE));
  1198. }
  1199. /**
  1200. * @brief Enable Address match interrupt (slave mode only).
  1201. * @rmtoll CR1 ADDRIE LL_I2C_EnableIT_ADDR
  1202. * @param I2Cx I2C Instance.
  1203. * @retval None
  1204. */
  1205. __STATIC_INLINE void LL_I2C_EnableIT_ADDR(I2C_TypeDef *I2Cx)
  1206. {
  1207. SET_BIT(I2Cx->CR1, I2C_CR1_ADDRIE);
  1208. }
  1209. /**
  1210. * @brief Disable Address match interrupt (slave mode only).
  1211. * @rmtoll CR1 ADDRIE LL_I2C_DisableIT_ADDR
  1212. * @param I2Cx I2C Instance.
  1213. * @retval None
  1214. */
  1215. __STATIC_INLINE void LL_I2C_DisableIT_ADDR(I2C_TypeDef *I2Cx)
  1216. {
  1217. CLEAR_BIT(I2Cx->CR1, I2C_CR1_ADDRIE);
  1218. }
  1219. /**
  1220. * @brief Check if Address match interrupt is enabled or disabled.
  1221. * @rmtoll CR1 ADDRIE LL_I2C_IsEnabledIT_ADDR
  1222. * @param I2Cx I2C Instance.
  1223. * @retval State of bit (1 or 0).
  1224. */
  1225. __STATIC_INLINE uint32_t LL_I2C_IsEnabledIT_ADDR(I2C_TypeDef *I2Cx)
  1226. {
  1227. return (READ_BIT(I2Cx->CR1, I2C_CR1_ADDRIE) == (I2C_CR1_ADDRIE));
  1228. }
  1229. /**
  1230. * @brief Enable Not acknowledge received interrupt.
  1231. * @rmtoll CR1 NACKIE LL_I2C_EnableIT_NACK
  1232. * @param I2Cx I2C Instance.
  1233. * @retval None
  1234. */
  1235. __STATIC_INLINE void LL_I2C_EnableIT_NACK(I2C_TypeDef *I2Cx)
  1236. {
  1237. SET_BIT(I2Cx->CR1, I2C_CR1_NACKIE);
  1238. }
  1239. /**
  1240. * @brief Disable Not acknowledge received interrupt.
  1241. * @rmtoll CR1 NACKIE LL_I2C_DisableIT_NACK
  1242. * @param I2Cx I2C Instance.
  1243. * @retval None
  1244. */
  1245. __STATIC_INLINE void LL_I2C_DisableIT_NACK(I2C_TypeDef *I2Cx)
  1246. {
  1247. CLEAR_BIT(I2Cx->CR1, I2C_CR1_NACKIE);
  1248. }
  1249. /**
  1250. * @brief Check if Not acknowledge received interrupt is enabled or disabled.
  1251. * @rmtoll CR1 NACKIE LL_I2C_IsEnabledIT_NACK
  1252. * @param I2Cx I2C Instance.
  1253. * @retval State of bit (1 or 0).
  1254. */
  1255. __STATIC_INLINE uint32_t LL_I2C_IsEnabledIT_NACK(I2C_TypeDef *I2Cx)
  1256. {
  1257. return (READ_BIT(I2Cx->CR1, I2C_CR1_NACKIE) == (I2C_CR1_NACKIE));
  1258. }
  1259. /**
  1260. * @brief Enable STOP detection interrupt.
  1261. * @rmtoll CR1 STOPIE LL_I2C_EnableIT_STOP
  1262. * @param I2Cx I2C Instance.
  1263. * @retval None
  1264. */
  1265. __STATIC_INLINE void LL_I2C_EnableIT_STOP(I2C_TypeDef *I2Cx)
  1266. {
  1267. SET_BIT(I2Cx->CR1, I2C_CR1_STOPIE);
  1268. }
  1269. /**
  1270. * @brief Disable STOP detection interrupt.
  1271. * @rmtoll CR1 STOPIE LL_I2C_DisableIT_STOP
  1272. * @param I2Cx I2C Instance.
  1273. * @retval None
  1274. */
  1275. __STATIC_INLINE void LL_I2C_DisableIT_STOP(I2C_TypeDef *I2Cx)
  1276. {
  1277. CLEAR_BIT(I2Cx->CR1, I2C_CR1_STOPIE);
  1278. }
  1279. /**
  1280. * @brief Check if STOP detection interrupt is enabled or disabled.
  1281. * @rmtoll CR1 STOPIE LL_I2C_IsEnabledIT_STOP
  1282. * @param I2Cx I2C Instance.
  1283. * @retval State of bit (1 or 0).
  1284. */
  1285. __STATIC_INLINE uint32_t LL_I2C_IsEnabledIT_STOP(I2C_TypeDef *I2Cx)
  1286. {
  1287. return (READ_BIT(I2Cx->CR1, I2C_CR1_STOPIE) == (I2C_CR1_STOPIE));
  1288. }
  1289. /**
  1290. * @brief Enable Transfer Complete interrupt.
  1291. * @note Any of these events will generate interrupt :
  1292. * Transfer Complete (TC)
  1293. * Transfer Complete Reload (TCR)
  1294. * @rmtoll CR1 TCIE LL_I2C_EnableIT_TC
  1295. * @param I2Cx I2C Instance.
  1296. * @retval None
  1297. */
  1298. __STATIC_INLINE void LL_I2C_EnableIT_TC(I2C_TypeDef *I2Cx)
  1299. {
  1300. SET_BIT(I2Cx->CR1, I2C_CR1_TCIE);
  1301. }
  1302. /**
  1303. * @brief Disable Transfer Complete interrupt.
  1304. * @note Any of these events will generate interrupt :
  1305. * Transfer Complete (TC)
  1306. * Transfer Complete Reload (TCR)
  1307. * @rmtoll CR1 TCIE LL_I2C_DisableIT_TC
  1308. * @param I2Cx I2C Instance.
  1309. * @retval None
  1310. */
  1311. __STATIC_INLINE void LL_I2C_DisableIT_TC(I2C_TypeDef *I2Cx)
  1312. {
  1313. CLEAR_BIT(I2Cx->CR1, I2C_CR1_TCIE);
  1314. }
  1315. /**
  1316. * @brief Check if Transfer Complete interrupt is enabled or disabled.
  1317. * @rmtoll CR1 TCIE LL_I2C_IsEnabledIT_TC
  1318. * @param I2Cx I2C Instance.
  1319. * @retval State of bit (1 or 0).
  1320. */
  1321. __STATIC_INLINE uint32_t LL_I2C_IsEnabledIT_TC(I2C_TypeDef *I2Cx)
  1322. {
  1323. return (READ_BIT(I2Cx->CR1, I2C_CR1_TCIE) == (I2C_CR1_TCIE));
  1324. }
  1325. /**
  1326. * @brief Enable Error interrupts.
  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 Any of these errors will generate interrupt :
  1330. * Arbitration Loss (ARLO)
  1331. * Bus Error detection (BERR)
  1332. * Overrun/Underrun (OVR)
  1333. * SMBus Timeout detection (TIMEOUT)
  1334. * SMBus PEC error detection (PECERR)
  1335. * SMBus Alert pin event detection (ALERT)
  1336. * @rmtoll CR1 ERRIE LL_I2C_EnableIT_ERR
  1337. * @param I2Cx I2C Instance.
  1338. * @retval None
  1339. */
  1340. __STATIC_INLINE void LL_I2C_EnableIT_ERR(I2C_TypeDef *I2Cx)
  1341. {
  1342. SET_BIT(I2Cx->CR1, I2C_CR1_ERRIE);
  1343. }
  1344. /**
  1345. * @brief Disable Error interrupts.
  1346. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1347. * SMBus feature is supported by the I2Cx Instance.
  1348. * @note Any of these errors will generate interrupt :
  1349. * Arbitration Loss (ARLO)
  1350. * Bus Error detection (BERR)
  1351. * Overrun/Underrun (OVR)
  1352. * SMBus Timeout detection (TIMEOUT)
  1353. * SMBus PEC error detection (PECERR)
  1354. * SMBus Alert pin event detection (ALERT)
  1355. * @rmtoll CR1 ERRIE LL_I2C_DisableIT_ERR
  1356. * @param I2Cx I2C Instance.
  1357. * @retval None
  1358. */
  1359. __STATIC_INLINE void LL_I2C_DisableIT_ERR(I2C_TypeDef *I2Cx)
  1360. {
  1361. CLEAR_BIT(I2Cx->CR1, I2C_CR1_ERRIE);
  1362. }
  1363. /**
  1364. * @brief Check if Error interrupts are enabled or disabled.
  1365. * @rmtoll CR1 ERRIE LL_I2C_IsEnabledIT_ERR
  1366. * @param I2Cx I2C Instance.
  1367. * @retval State of bit (1 or 0).
  1368. */
  1369. __STATIC_INLINE uint32_t LL_I2C_IsEnabledIT_ERR(I2C_TypeDef *I2Cx)
  1370. {
  1371. return (READ_BIT(I2Cx->CR1, I2C_CR1_ERRIE) == (I2C_CR1_ERRIE));
  1372. }
  1373. /**
  1374. * @}
  1375. */
  1376. /** @defgroup I2C_LL_EF_FLAG_management FLAG_management
  1377. * @{
  1378. */
  1379. /**
  1380. * @brief Indicate the status of Transmit data register empty flag.
  1381. * @note RESET: When next data is written in Transmit data register.
  1382. * SET: When Transmit data register is empty.
  1383. * @rmtoll ISR TXE LL_I2C_IsActiveFlag_TXE
  1384. * @param I2Cx I2C Instance.
  1385. * @retval State of bit (1 or 0).
  1386. */
  1387. __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_TXE(I2C_TypeDef *I2Cx)
  1388. {
  1389. return (READ_BIT(I2Cx->ISR, I2C_ISR_TXE) == (I2C_ISR_TXE));
  1390. }
  1391. /**
  1392. * @brief Indicate the status of Transmit interrupt flag.
  1393. * @note RESET: When next data is written in Transmit data register.
  1394. * SET: When Transmit data register is empty.
  1395. * @rmtoll ISR TXIS LL_I2C_IsActiveFlag_TXIS
  1396. * @param I2Cx I2C Instance.
  1397. * @retval State of bit (1 or 0).
  1398. */
  1399. __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_TXIS(I2C_TypeDef *I2Cx)
  1400. {
  1401. return (READ_BIT(I2Cx->ISR, I2C_ISR_TXIS) == (I2C_ISR_TXIS));
  1402. }
  1403. /**
  1404. * @brief Indicate the status of Receive data register not empty flag.
  1405. * @note RESET: When Receive data register is read.
  1406. * SET: When the received data is copied in Receive data register.
  1407. * @rmtoll ISR RXNE LL_I2C_IsActiveFlag_RXNE
  1408. * @param I2Cx I2C Instance.
  1409. * @retval State of bit (1 or 0).
  1410. */
  1411. __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_RXNE(I2C_TypeDef *I2Cx)
  1412. {
  1413. return (READ_BIT(I2Cx->ISR, I2C_ISR_RXNE) == (I2C_ISR_RXNE));
  1414. }
  1415. /**
  1416. * @brief Indicate the status of Address matched flag (slave mode).
  1417. * @note RESET: Clear default value.
  1418. * SET: When the received slave address matched with one of the enabled slave address.
  1419. * @rmtoll ISR ADDR LL_I2C_IsActiveFlag_ADDR
  1420. * @param I2Cx I2C Instance.
  1421. * @retval State of bit (1 or 0).
  1422. */
  1423. __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_ADDR(I2C_TypeDef *I2Cx)
  1424. {
  1425. return (READ_BIT(I2Cx->ISR, I2C_ISR_ADDR) == (I2C_ISR_ADDR));
  1426. }
  1427. /**
  1428. * @brief Indicate the status of Not Acknowledge received flag.
  1429. * @note RESET: Clear default value.
  1430. * SET: When a NACK is received after a byte transmission.
  1431. * @rmtoll ISR NACKF LL_I2C_IsActiveFlag_NACK
  1432. * @param I2Cx I2C Instance.
  1433. * @retval State of bit (1 or 0).
  1434. */
  1435. __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_NACK(I2C_TypeDef *I2Cx)
  1436. {
  1437. return (READ_BIT(I2Cx->ISR, I2C_ISR_NACKF) == (I2C_ISR_NACKF));
  1438. }
  1439. /**
  1440. * @brief Indicate the status of Stop detection flag.
  1441. * @note RESET: Clear default value.
  1442. * SET: When a Stop condition is detected.
  1443. * @rmtoll ISR STOPF LL_I2C_IsActiveFlag_STOP
  1444. * @param I2Cx I2C Instance.
  1445. * @retval State of bit (1 or 0).
  1446. */
  1447. __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_STOP(I2C_TypeDef *I2Cx)
  1448. {
  1449. return (READ_BIT(I2Cx->ISR, I2C_ISR_STOPF) == (I2C_ISR_STOPF));
  1450. }
  1451. /**
  1452. * @brief Indicate the status of Transfer complete flag (master mode).
  1453. * @note RESET: Clear default value.
  1454. * SET: When RELOAD=0, AUTOEND=0 and NBYTES date have been transferred.
  1455. * @rmtoll ISR TC LL_I2C_IsActiveFlag_TC
  1456. * @param I2Cx I2C Instance.
  1457. * @retval State of bit (1 or 0).
  1458. */
  1459. __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_TC(I2C_TypeDef *I2Cx)
  1460. {
  1461. return (READ_BIT(I2Cx->ISR, I2C_ISR_TC) == (I2C_ISR_TC));
  1462. }
  1463. /**
  1464. * @brief Indicate the status of Transfer complete flag (master mode).
  1465. * @note RESET: Clear default value.
  1466. * SET: When RELOAD=1 and NBYTES date have been transferred.
  1467. * @rmtoll ISR TCR LL_I2C_IsActiveFlag_TCR
  1468. * @param I2Cx I2C Instance.
  1469. * @retval State of bit (1 or 0).
  1470. */
  1471. __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_TCR(I2C_TypeDef *I2Cx)
  1472. {
  1473. return (READ_BIT(I2Cx->ISR, I2C_ISR_TCR) == (I2C_ISR_TCR));
  1474. }
  1475. /**
  1476. * @brief Indicate the status of Bus error flag.
  1477. * @note RESET: Clear default value.
  1478. * SET: When a misplaced Start or Stop condition is detected.
  1479. * @rmtoll ISR BERR LL_I2C_IsActiveFlag_BERR
  1480. * @param I2Cx I2C Instance.
  1481. * @retval State of bit (1 or 0).
  1482. */
  1483. __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_BERR(I2C_TypeDef *I2Cx)
  1484. {
  1485. return (READ_BIT(I2Cx->ISR, I2C_ISR_BERR) == (I2C_ISR_BERR));
  1486. }
  1487. /**
  1488. * @brief Indicate the status of Arbitration lost flag.
  1489. * @note RESET: Clear default value.
  1490. * SET: When arbitration lost.
  1491. * @rmtoll ISR ARLO LL_I2C_IsActiveFlag_ARLO
  1492. * @param I2Cx I2C Instance.
  1493. * @retval State of bit (1 or 0).
  1494. */
  1495. __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_ARLO(I2C_TypeDef *I2Cx)
  1496. {
  1497. return (READ_BIT(I2Cx->ISR, I2C_ISR_ARLO) == (I2C_ISR_ARLO));
  1498. }
  1499. /**
  1500. * @brief Indicate the status of Overrun/Underrun flag (slave mode).
  1501. * @note RESET: Clear default value.
  1502. * SET: When an overrun/underrun error occurs (Clock Stretching Disabled).
  1503. * @rmtoll ISR OVR LL_I2C_IsActiveFlag_OVR
  1504. * @param I2Cx I2C Instance.
  1505. * @retval State of bit (1 or 0).
  1506. */
  1507. __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_OVR(I2C_TypeDef *I2Cx)
  1508. {
  1509. return (READ_BIT(I2Cx->ISR, I2C_ISR_OVR) == (I2C_ISR_OVR));
  1510. }
  1511. /**
  1512. * @brief Indicate the status of SMBus PEC error flag in reception.
  1513. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1514. * SMBus feature is supported by the I2Cx Instance.
  1515. * @note RESET: Clear default value.
  1516. * SET: When the received PEC does not match with the PEC register content.
  1517. * @rmtoll ISR PECERR LL_I2C_IsActiveSMBusFlag_PECERR
  1518. * @param I2Cx I2C Instance.
  1519. * @retval State of bit (1 or 0).
  1520. */
  1521. __STATIC_INLINE uint32_t LL_I2C_IsActiveSMBusFlag_PECERR(I2C_TypeDef *I2Cx)
  1522. {
  1523. return (READ_BIT(I2Cx->ISR, I2C_ISR_PECERR) == (I2C_ISR_PECERR));
  1524. }
  1525. /**
  1526. * @brief Indicate the status of SMBus Timeout detection flag.
  1527. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1528. * SMBus feature is supported by the I2Cx Instance.
  1529. * @note RESET: Clear default value.
  1530. * SET: When a timeout or extended clock timeout occurs.
  1531. * @rmtoll ISR TIMEOUT LL_I2C_IsActiveSMBusFlag_TIMEOUT
  1532. * @param I2Cx I2C Instance.
  1533. * @retval State of bit (1 or 0).
  1534. */
  1535. __STATIC_INLINE uint32_t LL_I2C_IsActiveSMBusFlag_TIMEOUT(I2C_TypeDef *I2Cx)
  1536. {
  1537. return (READ_BIT(I2Cx->ISR, I2C_ISR_TIMEOUT) == (I2C_ISR_TIMEOUT));
  1538. }
  1539. /**
  1540. * @brief Indicate the status of SMBus alert flag.
  1541. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1542. * SMBus feature is supported by the I2Cx Instance.
  1543. * @note RESET: Clear default value.
  1544. * SET: When SMBus host configuration, SMBus alert enabled and
  1545. * a falling edge event occurs on SMBA pin.
  1546. * @rmtoll ISR ALERT LL_I2C_IsActiveSMBusFlag_ALERT
  1547. * @param I2Cx I2C Instance.
  1548. * @retval State of bit (1 or 0).
  1549. */
  1550. __STATIC_INLINE uint32_t LL_I2C_IsActiveSMBusFlag_ALERT(I2C_TypeDef *I2Cx)
  1551. {
  1552. return (READ_BIT(I2Cx->ISR, I2C_ISR_ALERT) == (I2C_ISR_ALERT));
  1553. }
  1554. /**
  1555. * @brief Indicate the status of Bus Busy flag.
  1556. * @note RESET: Clear default value.
  1557. * SET: When a Start condition is detected.
  1558. * @rmtoll ISR BUSY LL_I2C_IsActiveFlag_BUSY
  1559. * @param I2Cx I2C Instance.
  1560. * @retval State of bit (1 or 0).
  1561. */
  1562. __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_BUSY(I2C_TypeDef *I2Cx)
  1563. {
  1564. return (READ_BIT(I2Cx->ISR, I2C_ISR_BUSY) == (I2C_ISR_BUSY));
  1565. }
  1566. /**
  1567. * @brief Clear Address Matched flag.
  1568. * @rmtoll ICR ADDRCF LL_I2C_ClearFlag_ADDR
  1569. * @param I2Cx I2C Instance.
  1570. * @retval None
  1571. */
  1572. __STATIC_INLINE void LL_I2C_ClearFlag_ADDR(I2C_TypeDef *I2Cx)
  1573. {
  1574. SET_BIT(I2Cx->ICR, I2C_ICR_ADDRCF);
  1575. }
  1576. /**
  1577. * @brief Clear Not Acknowledge flag.
  1578. * @rmtoll ICR NACKCF LL_I2C_ClearFlag_NACK
  1579. * @param I2Cx I2C Instance.
  1580. * @retval None
  1581. */
  1582. __STATIC_INLINE void LL_I2C_ClearFlag_NACK(I2C_TypeDef *I2Cx)
  1583. {
  1584. SET_BIT(I2Cx->ICR, I2C_ICR_NACKCF);
  1585. }
  1586. /**
  1587. * @brief Clear Stop detection flag.
  1588. * @rmtoll ICR STOPCF LL_I2C_ClearFlag_STOP
  1589. * @param I2Cx I2C Instance.
  1590. * @retval None
  1591. */
  1592. __STATIC_INLINE void LL_I2C_ClearFlag_STOP(I2C_TypeDef *I2Cx)
  1593. {
  1594. SET_BIT(I2Cx->ICR, I2C_ICR_STOPCF);
  1595. }
  1596. /**
  1597. * @brief Clear Transmit data register empty flag (TXE).
  1598. * @note This bit can be clear by software in order to flush the transmit data register (TXDR).
  1599. * @rmtoll ISR TXE LL_I2C_ClearFlag_TXE
  1600. * @param I2Cx I2C Instance.
  1601. * @retval None
  1602. */
  1603. __STATIC_INLINE void LL_I2C_ClearFlag_TXE(I2C_TypeDef *I2Cx)
  1604. {
  1605. WRITE_REG(I2Cx->ISR, I2C_ISR_TXE);
  1606. }
  1607. /**
  1608. * @brief Clear Bus error flag.
  1609. * @rmtoll ICR BERRCF LL_I2C_ClearFlag_BERR
  1610. * @param I2Cx I2C Instance.
  1611. * @retval None
  1612. */
  1613. __STATIC_INLINE void LL_I2C_ClearFlag_BERR(I2C_TypeDef *I2Cx)
  1614. {
  1615. SET_BIT(I2Cx->ICR, I2C_ICR_BERRCF);
  1616. }
  1617. /**
  1618. * @brief Clear Arbitration lost flag.
  1619. * @rmtoll ICR ARLOCF LL_I2C_ClearFlag_ARLO
  1620. * @param I2Cx I2C Instance.
  1621. * @retval None
  1622. */
  1623. __STATIC_INLINE void LL_I2C_ClearFlag_ARLO(I2C_TypeDef *I2Cx)
  1624. {
  1625. SET_BIT(I2Cx->ICR, I2C_ICR_ARLOCF);
  1626. }
  1627. /**
  1628. * @brief Clear Overrun/Underrun flag.
  1629. * @rmtoll ICR OVRCF LL_I2C_ClearFlag_OVR
  1630. * @param I2Cx I2C Instance.
  1631. * @retval None
  1632. */
  1633. __STATIC_INLINE void LL_I2C_ClearFlag_OVR(I2C_TypeDef *I2Cx)
  1634. {
  1635. SET_BIT(I2Cx->ICR, I2C_ICR_OVRCF);
  1636. }
  1637. /**
  1638. * @brief Clear SMBus PEC error flag.
  1639. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1640. * SMBus feature is supported by the I2Cx Instance.
  1641. * @rmtoll ICR PECCF LL_I2C_ClearSMBusFlag_PECERR
  1642. * @param I2Cx I2C Instance.
  1643. * @retval None
  1644. */
  1645. __STATIC_INLINE void LL_I2C_ClearSMBusFlag_PECERR(I2C_TypeDef *I2Cx)
  1646. {
  1647. SET_BIT(I2Cx->ICR, I2C_ICR_PECCF);
  1648. }
  1649. /**
  1650. * @brief Clear SMBus Timeout detection flag.
  1651. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1652. * SMBus feature is supported by the I2Cx Instance.
  1653. * @rmtoll ICR TIMOUTCF LL_I2C_ClearSMBusFlag_TIMEOUT
  1654. * @param I2Cx I2C Instance.
  1655. * @retval None
  1656. */
  1657. __STATIC_INLINE void LL_I2C_ClearSMBusFlag_TIMEOUT(I2C_TypeDef *I2Cx)
  1658. {
  1659. SET_BIT(I2Cx->ICR, I2C_ICR_TIMOUTCF);
  1660. }
  1661. /**
  1662. * @brief Clear SMBus Alert flag.
  1663. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1664. * SMBus feature is supported by the I2Cx Instance.
  1665. * @rmtoll ICR ALERTCF LL_I2C_ClearSMBusFlag_ALERT
  1666. * @param I2Cx I2C Instance.
  1667. * @retval None
  1668. */
  1669. __STATIC_INLINE void LL_I2C_ClearSMBusFlag_ALERT(I2C_TypeDef *I2Cx)
  1670. {
  1671. SET_BIT(I2Cx->ICR, I2C_ICR_ALERTCF);
  1672. }
  1673. /**
  1674. * @}
  1675. */
  1676. /** @defgroup I2C_LL_EF_Data_Management Data_Management
  1677. * @{
  1678. */
  1679. /**
  1680. * @brief Enable automatic STOP condition generation (master mode).
  1681. * @note Automatic end mode : a STOP condition is automatically sent when NBYTES data are transferred.
  1682. * This bit has no effect in slave mode or when RELOAD bit is set.
  1683. * @rmtoll CR2 AUTOEND LL_I2C_EnableAutoEndMode
  1684. * @param I2Cx I2C Instance.
  1685. * @retval None
  1686. */
  1687. __STATIC_INLINE void LL_I2C_EnableAutoEndMode(I2C_TypeDef *I2Cx)
  1688. {
  1689. SET_BIT(I2Cx->CR2, I2C_CR2_AUTOEND);
  1690. }
  1691. /**
  1692. * @brief Disable automatic STOP condition generation (master mode).
  1693. * @note Software end mode : TC flag is set when NBYTES data are transferre, stretching SCL low.
  1694. * @rmtoll CR2 AUTOEND LL_I2C_DisableAutoEndMode
  1695. * @param I2Cx I2C Instance.
  1696. * @retval None
  1697. */
  1698. __STATIC_INLINE void LL_I2C_DisableAutoEndMode(I2C_TypeDef *I2Cx)
  1699. {
  1700. CLEAR_BIT(I2Cx->CR2, I2C_CR2_AUTOEND);
  1701. }
  1702. /**
  1703. * @brief Check if automatic STOP condition is enabled or disabled.
  1704. * @rmtoll CR2 AUTOEND LL_I2C_IsEnabledAutoEndMode
  1705. * @param I2Cx I2C Instance.
  1706. * @retval State of bit (1 or 0).
  1707. */
  1708. __STATIC_INLINE uint32_t LL_I2C_IsEnabledAutoEndMode(I2C_TypeDef *I2Cx)
  1709. {
  1710. return (READ_BIT(I2Cx->CR2, I2C_CR2_AUTOEND) == (I2C_CR2_AUTOEND));
  1711. }
  1712. /**
  1713. * @brief Enable reload mode (master mode).
  1714. * @note The transfer is not completed after the NBYTES data transfer, NBYTES will be reloaded when TCR flag is set.
  1715. * @rmtoll CR2 RELOAD LL_I2C_EnableReloadMode
  1716. * @param I2Cx I2C Instance.
  1717. * @retval None
  1718. */
  1719. __STATIC_INLINE void LL_I2C_EnableReloadMode(I2C_TypeDef *I2Cx)
  1720. {
  1721. SET_BIT(I2Cx->CR2, I2C_CR2_RELOAD);
  1722. }
  1723. /**
  1724. * @brief Disable reload mode (master mode).
  1725. * @note The transfer is completed after the NBYTES data transfer(STOP or RESTART will follow).
  1726. * @rmtoll CR2 RELOAD LL_I2C_DisableReloadMode
  1727. * @param I2Cx I2C Instance.
  1728. * @retval None
  1729. */
  1730. __STATIC_INLINE void LL_I2C_DisableReloadMode(I2C_TypeDef *I2Cx)
  1731. {
  1732. CLEAR_BIT(I2Cx->CR2, I2C_CR2_RELOAD);
  1733. }
  1734. /**
  1735. * @brief Check if reload mode is enabled or disabled.
  1736. * @rmtoll CR2 RELOAD LL_I2C_IsEnabledReloadMode
  1737. * @param I2Cx I2C Instance.
  1738. * @retval State of bit (1 or 0).
  1739. */
  1740. __STATIC_INLINE uint32_t LL_I2C_IsEnabledReloadMode(I2C_TypeDef *I2Cx)
  1741. {
  1742. return (READ_BIT(I2Cx->CR2, I2C_CR2_RELOAD) == (I2C_CR2_RELOAD));
  1743. }
  1744. /**
  1745. * @brief Configure the number of bytes for transfer.
  1746. * @note Changing these bits when START bit is set is not allowed.
  1747. * @rmtoll CR2 NBYTES LL_I2C_SetTransferSize
  1748. * @param I2Cx I2C Instance.
  1749. * @param TransferSize This parameter must be a value between Min_Data=0x00 and Max_Data=0xFF.
  1750. * @retval None
  1751. */
  1752. __STATIC_INLINE void LL_I2C_SetTransferSize(I2C_TypeDef *I2Cx, uint32_t TransferSize)
  1753. {
  1754. MODIFY_REG(I2Cx->CR2, I2C_CR2_NBYTES, TransferSize << I2C_CR2_NBYTES_Pos);
  1755. }
  1756. /**
  1757. * @brief Get the number of bytes configured for transfer.
  1758. * @rmtoll CR2 NBYTES LL_I2C_GetTransferSize
  1759. * @param I2Cx I2C Instance.
  1760. * @retval Value between Min_Data=0x0 and Max_Data=0xFF
  1761. */
  1762. __STATIC_INLINE uint32_t LL_I2C_GetTransferSize(I2C_TypeDef *I2Cx)
  1763. {
  1764. return (uint32_t)(READ_BIT(I2Cx->CR2, I2C_CR2_NBYTES) >> I2C_CR2_NBYTES_Pos);
  1765. }
  1766. /**
  1767. * @brief Prepare the generation of a ACKnowledge or Non ACKnowledge condition after the address receive match code or next received byte.
  1768. * @note Usage in Slave mode only.
  1769. * @rmtoll CR2 NACK LL_I2C_AcknowledgeNextData
  1770. * @param I2Cx I2C Instance.
  1771. * @param TypeAcknowledge This parameter can be one of the following values:
  1772. * @arg @ref LL_I2C_ACK
  1773. * @arg @ref LL_I2C_NACK
  1774. * @retval None
  1775. */
  1776. __STATIC_INLINE void LL_I2C_AcknowledgeNextData(I2C_TypeDef *I2Cx, uint32_t TypeAcknowledge)
  1777. {
  1778. MODIFY_REG(I2Cx->CR2, I2C_CR2_NACK, TypeAcknowledge);
  1779. }
  1780. /**
  1781. * @brief Generate a START or RESTART condition
  1782. * @note The START bit can be set even if bus is BUSY or I2C is in slave mode.
  1783. * This action has no effect when RELOAD is set.
  1784. * @rmtoll CR2 START LL_I2C_GenerateStartCondition
  1785. * @param I2Cx I2C Instance.
  1786. * @retval None
  1787. */
  1788. __STATIC_INLINE void LL_I2C_GenerateStartCondition(I2C_TypeDef *I2Cx)
  1789. {
  1790. SET_BIT(I2Cx->CR2, I2C_CR2_START);
  1791. }
  1792. /**
  1793. * @brief Generate a STOP condition after the current byte transfer (master mode).
  1794. * @rmtoll CR2 STOP LL_I2C_GenerateStopCondition
  1795. * @param I2Cx I2C Instance.
  1796. * @retval None
  1797. */
  1798. __STATIC_INLINE void LL_I2C_GenerateStopCondition(I2C_TypeDef *I2Cx)
  1799. {
  1800. SET_BIT(I2Cx->CR2, I2C_CR2_STOP);
  1801. }
  1802. /**
  1803. * @brief Enable automatic RESTART Read request condition for 10bit address header (master mode).
  1804. * @note The master sends the complete 10bit slave address read sequence :
  1805. * Start + 2 bytes 10bit address in Write direction + Restart + first 7 bits of 10bit address in Read direction.
  1806. * @rmtoll CR2 HEAD10R LL_I2C_EnableAuto10BitRead
  1807. * @param I2Cx I2C Instance.
  1808. * @retval None
  1809. */
  1810. __STATIC_INLINE void LL_I2C_EnableAuto10BitRead(I2C_TypeDef *I2Cx)
  1811. {
  1812. CLEAR_BIT(I2Cx->CR2, I2C_CR2_HEAD10R);
  1813. }
  1814. /**
  1815. * @brief Disable automatic RESTART Read request condition for 10bit address header (master mode).
  1816. * @note The master only sends the first 7 bits of 10bit address in Read direction.
  1817. * @rmtoll CR2 HEAD10R LL_I2C_DisableAuto10BitRead
  1818. * @param I2Cx I2C Instance.
  1819. * @retval None
  1820. */
  1821. __STATIC_INLINE void LL_I2C_DisableAuto10BitRead(I2C_TypeDef *I2Cx)
  1822. {
  1823. SET_BIT(I2Cx->CR2, I2C_CR2_HEAD10R);
  1824. }
  1825. /**
  1826. * @brief Check if automatic RESTART Read request condition for 10bit address header is enabled or disabled.
  1827. * @rmtoll CR2 HEAD10R LL_I2C_IsEnabledAuto10BitRead
  1828. * @param I2Cx I2C Instance.
  1829. * @retval State of bit (1 or 0).
  1830. */
  1831. __STATIC_INLINE uint32_t LL_I2C_IsEnabledAuto10BitRead(I2C_TypeDef *I2Cx)
  1832. {
  1833. return (READ_BIT(I2Cx->CR2, I2C_CR2_HEAD10R) != (I2C_CR2_HEAD10R));
  1834. }
  1835. /**
  1836. * @brief Configure the transfer direction (master mode).
  1837. * @note Changing these bits when START bit is set is not allowed.
  1838. * @rmtoll CR2 RD_WRN LL_I2C_SetTransferRequest
  1839. * @param I2Cx I2C Instance.
  1840. * @param TransferRequest This parameter can be one of the following values:
  1841. * @arg @ref LL_I2C_REQUEST_WRITE
  1842. * @arg @ref LL_I2C_REQUEST_READ
  1843. * @retval None
  1844. */
  1845. __STATIC_INLINE void LL_I2C_SetTransferRequest(I2C_TypeDef *I2Cx, uint32_t TransferRequest)
  1846. {
  1847. MODIFY_REG(I2Cx->CR2, I2C_CR2_RD_WRN, TransferRequest);
  1848. }
  1849. /**
  1850. * @brief Get the transfer direction requested (master mode).
  1851. * @rmtoll CR2 RD_WRN LL_I2C_GetTransferRequest
  1852. * @param I2Cx I2C Instance.
  1853. * @retval Returned value can be one of the following values:
  1854. * @arg @ref LL_I2C_REQUEST_WRITE
  1855. * @arg @ref LL_I2C_REQUEST_READ
  1856. */
  1857. __STATIC_INLINE uint32_t LL_I2C_GetTransferRequest(I2C_TypeDef *I2Cx)
  1858. {
  1859. return (uint32_t)(READ_BIT(I2Cx->CR2, I2C_CR2_RD_WRN));
  1860. }
  1861. /**
  1862. * @brief Configure the slave address for transfer (master mode).
  1863. * @note Changing these bits when START bit is set is not allowed.
  1864. * @rmtoll CR2 SADD LL_I2C_SetSlaveAddr
  1865. * @param I2Cx I2C Instance.
  1866. * @param SlaveAddr This parameter must be a value between Min_Data=0x00 and Max_Data=0x3F.
  1867. * @retval None
  1868. */
  1869. __STATIC_INLINE void LL_I2C_SetSlaveAddr(I2C_TypeDef *I2Cx, uint32_t SlaveAddr)
  1870. {
  1871. MODIFY_REG(I2Cx->CR2, I2C_CR2_SADD, SlaveAddr);
  1872. }
  1873. /**
  1874. * @brief Get the slave address programmed for transfer.
  1875. * @rmtoll CR2 SADD LL_I2C_GetSlaveAddr
  1876. * @param I2Cx I2C Instance.
  1877. * @retval Value between Min_Data=0x0 and Max_Data=0x3F
  1878. */
  1879. __STATIC_INLINE uint32_t LL_I2C_GetSlaveAddr(I2C_TypeDef *I2Cx)
  1880. {
  1881. return (uint32_t)(READ_BIT(I2Cx->CR2, I2C_CR2_SADD));
  1882. }
  1883. /**
  1884. * @brief Handles I2Cx communication when starting transfer or during transfer (TC or TCR flag are set).
  1885. * @rmtoll CR2 SADD LL_I2C_HandleTransfer\n
  1886. * CR2 ADD10 LL_I2C_HandleTransfer\n
  1887. * CR2 RD_WRN LL_I2C_HandleTransfer\n
  1888. * CR2 START LL_I2C_HandleTransfer\n
  1889. * CR2 STOP LL_I2C_HandleTransfer\n
  1890. * CR2 RELOAD LL_I2C_HandleTransfer\n
  1891. * CR2 NBYTES LL_I2C_HandleTransfer\n
  1892. * CR2 AUTOEND LL_I2C_HandleTransfer\n
  1893. * CR2 HEAD10R LL_I2C_HandleTransfer
  1894. * @param I2Cx I2C Instance.
  1895. * @param SlaveAddr Specifies the slave address to be programmed.
  1896. * @param SlaveAddrSize This parameter can be one of the following values:
  1897. * @arg @ref LL_I2C_ADDRSLAVE_7BIT
  1898. * @arg @ref LL_I2C_ADDRSLAVE_10BIT
  1899. * @param TransferSize Specifies the number of bytes to be programmed.
  1900. * This parameter must be a value between Min_Data=0 and Max_Data=255.
  1901. * @param EndMode This parameter can be one of the following values:
  1902. * @arg @ref LL_I2C_MODE_RELOAD
  1903. * @arg @ref LL_I2C_MODE_AUTOEND
  1904. * @arg @ref LL_I2C_MODE_SOFTEND
  1905. * @arg @ref LL_I2C_MODE_SMBUS_RELOAD
  1906. * @arg @ref LL_I2C_MODE_SMBUS_AUTOEND_NO_PEC
  1907. * @arg @ref LL_I2C_MODE_SMBUS_SOFTEND_NO_PEC
  1908. * @arg @ref LL_I2C_MODE_SMBUS_AUTOEND_WITH_PEC
  1909. * @arg @ref LL_I2C_MODE_SMBUS_SOFTEND_WITH_PEC
  1910. * @param Request This parameter can be one of the following values:
  1911. * @arg @ref LL_I2C_GENERATE_NOSTARTSTOP
  1912. * @arg @ref LL_I2C_GENERATE_STOP
  1913. * @arg @ref LL_I2C_GENERATE_START_READ
  1914. * @arg @ref LL_I2C_GENERATE_START_WRITE
  1915. * @arg @ref LL_I2C_GENERATE_RESTART_7BIT_READ
  1916. * @arg @ref LL_I2C_GENERATE_RESTART_7BIT_WRITE
  1917. * @arg @ref LL_I2C_GENERATE_RESTART_10BIT_READ
  1918. * @arg @ref LL_I2C_GENERATE_RESTART_10BIT_WRITE
  1919. * @retval None
  1920. */
  1921. __STATIC_INLINE void LL_I2C_HandleTransfer(I2C_TypeDef *I2Cx, uint32_t SlaveAddr, uint32_t SlaveAddrSize,
  1922. uint32_t TransferSize, uint32_t EndMode, uint32_t Request)
  1923. {
  1924. MODIFY_REG(I2Cx->CR2, I2C_CR2_SADD | I2C_CR2_ADD10 | (I2C_CR2_RD_WRN & (uint32_t)(Request >> (31U - I2C_CR2_RD_WRN_Pos))) | I2C_CR2_START | I2C_CR2_STOP | I2C_CR2_RELOAD |
  1925. I2C_CR2_NBYTES | I2C_CR2_AUTOEND | I2C_CR2_HEAD10R,
  1926. SlaveAddr | SlaveAddrSize | TransferSize << I2C_CR2_NBYTES_Pos | EndMode | Request);
  1927. }
  1928. /**
  1929. * @brief Indicate the value of transfer direction (slave mode).
  1930. * @note RESET: Write transfer, Slave enters in receiver mode.
  1931. * SET: Read transfer, Slave enters in transmitter mode.
  1932. * @rmtoll ISR DIR LL_I2C_GetTransferDirection
  1933. * @param I2Cx I2C Instance.
  1934. * @retval Returned value can be one of the following values:
  1935. * @arg @ref LL_I2C_DIRECTION_WRITE
  1936. * @arg @ref LL_I2C_DIRECTION_READ
  1937. */
  1938. __STATIC_INLINE uint32_t LL_I2C_GetTransferDirection(I2C_TypeDef *I2Cx)
  1939. {
  1940. return (uint32_t)(READ_BIT(I2Cx->ISR, I2C_ISR_DIR));
  1941. }
  1942. /**
  1943. * @brief Return the slave matched address.
  1944. * @rmtoll ISR ADDCODE LL_I2C_GetAddressMatchCode
  1945. * @param I2Cx I2C Instance.
  1946. * @retval Value between Min_Data=0x00 and Max_Data=0x3F
  1947. */
  1948. __STATIC_INLINE uint32_t LL_I2C_GetAddressMatchCode(I2C_TypeDef *I2Cx)
  1949. {
  1950. return (uint32_t)(READ_BIT(I2Cx->ISR, I2C_ISR_ADDCODE) >> I2C_ISR_ADDCODE_Pos << 1);
  1951. }
  1952. /**
  1953. * @brief Enable internal comparison of the SMBus Packet Error byte (transmission or reception mode).
  1954. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1955. * SMBus feature is supported by the I2Cx Instance.
  1956. * @note This feature is cleared by hardware when the PEC byte is transferred, or when a STOP condition or an Address Matched is received.
  1957. * This bit has no effect when RELOAD bit is set.
  1958. * This bit has no effect in device mode when SBC bit is not set.
  1959. * @rmtoll CR2 PECBYTE LL_I2C_EnableSMBusPECCompare
  1960. * @param I2Cx I2C Instance.
  1961. * @retval None
  1962. */
  1963. __STATIC_INLINE void LL_I2C_EnableSMBusPECCompare(I2C_TypeDef *I2Cx)
  1964. {
  1965. SET_BIT(I2Cx->CR2, I2C_CR2_PECBYTE);
  1966. }
  1967. /**
  1968. * @brief Check if the SMBus Packet Error byte internal comparison is requested or not.
  1969. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1970. * SMBus feature is supported by the I2Cx Instance.
  1971. * @rmtoll CR2 PECBYTE LL_I2C_IsEnabledSMBusPECCompare
  1972. * @param I2Cx I2C Instance.
  1973. * @retval State of bit (1 or 0).
  1974. */
  1975. __STATIC_INLINE uint32_t LL_I2C_IsEnabledSMBusPECCompare(I2C_TypeDef *I2Cx)
  1976. {
  1977. return (READ_BIT(I2Cx->CR2, I2C_CR2_PECBYTE) == (I2C_CR2_PECBYTE));
  1978. }
  1979. /**
  1980. * @brief Get the SMBus Packet Error byte calculated.
  1981. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1982. * SMBus feature is supported by the I2Cx Instance.
  1983. * @rmtoll PECR PEC LL_I2C_GetSMBusPEC
  1984. * @param I2Cx I2C Instance.
  1985. * @retval Value between Min_Data=0x00 and Max_Data=0xFF
  1986. */
  1987. __STATIC_INLINE uint32_t LL_I2C_GetSMBusPEC(I2C_TypeDef *I2Cx)
  1988. {
  1989. return (uint32_t)(READ_BIT(I2Cx->PECR, I2C_PECR_PEC));
  1990. }
  1991. /**
  1992. * @brief Read Receive Data register.
  1993. * @rmtoll RXDR RXDATA LL_I2C_ReceiveData8
  1994. * @param I2Cx I2C Instance.
  1995. * @retval Value between Min_Data=0x00 and Max_Data=0xFF
  1996. */
  1997. __STATIC_INLINE uint8_t LL_I2C_ReceiveData8(I2C_TypeDef *I2Cx)
  1998. {
  1999. return (uint8_t)(READ_BIT(I2Cx->RXDR, I2C_RXDR_RXDATA));
  2000. }
  2001. /**
  2002. * @brief Write in Transmit Data Register .
  2003. * @rmtoll TXDR TXDATA LL_I2C_TransmitData8
  2004. * @param I2Cx I2C Instance.
  2005. * @param Data Value between Min_Data=0x00 and Max_Data=0xFF
  2006. * @retval None
  2007. */
  2008. __STATIC_INLINE void LL_I2C_TransmitData8(I2C_TypeDef *I2Cx, uint8_t Data)
  2009. {
  2010. WRITE_REG(I2Cx->TXDR, Data);
  2011. }
  2012. /**
  2013. * @}
  2014. */
  2015. #if defined(USE_FULL_LL_DRIVER)
  2016. /** @defgroup I2C_LL_EF_Init Initialization and de-initialization functions
  2017. * @{
  2018. */
  2019. uint32_t LL_I2C_Init(I2C_TypeDef *I2Cx, LL_I2C_InitTypeDef *I2C_InitStruct);
  2020. uint32_t LL_I2C_DeInit(I2C_TypeDef *I2Cx);
  2021. void LL_I2C_StructInit(LL_I2C_InitTypeDef *I2C_InitStruct);
  2022. /**
  2023. * @}
  2024. */
  2025. #endif /* USE_FULL_LL_DRIVER */
  2026. /**
  2027. * @}
  2028. */
  2029. /**
  2030. * @}
  2031. */
  2032. #endif /* I2C1 || I2C2 || I2C3 || I2C4 */
  2033. /**
  2034. * @}
  2035. */
  2036. #ifdef __cplusplus
  2037. }
  2038. #endif
  2039. #endif /* __STM32L4xx_LL_I2C_H */
  2040. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/