stm32g0xx_ll_i2c.h 82 KB

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