stm32l4xx_ll_i2c.h 83 KB

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