stm32l4xx_ll_i2c.h 82 KB

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