stm32g0xx_ll_i2c.h 81 KB

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