stm32f4xx_ll_i2c.h 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892
  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_ll_i2c.h
  4. * @author MCD Application Team
  5. * @brief Header file of I2C LL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. */
  19. /* Define to prevent recursive inclusion -------------------------------------*/
  20. #ifndef __STM32F4xx_LL_I2C_H
  21. #define __STM32F4xx_LL_I2C_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /* Includes ------------------------------------------------------------------*/
  26. #include "stm32f4xx.h"
  27. /** @addtogroup STM32F4xx_LL_Driver
  28. * @{
  29. */
  30. #if defined (I2C1) || defined (I2C2) || defined (I2C3)
  31. /** @defgroup I2C_LL I2C
  32. * @{
  33. */
  34. /* Private types -------------------------------------------------------------*/
  35. /* Private variables ---------------------------------------------------------*/
  36. /* Private constants ---------------------------------------------------------*/
  37. /** @defgroup I2C_LL_Private_Constants I2C Private Constants
  38. * @{
  39. */
  40. /* Defines used to perform compute and check in the macros */
  41. #define LL_I2C_MAX_SPEED_STANDARD 100000U
  42. #define LL_I2C_MAX_SPEED_FAST 400000U
  43. /**
  44. * @}
  45. */
  46. /* Private macros ------------------------------------------------------------*/
  47. #if defined(USE_FULL_LL_DRIVER)
  48. /** @defgroup I2C_LL_Private_Macros I2C Private Macros
  49. * @{
  50. */
  51. /**
  52. * @}
  53. */
  54. #endif /*USE_FULL_LL_DRIVER*/
  55. /* Exported types ------------------------------------------------------------*/
  56. #if defined(USE_FULL_LL_DRIVER)
  57. /** @defgroup I2C_LL_ES_INIT I2C Exported Init structure
  58. * @{
  59. */
  60. typedef struct
  61. {
  62. uint32_t PeripheralMode; /*!< Specifies the peripheral mode.
  63. This parameter can be a value of @ref I2C_LL_EC_PERIPHERAL_MODE
  64. This feature can be modified afterwards using unitary function @ref LL_I2C_SetMode(). */
  65. uint32_t ClockSpeed; /*!< Specifies the clock frequency.
  66. This parameter must be set to a value lower than 400kHz (in Hz)
  67. This feature can be modified afterwards using unitary function @ref LL_I2C_SetClockPeriod()
  68. or @ref LL_I2C_SetDutyCycle() or @ref LL_I2C_SetClockSpeedMode() or @ref LL_I2C_ConfigSpeed(). */
  69. uint32_t DutyCycle; /*!< Specifies the I2C fast mode duty cycle.
  70. This parameter can be a value of @ref I2C_LL_EC_DUTYCYCLE
  71. This feature can be modified afterwards using unitary function @ref LL_I2C_SetDutyCycle(). */
  72. #if defined(I2C_FLTR_ANOFF)&&defined(I2C_FLTR_DNF)
  73. uint32_t AnalogFilter; /*!< Enables or disables analog noise filter.
  74. This parameter can be a value of @ref I2C_LL_EC_ANALOGFILTER_SELECTION
  75. This feature can be modified afterwards using unitary functions @ref LL_I2C_EnableAnalogFilter() or LL_I2C_DisableAnalogFilter(). */
  76. uint32_t DigitalFilter; /*!< Configures the digital noise filter.
  77. This parameter can be a number between Min_Data = 0x00 and Max_Data = 0x0F
  78. This feature can be modified afterwards using unitary function @ref LL_I2C_SetDigitalFilter(). */
  79. #endif
  80. uint32_t OwnAddress1; /*!< Specifies the device own address 1.
  81. This parameter must be a value between Min_Data = 0x00 and Max_Data = 0x3FF
  82. This feature can be modified afterwards using unitary function @ref LL_I2C_SetOwnAddress1(). */
  83. uint32_t TypeAcknowledge; /*!< Specifies the ACKnowledge or Non ACKnowledge condition after the address receive match code or next received byte.
  84. This parameter can be a value of @ref I2C_LL_EC_I2C_ACKNOWLEDGE
  85. This feature can be modified afterwards using unitary function @ref LL_I2C_AcknowledgeNextData(). */
  86. uint32_t OwnAddrSize; /*!< Specifies the device own address 1 size (7-bit or 10-bit).
  87. This parameter can be a value of @ref I2C_LL_EC_OWNADDRESS1
  88. This feature can be modified afterwards using unitary function @ref LL_I2C_SetOwnAddress1(). */
  89. } LL_I2C_InitTypeDef;
  90. /**
  91. * @}
  92. */
  93. #endif /*USE_FULL_LL_DRIVER*/
  94. /* Exported constants --------------------------------------------------------*/
  95. /** @defgroup I2C_LL_Exported_Constants I2C Exported Constants
  96. * @{
  97. */
  98. /** @defgroup I2C_LL_EC_GET_FLAG Get Flags Defines
  99. * @brief Flags defines which can be used with LL_I2C_ReadReg function
  100. * @{
  101. */
  102. #define LL_I2C_SR1_SB I2C_SR1_SB /*!< Start Bit (master mode) */
  103. #define LL_I2C_SR1_ADDR I2C_SR1_ADDR /*!< Address sent (master mode) or
  104. Address matched flag (slave mode) */
  105. #define LL_I2C_SR1_BTF I2C_SR1_BTF /*!< Byte Transfer Finished flag */
  106. #define LL_I2C_SR1_ADD10 I2C_SR1_ADD10 /*!< 10-bit header sent (master mode) */
  107. #define LL_I2C_SR1_STOPF I2C_SR1_STOPF /*!< Stop detection flag (slave mode) */
  108. #define LL_I2C_SR1_RXNE I2C_SR1_RXNE /*!< Data register not empty (receivers) */
  109. #define LL_I2C_SR1_TXE I2C_SR1_TXE /*!< Data register empty (transmitters) */
  110. #define LL_I2C_SR1_BERR I2C_SR1_BERR /*!< Bus error */
  111. #define LL_I2C_SR1_ARLO I2C_SR1_ARLO /*!< Arbitration lost */
  112. #define LL_I2C_SR1_AF I2C_SR1_AF /*!< Acknowledge failure flag */
  113. #define LL_I2C_SR1_OVR I2C_SR1_OVR /*!< Overrun/Underrun */
  114. #define LL_I2C_SR1_PECERR I2C_ISR_PECERR /*!< PEC Error in reception (SMBus mode) */
  115. #define LL_I2C_SR1_TIMEOUT I2C_ISR_TIMEOUT /*!< Timeout detection flag (SMBus mode) */
  116. #define LL_I2C_SR1_SMALERT I2C_ISR_SMALERT /*!< SMBus alert (SMBus mode) */
  117. #define LL_I2C_SR2_MSL I2C_SR2_MSL /*!< Master/Slave flag */
  118. #define LL_I2C_SR2_BUSY I2C_SR2_BUSY /*!< Bus busy flag */
  119. #define LL_I2C_SR2_TRA I2C_SR2_TRA /*!< Transmitter/receiver direction */
  120. #define LL_I2C_SR2_GENCALL I2C_SR2_GENCALL /*!< General call address (Slave mode) */
  121. #define LL_I2C_SR2_SMBDEFAULT I2C_SR2_SMBDEFAULT /*!< SMBus Device default address (Slave mode) */
  122. #define LL_I2C_SR2_SMBHOST I2C_SR2_SMBHOST /*!< SMBus Host address (Slave mode) */
  123. #define LL_I2C_SR2_DUALF I2C_SR2_DUALF /*!< Dual flag (Slave mode) */
  124. /**
  125. * @}
  126. */
  127. /** @defgroup I2C_LL_EC_IT IT Defines
  128. * @brief IT defines which can be used with LL_I2C_ReadReg and LL_I2C_WriteReg functions
  129. * @{
  130. */
  131. #define LL_I2C_CR2_ITEVTEN I2C_CR2_ITEVTEN /*!< Events interrupts enable */
  132. #define LL_I2C_CR2_ITBUFEN I2C_CR2_ITBUFEN /*!< Buffer interrupts enable */
  133. #define LL_I2C_CR2_ITERREN I2C_CR2_ITERREN /*!< Error interrupts enable */
  134. /**
  135. * @}
  136. */
  137. #if defined(I2C_FLTR_ANOFF)
  138. /** @defgroup I2C_LL_EC_ANALOGFILTER_SELECTION Analog Filter Selection
  139. * @{
  140. */
  141. #define LL_I2C_ANALOGFILTER_ENABLE 0x00000000U /*!< Analog filter is enabled. */
  142. #define LL_I2C_ANALOGFILTER_DISABLE I2C_FLTR_ANOFF /*!< Analog filter is disabled.*/
  143. /**
  144. * @}
  145. */
  146. #endif
  147. /** @defgroup I2C_LL_EC_OWNADDRESS1 Own Address 1 Length
  148. * @{
  149. */
  150. #define LL_I2C_OWNADDRESS1_7BIT 0x00004000U /*!< Own address 1 is a 7-bit address. */
  151. #define LL_I2C_OWNADDRESS1_10BIT (uint32_t)(I2C_OAR1_ADDMODE | 0x00004000U) /*!< Own address 1 is a 10-bit address. */
  152. /**
  153. * @}
  154. */
  155. /** @defgroup I2C_LL_EC_DUTYCYCLE Fast Mode Duty Cycle
  156. * @{
  157. */
  158. #define LL_I2C_DUTYCYCLE_2 0x00000000U /*!< I2C fast mode Tlow/Thigh = 2 */
  159. #define LL_I2C_DUTYCYCLE_16_9 I2C_CCR_DUTY /*!< I2C fast mode Tlow/Thigh = 16/9 */
  160. /**
  161. * @}
  162. */
  163. /** @defgroup I2C_LL_EC_CLOCK_SPEED_MODE Master Clock Speed Mode
  164. * @{
  165. */
  166. #define LL_I2C_CLOCK_SPEED_STANDARD_MODE 0x00000000U /*!< Master clock speed range is standard mode */
  167. #define LL_I2C_CLOCK_SPEED_FAST_MODE I2C_CCR_FS /*!< Master clock speed range is fast mode */
  168. /**
  169. * @}
  170. */
  171. /** @defgroup I2C_LL_EC_PERIPHERAL_MODE Peripheral Mode
  172. * @{
  173. */
  174. #define LL_I2C_MODE_I2C 0x00000000U /*!< I2C Master or Slave mode */
  175. #define LL_I2C_MODE_SMBUS_HOST (uint32_t)(I2C_CR1_SMBUS | I2C_CR1_SMBTYPE | I2C_CR1_ENARP) /*!< SMBus Host address acknowledge */
  176. #define LL_I2C_MODE_SMBUS_DEVICE I2C_CR1_SMBUS /*!< SMBus Device default mode (Default address not acknowledge) */
  177. #define LL_I2C_MODE_SMBUS_DEVICE_ARP (uint32_t)(I2C_CR1_SMBUS | I2C_CR1_ENARP) /*!< SMBus Device Default address acknowledge */
  178. /**
  179. * @}
  180. */
  181. /** @defgroup I2C_LL_EC_I2C_ACKNOWLEDGE Acknowledge Generation
  182. * @{
  183. */
  184. #define LL_I2C_ACK I2C_CR1_ACK /*!< ACK is sent after current received byte. */
  185. #define LL_I2C_NACK 0x00000000U /*!< NACK is sent after current received byte.*/
  186. /**
  187. * @}
  188. */
  189. /** @defgroup I2C_LL_EC_DIRECTION Read Write Direction
  190. * @{
  191. */
  192. #define LL_I2C_DIRECTION_WRITE I2C_SR2_TRA /*!< Bus is in write transfer */
  193. #define LL_I2C_DIRECTION_READ 0x00000000U /*!< Bus is in read transfer */
  194. /**
  195. * @}
  196. */
  197. /**
  198. * @}
  199. */
  200. /* Exported macro ------------------------------------------------------------*/
  201. /** @defgroup I2C_LL_Exported_Macros I2C Exported Macros
  202. * @{
  203. */
  204. /** @defgroup I2C_LL_EM_WRITE_READ Common Write and read registers Macros
  205. * @{
  206. */
  207. /**
  208. * @brief Write a value in I2C register
  209. * @param __INSTANCE__ I2C Instance
  210. * @param __REG__ Register to be written
  211. * @param __VALUE__ Value to be written in the register
  212. * @retval None
  213. */
  214. #define LL_I2C_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
  215. /**
  216. * @brief Read a value in I2C register
  217. * @param __INSTANCE__ I2C Instance
  218. * @param __REG__ Register to be read
  219. * @retval Register value
  220. */
  221. #define LL_I2C_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
  222. /**
  223. * @}
  224. */
  225. /** @defgroup I2C_LL_EM_Exported_Macros_Helper Exported_Macros_Helper
  226. * @{
  227. */
  228. /**
  229. * @brief Convert Peripheral Clock Frequency in Mhz.
  230. * @param __PCLK__ This parameter must be a value of peripheral clock (in Hz).
  231. * @retval Value of peripheral clock (in Mhz)
  232. */
  233. #define __LL_I2C_FREQ_HZ_TO_MHZ(__PCLK__) (uint32_t)((__PCLK__)/1000000U)
  234. /**
  235. * @brief Convert Peripheral Clock Frequency in Hz.
  236. * @param __PCLK__ This parameter must be a value of peripheral clock (in Mhz).
  237. * @retval Value of peripheral clock (in Hz)
  238. */
  239. #define __LL_I2C_FREQ_MHZ_TO_HZ(__PCLK__) (uint32_t)((__PCLK__)*1000000U)
  240. /**
  241. * @brief Compute I2C Clock rising time.
  242. * @param __FREQRANGE__ This parameter must be a value of peripheral clock (in Mhz).
  243. * @param __SPEED__ This parameter must be a value lower than 400kHz (in Hz).
  244. * @retval Value between Min_Data=0x02 and Max_Data=0x3F
  245. */
  246. #define __LL_I2C_RISE_TIME(__FREQRANGE__, __SPEED__) (uint32_t)(((__SPEED__) <= LL_I2C_MAX_SPEED_STANDARD) ? ((__FREQRANGE__) + 1U) : ((((__FREQRANGE__) * 300U) / 1000U) + 1U))
  247. /**
  248. * @brief Compute Speed clock range to a Clock Control Register (I2C_CCR_CCR) value.
  249. * @param __PCLK__ This parameter must be a value of peripheral clock (in Hz).
  250. * @param __SPEED__ This parameter must be a value lower than 400kHz (in Hz).
  251. * @param __DUTYCYCLE__ This parameter can be one of the following values:
  252. * @arg @ref LL_I2C_DUTYCYCLE_2
  253. * @arg @ref LL_I2C_DUTYCYCLE_16_9
  254. * @retval Value between Min_Data=0x004 and Max_Data=0xFFF, except in FAST DUTY mode where Min_Data=0x001.
  255. */
  256. #define __LL_I2C_SPEED_TO_CCR(__PCLK__, __SPEED__, __DUTYCYCLE__) (uint32_t)(((__SPEED__) <= LL_I2C_MAX_SPEED_STANDARD)? \
  257. (__LL_I2C_SPEED_STANDARD_TO_CCR((__PCLK__), (__SPEED__))) : \
  258. (__LL_I2C_SPEED_FAST_TO_CCR((__PCLK__), (__SPEED__), (__DUTYCYCLE__))))
  259. /**
  260. * @brief Compute Speed Standard clock range to a Clock Control Register (I2C_CCR_CCR) value.
  261. * @param __PCLK__ This parameter must be a value of peripheral clock (in Hz).
  262. * @param __SPEED__ This parameter must be a value lower than 100kHz (in Hz).
  263. * @retval Value between Min_Data=0x004 and Max_Data=0xFFF.
  264. */
  265. #define __LL_I2C_SPEED_STANDARD_TO_CCR(__PCLK__, __SPEED__) (uint32_t)(((((__PCLK__)/((__SPEED__) << 1U)) & I2C_CCR_CCR) < 4U)? 4U:((__PCLK__) / ((__SPEED__) << 1U)))
  266. /**
  267. * @brief Compute Speed Fast clock range to a Clock Control Register (I2C_CCR_CCR) value.
  268. * @param __PCLK__ This parameter must be a value of peripheral clock (in Hz).
  269. * @param __SPEED__ This parameter must be a value between Min_Data=100Khz and Max_Data=400Khz (in Hz).
  270. * @param __DUTYCYCLE__ This parameter can be one of the following values:
  271. * @arg @ref LL_I2C_DUTYCYCLE_2
  272. * @arg @ref LL_I2C_DUTYCYCLE_16_9
  273. * @retval Value between Min_Data=0x001 and Max_Data=0xFFF
  274. */
  275. #define __LL_I2C_SPEED_FAST_TO_CCR(__PCLK__, __SPEED__, __DUTYCYCLE__) (uint32_t)(((__DUTYCYCLE__) == LL_I2C_DUTYCYCLE_2)? \
  276. (((((__PCLK__) / ((__SPEED__) * 3U)) & I2C_CCR_CCR) == 0U)? 1U:((__PCLK__) / ((__SPEED__) * 3U))) : \
  277. (((((__PCLK__) / ((__SPEED__) * 25U)) & I2C_CCR_CCR) == 0U)? 1U:((__PCLK__) / ((__SPEED__) * 25U))))
  278. /**
  279. * @brief Get the Least significant bits of a 10-Bits address.
  280. * @param __ADDRESS__ This parameter must be a value of a 10-Bits slave address.
  281. * @retval Value between Min_Data=0x00 and Max_Data=0xFF
  282. */
  283. #define __LL_I2C_10BIT_ADDRESS(__ADDRESS__) ((uint8_t)((uint16_t)((__ADDRESS__) & (uint16_t)(0x00FF))))
  284. /**
  285. * @brief Convert a 10-Bits address to a 10-Bits header with Write direction.
  286. * @param __ADDRESS__ This parameter must be a value of a 10-Bits slave address.
  287. * @retval Value between Min_Data=0xF0 and Max_Data=0xF6
  288. */
  289. #define __LL_I2C_10BIT_HEADER_WRITE(__ADDRESS__) ((uint8_t)((uint16_t)((uint16_t)(((uint16_t)((__ADDRESS__) & (uint16_t)(0x0300))) >> 7) | (uint16_t)(0xF0))))
  290. /**
  291. * @brief Convert a 10-Bits address to a 10-Bits header with Read direction.
  292. * @param __ADDRESS__ This parameter must be a value of a 10-Bits slave address.
  293. * @retval Value between Min_Data=0xF1 and Max_Data=0xF7
  294. */
  295. #define __LL_I2C_10BIT_HEADER_READ(__ADDRESS__) ((uint8_t)((uint16_t)((uint16_t)(((uint16_t)((__ADDRESS__) & (uint16_t)(0x0300))) >> 7) | (uint16_t)(0xF1))))
  296. /**
  297. * @}
  298. */
  299. /**
  300. * @}
  301. */
  302. /* Exported functions --------------------------------------------------------*/
  303. /** @defgroup I2C_LL_Exported_Functions I2C Exported Functions
  304. * @{
  305. */
  306. /** @defgroup I2C_LL_EF_Configuration Configuration
  307. * @{
  308. */
  309. /**
  310. * @brief Enable I2C peripheral (PE = 1).
  311. * @rmtoll CR1 PE LL_I2C_Enable
  312. * @param I2Cx I2C Instance.
  313. * @retval None
  314. */
  315. __STATIC_INLINE void LL_I2C_Enable(I2C_TypeDef *I2Cx)
  316. {
  317. SET_BIT(I2Cx->CR1, I2C_CR1_PE);
  318. }
  319. /**
  320. * @brief Disable I2C peripheral (PE = 0).
  321. * @rmtoll CR1 PE LL_I2C_Disable
  322. * @param I2Cx I2C Instance.
  323. * @retval None
  324. */
  325. __STATIC_INLINE void LL_I2C_Disable(I2C_TypeDef *I2Cx)
  326. {
  327. CLEAR_BIT(I2Cx->CR1, I2C_CR1_PE);
  328. }
  329. /**
  330. * @brief Check if the I2C peripheral is enabled or disabled.
  331. * @rmtoll CR1 PE LL_I2C_IsEnabled
  332. * @param I2Cx I2C Instance.
  333. * @retval State of bit (1 or 0).
  334. */
  335. __STATIC_INLINE uint32_t LL_I2C_IsEnabled(I2C_TypeDef *I2Cx)
  336. {
  337. return (READ_BIT(I2Cx->CR1, I2C_CR1_PE) == (I2C_CR1_PE));
  338. }
  339. #if defined(I2C_FLTR_ANOFF)&&defined(I2C_FLTR_DNF)
  340. /**
  341. * @brief Configure Noise Filters (Analog and Digital).
  342. * @note If the analog filter is also enabled, the digital filter is added to analog filter.
  343. * The filters can only be programmed when the I2C is disabled (PE = 0).
  344. * @rmtoll FLTR ANOFF LL_I2C_ConfigFilters\n
  345. * FLTR DNF LL_I2C_ConfigFilters
  346. * @param I2Cx I2C Instance.
  347. * @param AnalogFilter This parameter can be one of the following values:
  348. * @arg @ref LL_I2C_ANALOGFILTER_ENABLE
  349. * @arg @ref LL_I2C_ANALOGFILTER_DISABLE
  350. * @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*TPCLK1)
  351. * This parameter is used to configure the digital noise filter on SDA and SCL input. The digital filter will suppress the spikes with a length of up to DNF[3:0]*TPCLK1.
  352. * @retval None
  353. */
  354. __STATIC_INLINE void LL_I2C_ConfigFilters(I2C_TypeDef *I2Cx, uint32_t AnalogFilter, uint32_t DigitalFilter)
  355. {
  356. MODIFY_REG(I2Cx->FLTR, I2C_FLTR_ANOFF | I2C_FLTR_DNF, AnalogFilter | DigitalFilter);
  357. }
  358. #endif
  359. #if defined(I2C_FLTR_DNF)
  360. /**
  361. * @brief Configure Digital Noise Filter.
  362. * @note If the analog filter is also enabled, the digital filter is added to analog filter.
  363. * This filter can only be programmed when the I2C is disabled (PE = 0).
  364. * @rmtoll FLTR DNF LL_I2C_SetDigitalFilter
  365. * @param I2Cx I2C Instance.
  366. * @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*TPCLK1)
  367. * This parameter is used to configure the digital noise filter on SDA and SCL input. The digital filter will suppress the spikes with a length of up to DNF[3:0]*TPCLK1.
  368. * @retval None
  369. */
  370. __STATIC_INLINE void LL_I2C_SetDigitalFilter(I2C_TypeDef *I2Cx, uint32_t DigitalFilter)
  371. {
  372. MODIFY_REG(I2Cx->FLTR, I2C_FLTR_DNF, DigitalFilter);
  373. }
  374. /**
  375. * @brief Get the current Digital Noise Filter configuration.
  376. * @rmtoll FLTR DNF LL_I2C_GetDigitalFilter
  377. * @param I2Cx I2C Instance.
  378. * @retval Value between Min_Data=0x0 and Max_Data=0xF
  379. */
  380. __STATIC_INLINE uint32_t LL_I2C_GetDigitalFilter(I2C_TypeDef *I2Cx)
  381. {
  382. return (uint32_t)(READ_BIT(I2Cx->FLTR, I2C_FLTR_DNF));
  383. }
  384. #endif
  385. #if defined(I2C_FLTR_ANOFF)
  386. /**
  387. * @brief Enable Analog Noise Filter.
  388. * @note This filter can only be programmed when the I2C is disabled (PE = 0).
  389. * @rmtoll FLTR ANOFF LL_I2C_EnableAnalogFilter
  390. * @param I2Cx I2C Instance.
  391. * @retval None
  392. */
  393. __STATIC_INLINE void LL_I2C_EnableAnalogFilter(I2C_TypeDef *I2Cx)
  394. {
  395. CLEAR_BIT(I2Cx->FLTR, I2C_FLTR_ANOFF);
  396. }
  397. /**
  398. * @brief Disable Analog Noise Filter.
  399. * @note This filter can only be programmed when the I2C is disabled (PE = 0).
  400. * @rmtoll FLTR ANOFF LL_I2C_DisableAnalogFilter
  401. * @param I2Cx I2C Instance.
  402. * @retval None
  403. */
  404. __STATIC_INLINE void LL_I2C_DisableAnalogFilter(I2C_TypeDef *I2Cx)
  405. {
  406. SET_BIT(I2Cx->FLTR, I2C_FLTR_ANOFF);
  407. }
  408. /**
  409. * @brief Check if Analog Noise Filter is enabled or disabled.
  410. * @rmtoll FLTR ANOFF LL_I2C_IsEnabledAnalogFilter
  411. * @param I2Cx I2C Instance.
  412. * @retval State of bit (1 or 0).
  413. */
  414. __STATIC_INLINE uint32_t LL_I2C_IsEnabledAnalogFilter(I2C_TypeDef *I2Cx)
  415. {
  416. return (READ_BIT(I2Cx->FLTR, I2C_FLTR_ANOFF) == (I2C_FLTR_ANOFF));
  417. }
  418. #endif
  419. /**
  420. * @brief Enable DMA transmission requests.
  421. * @rmtoll CR2 DMAEN LL_I2C_EnableDMAReq_TX
  422. * @param I2Cx I2C Instance.
  423. * @retval None
  424. */
  425. __STATIC_INLINE void LL_I2C_EnableDMAReq_TX(I2C_TypeDef *I2Cx)
  426. {
  427. SET_BIT(I2Cx->CR2, I2C_CR2_DMAEN);
  428. }
  429. /**
  430. * @brief Disable DMA transmission requests.
  431. * @rmtoll CR2 DMAEN LL_I2C_DisableDMAReq_TX
  432. * @param I2Cx I2C Instance.
  433. * @retval None
  434. */
  435. __STATIC_INLINE void LL_I2C_DisableDMAReq_TX(I2C_TypeDef *I2Cx)
  436. {
  437. CLEAR_BIT(I2Cx->CR2, I2C_CR2_DMAEN);
  438. }
  439. /**
  440. * @brief Check if DMA transmission requests are enabled or disabled.
  441. * @rmtoll CR2 DMAEN LL_I2C_IsEnabledDMAReq_TX
  442. * @param I2Cx I2C Instance.
  443. * @retval State of bit (1 or 0).
  444. */
  445. __STATIC_INLINE uint32_t LL_I2C_IsEnabledDMAReq_TX(I2C_TypeDef *I2Cx)
  446. {
  447. return (READ_BIT(I2Cx->CR2, I2C_CR2_DMAEN) == (I2C_CR2_DMAEN));
  448. }
  449. /**
  450. * @brief Enable DMA reception requests.
  451. * @rmtoll CR2 DMAEN LL_I2C_EnableDMAReq_RX
  452. * @param I2Cx I2C Instance.
  453. * @retval None
  454. */
  455. __STATIC_INLINE void LL_I2C_EnableDMAReq_RX(I2C_TypeDef *I2Cx)
  456. {
  457. SET_BIT(I2Cx->CR2, I2C_CR2_DMAEN);
  458. }
  459. /**
  460. * @brief Disable DMA reception requests.
  461. * @rmtoll CR2 DMAEN LL_I2C_DisableDMAReq_RX
  462. * @param I2Cx I2C Instance.
  463. * @retval None
  464. */
  465. __STATIC_INLINE void LL_I2C_DisableDMAReq_RX(I2C_TypeDef *I2Cx)
  466. {
  467. CLEAR_BIT(I2Cx->CR2, I2C_CR2_DMAEN);
  468. }
  469. /**
  470. * @brief Check if DMA reception requests are enabled or disabled.
  471. * @rmtoll CR2 DMAEN LL_I2C_IsEnabledDMAReq_RX
  472. * @param I2Cx I2C Instance.
  473. * @retval State of bit (1 or 0).
  474. */
  475. __STATIC_INLINE uint32_t LL_I2C_IsEnabledDMAReq_RX(I2C_TypeDef *I2Cx)
  476. {
  477. return (READ_BIT(I2Cx->CR2, I2C_CR2_DMAEN) == (I2C_CR2_DMAEN));
  478. }
  479. /**
  480. * @brief Get the data register address used for DMA transfer.
  481. * @rmtoll DR DR LL_I2C_DMA_GetRegAddr
  482. * @param I2Cx I2C Instance.
  483. * @retval Address of data register
  484. */
  485. __STATIC_INLINE uint32_t LL_I2C_DMA_GetRegAddr(I2C_TypeDef *I2Cx)
  486. {
  487. return (uint32_t) & (I2Cx->DR);
  488. }
  489. /**
  490. * @brief Enable Clock stretching.
  491. * @note This bit can only be programmed when the I2C is disabled (PE = 0).
  492. * @rmtoll CR1 NOSTRETCH LL_I2C_EnableClockStretching
  493. * @param I2Cx I2C Instance.
  494. * @retval None
  495. */
  496. __STATIC_INLINE void LL_I2C_EnableClockStretching(I2C_TypeDef *I2Cx)
  497. {
  498. CLEAR_BIT(I2Cx->CR1, I2C_CR1_NOSTRETCH);
  499. }
  500. /**
  501. * @brief Disable Clock stretching.
  502. * @note This bit can only be programmed when the I2C is disabled (PE = 0).
  503. * @rmtoll CR1 NOSTRETCH LL_I2C_DisableClockStretching
  504. * @param I2Cx I2C Instance.
  505. * @retval None
  506. */
  507. __STATIC_INLINE void LL_I2C_DisableClockStretching(I2C_TypeDef *I2Cx)
  508. {
  509. SET_BIT(I2Cx->CR1, I2C_CR1_NOSTRETCH);
  510. }
  511. /**
  512. * @brief Check if Clock stretching is enabled or disabled.
  513. * @rmtoll CR1 NOSTRETCH LL_I2C_IsEnabledClockStretching
  514. * @param I2Cx I2C Instance.
  515. * @retval State of bit (1 or 0).
  516. */
  517. __STATIC_INLINE uint32_t LL_I2C_IsEnabledClockStretching(I2C_TypeDef *I2Cx)
  518. {
  519. return (READ_BIT(I2Cx->CR1, I2C_CR1_NOSTRETCH) != (I2C_CR1_NOSTRETCH));
  520. }
  521. /**
  522. * @brief Enable General Call.
  523. * @note When enabled the Address 0x00 is ACKed.
  524. * @rmtoll CR1 ENGC LL_I2C_EnableGeneralCall
  525. * @param I2Cx I2C Instance.
  526. * @retval None
  527. */
  528. __STATIC_INLINE void LL_I2C_EnableGeneralCall(I2C_TypeDef *I2Cx)
  529. {
  530. SET_BIT(I2Cx->CR1, I2C_CR1_ENGC);
  531. }
  532. /**
  533. * @brief Disable General Call.
  534. * @note When disabled the Address 0x00 is NACKed.
  535. * @rmtoll CR1 ENGC LL_I2C_DisableGeneralCall
  536. * @param I2Cx I2C Instance.
  537. * @retval None
  538. */
  539. __STATIC_INLINE void LL_I2C_DisableGeneralCall(I2C_TypeDef *I2Cx)
  540. {
  541. CLEAR_BIT(I2Cx->CR1, I2C_CR1_ENGC);
  542. }
  543. /**
  544. * @brief Check if General Call is enabled or disabled.
  545. * @rmtoll CR1 ENGC LL_I2C_IsEnabledGeneralCall
  546. * @param I2Cx I2C Instance.
  547. * @retval State of bit (1 or 0).
  548. */
  549. __STATIC_INLINE uint32_t LL_I2C_IsEnabledGeneralCall(I2C_TypeDef *I2Cx)
  550. {
  551. return (READ_BIT(I2Cx->CR1, I2C_CR1_ENGC) == (I2C_CR1_ENGC));
  552. }
  553. /**
  554. * @brief Set the Own Address1.
  555. * @rmtoll OAR1 ADD0 LL_I2C_SetOwnAddress1\n
  556. * OAR1 ADD1_7 LL_I2C_SetOwnAddress1\n
  557. * OAR1 ADD8_9 LL_I2C_SetOwnAddress1\n
  558. * OAR1 ADDMODE LL_I2C_SetOwnAddress1
  559. * @param I2Cx I2C Instance.
  560. * @param OwnAddress1 This parameter must be a value between Min_Data=0 and Max_Data=0x3FF.
  561. * @param OwnAddrSize This parameter can be one of the following values:
  562. * @arg @ref LL_I2C_OWNADDRESS1_7BIT
  563. * @arg @ref LL_I2C_OWNADDRESS1_10BIT
  564. * @retval None
  565. */
  566. __STATIC_INLINE void LL_I2C_SetOwnAddress1(I2C_TypeDef *I2Cx, uint32_t OwnAddress1, uint32_t OwnAddrSize)
  567. {
  568. MODIFY_REG(I2Cx->OAR1, I2C_OAR1_ADD0 | I2C_OAR1_ADD1_7 | I2C_OAR1_ADD8_9 | I2C_OAR1_ADDMODE, OwnAddress1 | OwnAddrSize);
  569. }
  570. /**
  571. * @brief Set the 7bits Own Address2.
  572. * @note This action has no effect if own address2 is enabled.
  573. * @rmtoll OAR2 ADD2 LL_I2C_SetOwnAddress2
  574. * @param I2Cx I2C Instance.
  575. * @param OwnAddress2 This parameter must be a value between Min_Data=0 and Max_Data=0x7F.
  576. * @retval None
  577. */
  578. __STATIC_INLINE void LL_I2C_SetOwnAddress2(I2C_TypeDef *I2Cx, uint32_t OwnAddress2)
  579. {
  580. MODIFY_REG(I2Cx->OAR2, I2C_OAR2_ADD2, OwnAddress2);
  581. }
  582. /**
  583. * @brief Enable acknowledge on Own Address2 match address.
  584. * @rmtoll OAR2 ENDUAL LL_I2C_EnableOwnAddress2
  585. * @param I2Cx I2C Instance.
  586. * @retval None
  587. */
  588. __STATIC_INLINE void LL_I2C_EnableOwnAddress2(I2C_TypeDef *I2Cx)
  589. {
  590. SET_BIT(I2Cx->OAR2, I2C_OAR2_ENDUAL);
  591. }
  592. /**
  593. * @brief Disable acknowledge on Own Address2 match address.
  594. * @rmtoll OAR2 ENDUAL LL_I2C_DisableOwnAddress2
  595. * @param I2Cx I2C Instance.
  596. * @retval None
  597. */
  598. __STATIC_INLINE void LL_I2C_DisableOwnAddress2(I2C_TypeDef *I2Cx)
  599. {
  600. CLEAR_BIT(I2Cx->OAR2, I2C_OAR2_ENDUAL);
  601. }
  602. /**
  603. * @brief Check if Own Address1 acknowledge is enabled or disabled.
  604. * @rmtoll OAR2 ENDUAL LL_I2C_IsEnabledOwnAddress2
  605. * @param I2Cx I2C Instance.
  606. * @retval State of bit (1 or 0).
  607. */
  608. __STATIC_INLINE uint32_t LL_I2C_IsEnabledOwnAddress2(I2C_TypeDef *I2Cx)
  609. {
  610. return (READ_BIT(I2Cx->OAR2, I2C_OAR2_ENDUAL) == (I2C_OAR2_ENDUAL));
  611. }
  612. /**
  613. * @brief Configure the Peripheral clock frequency.
  614. * @rmtoll CR2 FREQ LL_I2C_SetPeriphClock
  615. * @param I2Cx I2C Instance.
  616. * @param PeriphClock Peripheral Clock (in Hz)
  617. * @retval None
  618. */
  619. __STATIC_INLINE void LL_I2C_SetPeriphClock(I2C_TypeDef *I2Cx, uint32_t PeriphClock)
  620. {
  621. MODIFY_REG(I2Cx->CR2, I2C_CR2_FREQ, __LL_I2C_FREQ_HZ_TO_MHZ(PeriphClock));
  622. }
  623. /**
  624. * @brief Get the Peripheral clock frequency.
  625. * @rmtoll CR2 FREQ LL_I2C_GetPeriphClock
  626. * @param I2Cx I2C Instance.
  627. * @retval Value of Peripheral Clock (in Hz)
  628. */
  629. __STATIC_INLINE uint32_t LL_I2C_GetPeriphClock(I2C_TypeDef *I2Cx)
  630. {
  631. return (uint32_t)(__LL_I2C_FREQ_MHZ_TO_HZ(READ_BIT(I2Cx->CR2, I2C_CR2_FREQ)));
  632. }
  633. /**
  634. * @brief Configure the Duty cycle (Fast mode only).
  635. * @rmtoll CCR DUTY LL_I2C_SetDutyCycle
  636. * @param I2Cx I2C Instance.
  637. * @param DutyCycle This parameter can be one of the following values:
  638. * @arg @ref LL_I2C_DUTYCYCLE_2
  639. * @arg @ref LL_I2C_DUTYCYCLE_16_9
  640. * @retval None
  641. */
  642. __STATIC_INLINE void LL_I2C_SetDutyCycle(I2C_TypeDef *I2Cx, uint32_t DutyCycle)
  643. {
  644. MODIFY_REG(I2Cx->CCR, I2C_CCR_DUTY, DutyCycle);
  645. }
  646. /**
  647. * @brief Get the Duty cycle (Fast mode only).
  648. * @rmtoll CCR DUTY LL_I2C_GetDutyCycle
  649. * @param I2Cx I2C Instance.
  650. * @retval Returned value can be one of the following values:
  651. * @arg @ref LL_I2C_DUTYCYCLE_2
  652. * @arg @ref LL_I2C_DUTYCYCLE_16_9
  653. */
  654. __STATIC_INLINE uint32_t LL_I2C_GetDutyCycle(I2C_TypeDef *I2Cx)
  655. {
  656. return (uint32_t)(READ_BIT(I2Cx->CCR, I2C_CCR_DUTY));
  657. }
  658. /**
  659. * @brief Configure the I2C master clock speed mode.
  660. * @rmtoll CCR FS LL_I2C_SetClockSpeedMode
  661. * @param I2Cx I2C Instance.
  662. * @param ClockSpeedMode This parameter can be one of the following values:
  663. * @arg @ref LL_I2C_CLOCK_SPEED_STANDARD_MODE
  664. * @arg @ref LL_I2C_CLOCK_SPEED_FAST_MODE
  665. * @retval None
  666. */
  667. __STATIC_INLINE void LL_I2C_SetClockSpeedMode(I2C_TypeDef *I2Cx, uint32_t ClockSpeedMode)
  668. {
  669. MODIFY_REG(I2Cx->CCR, I2C_CCR_FS, ClockSpeedMode);
  670. }
  671. /**
  672. * @brief Get the the I2C master speed mode.
  673. * @rmtoll CCR FS LL_I2C_GetClockSpeedMode
  674. * @param I2Cx I2C Instance.
  675. * @retval Returned value can be one of the following values:
  676. * @arg @ref LL_I2C_CLOCK_SPEED_STANDARD_MODE
  677. * @arg @ref LL_I2C_CLOCK_SPEED_FAST_MODE
  678. */
  679. __STATIC_INLINE uint32_t LL_I2C_GetClockSpeedMode(I2C_TypeDef *I2Cx)
  680. {
  681. return (uint32_t)(READ_BIT(I2Cx->CCR, I2C_CCR_FS));
  682. }
  683. /**
  684. * @brief Configure the SCL, SDA rising time.
  685. * @note This bit can only be programmed when the I2C is disabled (PE = 0).
  686. * @rmtoll TRISE TRISE LL_I2C_SetRiseTime
  687. * @param I2Cx I2C Instance.
  688. * @param RiseTime This parameter must be a value between Min_Data=0x02 and Max_Data=0x3F.
  689. * @retval None
  690. */
  691. __STATIC_INLINE void LL_I2C_SetRiseTime(I2C_TypeDef *I2Cx, uint32_t RiseTime)
  692. {
  693. MODIFY_REG(I2Cx->TRISE, I2C_TRISE_TRISE, RiseTime);
  694. }
  695. /**
  696. * @brief Get the SCL, SDA rising time.
  697. * @rmtoll TRISE TRISE LL_I2C_GetRiseTime
  698. * @param I2Cx I2C Instance.
  699. * @retval Value between Min_Data=0x02 and Max_Data=0x3F
  700. */
  701. __STATIC_INLINE uint32_t LL_I2C_GetRiseTime(I2C_TypeDef *I2Cx)
  702. {
  703. return (uint32_t)(READ_BIT(I2Cx->TRISE, I2C_TRISE_TRISE));
  704. }
  705. /**
  706. * @brief Configure the SCL high and low period.
  707. * @note This bit can only be programmed when the I2C is disabled (PE = 0).
  708. * @rmtoll CCR CCR LL_I2C_SetClockPeriod
  709. * @param I2Cx I2C Instance.
  710. * @param ClockPeriod This parameter must be a value between Min_Data=0x004 and Max_Data=0xFFF, except in FAST DUTY mode where Min_Data=0x001.
  711. * @retval None
  712. */
  713. __STATIC_INLINE void LL_I2C_SetClockPeriod(I2C_TypeDef *I2Cx, uint32_t ClockPeriod)
  714. {
  715. MODIFY_REG(I2Cx->CCR, I2C_CCR_CCR, ClockPeriod);
  716. }
  717. /**
  718. * @brief Get the SCL high and low period.
  719. * @rmtoll CCR CCR LL_I2C_GetClockPeriod
  720. * @param I2Cx I2C Instance.
  721. * @retval Value between Min_Data=0x004 and Max_Data=0xFFF, except in FAST DUTY mode where Min_Data=0x001.
  722. */
  723. __STATIC_INLINE uint32_t LL_I2C_GetClockPeriod(I2C_TypeDef *I2Cx)
  724. {
  725. return (uint32_t)(READ_BIT(I2Cx->CCR, I2C_CCR_CCR));
  726. }
  727. /**
  728. * @brief Configure the SCL speed.
  729. * @note This bit can only be programmed when the I2C is disabled (PE = 0).
  730. * @rmtoll CR2 FREQ LL_I2C_ConfigSpeed\n
  731. * TRISE TRISE LL_I2C_ConfigSpeed\n
  732. * CCR FS LL_I2C_ConfigSpeed\n
  733. * CCR DUTY LL_I2C_ConfigSpeed\n
  734. * CCR CCR LL_I2C_ConfigSpeed
  735. * @param I2Cx I2C Instance.
  736. * @param PeriphClock Peripheral Clock (in Hz)
  737. * @param ClockSpeed This parameter must be a value lower than 400kHz (in Hz).
  738. * @param DutyCycle This parameter can be one of the following values:
  739. * @arg @ref LL_I2C_DUTYCYCLE_2
  740. * @arg @ref LL_I2C_DUTYCYCLE_16_9
  741. * @retval None
  742. */
  743. __STATIC_INLINE void LL_I2C_ConfigSpeed(I2C_TypeDef *I2Cx, uint32_t PeriphClock, uint32_t ClockSpeed,
  744. uint32_t DutyCycle)
  745. {
  746. register uint32_t freqrange = 0x0U;
  747. register uint32_t clockconfig = 0x0U;
  748. /* Compute frequency range */
  749. freqrange = __LL_I2C_FREQ_HZ_TO_MHZ(PeriphClock);
  750. /* Configure I2Cx: Frequency range register */
  751. MODIFY_REG(I2Cx->CR2, I2C_CR2_FREQ, freqrange);
  752. /* Configure I2Cx: Rise Time register */
  753. MODIFY_REG(I2Cx->TRISE, I2C_TRISE_TRISE, __LL_I2C_RISE_TIME(freqrange, ClockSpeed));
  754. /* Configure Speed mode, Duty Cycle and Clock control register value */
  755. if (ClockSpeed > LL_I2C_MAX_SPEED_STANDARD)
  756. {
  757. /* Set Speed mode at fast and duty cycle for Clock Speed request in fast clock range */
  758. clockconfig = LL_I2C_CLOCK_SPEED_FAST_MODE | \
  759. __LL_I2C_SPEED_FAST_TO_CCR(PeriphClock, ClockSpeed, DutyCycle) | \
  760. DutyCycle;
  761. }
  762. else
  763. {
  764. /* Set Speed mode at standard for Clock Speed request in standard clock range */
  765. clockconfig = LL_I2C_CLOCK_SPEED_STANDARD_MODE | \
  766. __LL_I2C_SPEED_STANDARD_TO_CCR(PeriphClock, ClockSpeed);
  767. }
  768. /* Configure I2Cx: Clock control register */
  769. MODIFY_REG(I2Cx->CCR, (I2C_CCR_FS | I2C_CCR_DUTY | I2C_CCR_CCR), clockconfig);
  770. }
  771. /**
  772. * @brief Configure peripheral mode.
  773. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  774. * SMBus feature is supported by the I2Cx Instance.
  775. * @rmtoll CR1 SMBUS LL_I2C_SetMode\n
  776. * CR1 SMBTYPE LL_I2C_SetMode\n
  777. * CR1 ENARP LL_I2C_SetMode
  778. * @param I2Cx I2C Instance.
  779. * @param PeripheralMode This parameter can be one of the following values:
  780. * @arg @ref LL_I2C_MODE_I2C
  781. * @arg @ref LL_I2C_MODE_SMBUS_HOST
  782. * @arg @ref LL_I2C_MODE_SMBUS_DEVICE
  783. * @arg @ref LL_I2C_MODE_SMBUS_DEVICE_ARP
  784. * @retval None
  785. */
  786. __STATIC_INLINE void LL_I2C_SetMode(I2C_TypeDef *I2Cx, uint32_t PeripheralMode)
  787. {
  788. MODIFY_REG(I2Cx->CR1, I2C_CR1_SMBUS | I2C_CR1_SMBTYPE | I2C_CR1_ENARP, PeripheralMode);
  789. }
  790. /**
  791. * @brief Get peripheral mode.
  792. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  793. * SMBus feature is supported by the I2Cx Instance.
  794. * @rmtoll CR1 SMBUS LL_I2C_GetMode\n
  795. * CR1 SMBTYPE LL_I2C_GetMode\n
  796. * CR1 ENARP LL_I2C_GetMode
  797. * @param I2Cx I2C Instance.
  798. * @retval Returned value can be one of the following values:
  799. * @arg @ref LL_I2C_MODE_I2C
  800. * @arg @ref LL_I2C_MODE_SMBUS_HOST
  801. * @arg @ref LL_I2C_MODE_SMBUS_DEVICE
  802. * @arg @ref LL_I2C_MODE_SMBUS_DEVICE_ARP
  803. */
  804. __STATIC_INLINE uint32_t LL_I2C_GetMode(I2C_TypeDef *I2Cx)
  805. {
  806. return (uint32_t)(READ_BIT(I2Cx->CR1, I2C_CR1_SMBUS | I2C_CR1_SMBTYPE | I2C_CR1_ENARP));
  807. }
  808. /**
  809. * @brief Enable SMBus alert (Host or Device mode)
  810. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  811. * SMBus feature is supported by the I2Cx Instance.
  812. * @note SMBus Device mode:
  813. * - SMBus Alert pin is drived low and
  814. * Alert Response Address Header acknowledge is enabled.
  815. * SMBus Host mode:
  816. * - SMBus Alert pin management is supported.
  817. * @rmtoll CR1 ALERT LL_I2C_EnableSMBusAlert
  818. * @param I2Cx I2C Instance.
  819. * @retval None
  820. */
  821. __STATIC_INLINE void LL_I2C_EnableSMBusAlert(I2C_TypeDef *I2Cx)
  822. {
  823. SET_BIT(I2Cx->CR1, I2C_CR1_ALERT);
  824. }
  825. /**
  826. * @brief Disable SMBus alert (Host or Device mode)
  827. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  828. * SMBus feature is supported by the I2Cx Instance.
  829. * @note SMBus Device mode:
  830. * - SMBus Alert pin is not drived (can be used as a standard GPIO) and
  831. * Alert Response Address Header acknowledge is disabled.
  832. * SMBus Host mode:
  833. * - SMBus Alert pin management is not supported.
  834. * @rmtoll CR1 ALERT LL_I2C_DisableSMBusAlert
  835. * @param I2Cx I2C Instance.
  836. * @retval None
  837. */
  838. __STATIC_INLINE void LL_I2C_DisableSMBusAlert(I2C_TypeDef *I2Cx)
  839. {
  840. CLEAR_BIT(I2Cx->CR1, I2C_CR1_ALERT);
  841. }
  842. /**
  843. * @brief Check if SMBus alert (Host or Device mode) is enabled or disabled.
  844. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  845. * SMBus feature is supported by the I2Cx Instance.
  846. * @rmtoll CR1 ALERT LL_I2C_IsEnabledSMBusAlert
  847. * @param I2Cx I2C Instance.
  848. * @retval State of bit (1 or 0).
  849. */
  850. __STATIC_INLINE uint32_t LL_I2C_IsEnabledSMBusAlert(I2C_TypeDef *I2Cx)
  851. {
  852. return (READ_BIT(I2Cx->CR1, I2C_CR1_ALERT) == (I2C_CR1_ALERT));
  853. }
  854. /**
  855. * @brief Enable SMBus Packet Error Calculation (PEC).
  856. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  857. * SMBus feature is supported by the I2Cx Instance.
  858. * @rmtoll CR1 ENPEC LL_I2C_EnableSMBusPEC
  859. * @param I2Cx I2C Instance.
  860. * @retval None
  861. */
  862. __STATIC_INLINE void LL_I2C_EnableSMBusPEC(I2C_TypeDef *I2Cx)
  863. {
  864. SET_BIT(I2Cx->CR1, I2C_CR1_ENPEC);
  865. }
  866. /**
  867. * @brief Disable SMBus Packet Error Calculation (PEC).
  868. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  869. * SMBus feature is supported by the I2Cx Instance.
  870. * @rmtoll CR1 ENPEC LL_I2C_DisableSMBusPEC
  871. * @param I2Cx I2C Instance.
  872. * @retval None
  873. */
  874. __STATIC_INLINE void LL_I2C_DisableSMBusPEC(I2C_TypeDef *I2Cx)
  875. {
  876. CLEAR_BIT(I2Cx->CR1, I2C_CR1_ENPEC);
  877. }
  878. /**
  879. * @brief Check if SMBus Packet Error Calculation (PEC) is enabled or disabled.
  880. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  881. * SMBus feature is supported by the I2Cx Instance.
  882. * @rmtoll CR1 ENPEC LL_I2C_IsEnabledSMBusPEC
  883. * @param I2Cx I2C Instance.
  884. * @retval State of bit (1 or 0).
  885. */
  886. __STATIC_INLINE uint32_t LL_I2C_IsEnabledSMBusPEC(I2C_TypeDef *I2Cx)
  887. {
  888. return (READ_BIT(I2Cx->CR1, I2C_CR1_ENPEC) == (I2C_CR1_ENPEC));
  889. }
  890. /**
  891. * @}
  892. */
  893. /** @defgroup I2C_LL_EF_IT_Management IT_Management
  894. * @{
  895. */
  896. /**
  897. * @brief Enable TXE interrupt.
  898. * @rmtoll CR2 ITEVTEN LL_I2C_EnableIT_TX\n
  899. * CR2 ITBUFEN LL_I2C_EnableIT_TX
  900. * @param I2Cx I2C Instance.
  901. * @retval None
  902. */
  903. __STATIC_INLINE void LL_I2C_EnableIT_TX(I2C_TypeDef *I2Cx)
  904. {
  905. SET_BIT(I2Cx->CR2, I2C_CR2_ITEVTEN | I2C_CR2_ITBUFEN);
  906. }
  907. /**
  908. * @brief Disable TXE interrupt.
  909. * @rmtoll CR2 ITEVTEN LL_I2C_DisableIT_TX\n
  910. * CR2 ITBUFEN LL_I2C_DisableIT_TX
  911. * @param I2Cx I2C Instance.
  912. * @retval None
  913. */
  914. __STATIC_INLINE void LL_I2C_DisableIT_TX(I2C_TypeDef *I2Cx)
  915. {
  916. CLEAR_BIT(I2Cx->CR2, I2C_CR2_ITEVTEN | I2C_CR2_ITBUFEN);
  917. }
  918. /**
  919. * @brief Check if the TXE Interrupt is enabled or disabled.
  920. * @rmtoll CR2 ITEVTEN LL_I2C_IsEnabledIT_TX\n
  921. * CR2 ITBUFEN LL_I2C_IsEnabledIT_TX
  922. * @param I2Cx I2C Instance.
  923. * @retval State of bit (1 or 0).
  924. */
  925. __STATIC_INLINE uint32_t LL_I2C_IsEnabledIT_TX(I2C_TypeDef *I2Cx)
  926. {
  927. return (READ_BIT(I2Cx->CR2, I2C_CR2_ITEVTEN | I2C_CR2_ITBUFEN) == (I2C_CR2_ITEVTEN | I2C_CR2_ITBUFEN));
  928. }
  929. /**
  930. * @brief Enable RXNE interrupt.
  931. * @rmtoll CR2 ITEVTEN LL_I2C_EnableIT_RX\n
  932. * CR2 ITBUFEN LL_I2C_EnableIT_RX
  933. * @param I2Cx I2C Instance.
  934. * @retval None
  935. */
  936. __STATIC_INLINE void LL_I2C_EnableIT_RX(I2C_TypeDef *I2Cx)
  937. {
  938. SET_BIT(I2Cx->CR2, I2C_CR2_ITEVTEN | I2C_CR2_ITBUFEN);
  939. }
  940. /**
  941. * @brief Disable RXNE interrupt.
  942. * @rmtoll CR2 ITEVTEN LL_I2C_DisableIT_RX\n
  943. * CR2 ITBUFEN LL_I2C_DisableIT_RX
  944. * @param I2Cx I2C Instance.
  945. * @retval None
  946. */
  947. __STATIC_INLINE void LL_I2C_DisableIT_RX(I2C_TypeDef *I2Cx)
  948. {
  949. CLEAR_BIT(I2Cx->CR2, I2C_CR2_ITEVTEN | I2C_CR2_ITBUFEN);
  950. }
  951. /**
  952. * @brief Check if the RXNE Interrupt is enabled or disabled.
  953. * @rmtoll CR2 ITEVTEN LL_I2C_IsEnabledIT_RX\n
  954. * CR2 ITBUFEN LL_I2C_IsEnabledIT_RX
  955. * @param I2Cx I2C Instance.
  956. * @retval State of bit (1 or 0).
  957. */
  958. __STATIC_INLINE uint32_t LL_I2C_IsEnabledIT_RX(I2C_TypeDef *I2Cx)
  959. {
  960. return (READ_BIT(I2Cx->CR2, I2C_CR2_ITEVTEN | I2C_CR2_ITBUFEN) == (I2C_CR2_ITEVTEN | I2C_CR2_ITBUFEN));
  961. }
  962. /**
  963. * @brief Enable Events interrupts.
  964. * @note Any of these events will generate interrupt :
  965. * Start Bit (SB)
  966. * Address sent, Address matched (ADDR)
  967. * 10-bit header sent (ADD10)
  968. * Stop detection (STOPF)
  969. * Byte transfer finished (BTF)
  970. *
  971. * @note Any of these events will generate interrupt if Buffer interrupts are enabled too(using unitary function @ref LL_I2C_EnableIT_BUF()) :
  972. * Receive buffer not empty (RXNE)
  973. * Transmit buffer empty (TXE)
  974. * @rmtoll CR2 ITEVTEN LL_I2C_EnableIT_EVT
  975. * @param I2Cx I2C Instance.
  976. * @retval None
  977. */
  978. __STATIC_INLINE void LL_I2C_EnableIT_EVT(I2C_TypeDef *I2Cx)
  979. {
  980. SET_BIT(I2Cx->CR2, I2C_CR2_ITEVTEN);
  981. }
  982. /**
  983. * @brief Disable Events interrupts.
  984. * @note Any of these events will generate interrupt :
  985. * Start Bit (SB)
  986. * Address sent, Address matched (ADDR)
  987. * 10-bit header sent (ADD10)
  988. * Stop detection (STOPF)
  989. * Byte transfer finished (BTF)
  990. * Receive buffer not empty (RXNE)
  991. * Transmit buffer empty (TXE)
  992. * @rmtoll CR2 ITEVTEN LL_I2C_DisableIT_EVT
  993. * @param I2Cx I2C Instance.
  994. * @retval None
  995. */
  996. __STATIC_INLINE void LL_I2C_DisableIT_EVT(I2C_TypeDef *I2Cx)
  997. {
  998. CLEAR_BIT(I2Cx->CR2, I2C_CR2_ITEVTEN);
  999. }
  1000. /**
  1001. * @brief Check if Events interrupts are enabled or disabled.
  1002. * @rmtoll CR2 ITEVTEN LL_I2C_IsEnabledIT_EVT
  1003. * @param I2Cx I2C Instance.
  1004. * @retval State of bit (1 or 0).
  1005. */
  1006. __STATIC_INLINE uint32_t LL_I2C_IsEnabledIT_EVT(I2C_TypeDef *I2Cx)
  1007. {
  1008. return (READ_BIT(I2Cx->CR2, I2C_CR2_ITEVTEN) == (I2C_CR2_ITEVTEN));
  1009. }
  1010. /**
  1011. * @brief Enable Buffer interrupts.
  1012. * @note Any of these Buffer events will generate interrupt if Events interrupts are enabled too(using unitary function @ref LL_I2C_EnableIT_EVT()) :
  1013. * Receive buffer not empty (RXNE)
  1014. * Transmit buffer empty (TXE)
  1015. * @rmtoll CR2 ITBUFEN LL_I2C_EnableIT_BUF
  1016. * @param I2Cx I2C Instance.
  1017. * @retval None
  1018. */
  1019. __STATIC_INLINE void LL_I2C_EnableIT_BUF(I2C_TypeDef *I2Cx)
  1020. {
  1021. SET_BIT(I2Cx->CR2, I2C_CR2_ITBUFEN);
  1022. }
  1023. /**
  1024. * @brief Disable Buffer interrupts.
  1025. * @note Any of these Buffer events will generate interrupt :
  1026. * Receive buffer not empty (RXNE)
  1027. * Transmit buffer empty (TXE)
  1028. * @rmtoll CR2 ITBUFEN LL_I2C_DisableIT_BUF
  1029. * @param I2Cx I2C Instance.
  1030. * @retval None
  1031. */
  1032. __STATIC_INLINE void LL_I2C_DisableIT_BUF(I2C_TypeDef *I2Cx)
  1033. {
  1034. CLEAR_BIT(I2Cx->CR2, I2C_CR2_ITBUFEN);
  1035. }
  1036. /**
  1037. * @brief Check if Buffer interrupts are enabled or disabled.
  1038. * @rmtoll CR2 ITBUFEN LL_I2C_IsEnabledIT_BUF
  1039. * @param I2Cx I2C Instance.
  1040. * @retval State of bit (1 or 0).
  1041. */
  1042. __STATIC_INLINE uint32_t LL_I2C_IsEnabledIT_BUF(I2C_TypeDef *I2Cx)
  1043. {
  1044. return (READ_BIT(I2Cx->CR2, I2C_CR2_ITBUFEN) == (I2C_CR2_ITBUFEN));
  1045. }
  1046. /**
  1047. * @brief Enable Error interrupts.
  1048. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1049. * SMBus feature is supported by the I2Cx Instance.
  1050. * @note Any of these errors will generate interrupt :
  1051. * Bus Error detection (BERR)
  1052. * Arbitration Loss (ARLO)
  1053. * Acknowledge Failure(AF)
  1054. * Overrun/Underrun (OVR)
  1055. * SMBus Timeout detection (TIMEOUT)
  1056. * SMBus PEC error detection (PECERR)
  1057. * SMBus Alert pin event detection (SMBALERT)
  1058. * @rmtoll CR2 ITERREN LL_I2C_EnableIT_ERR
  1059. * @param I2Cx I2C Instance.
  1060. * @retval None
  1061. */
  1062. __STATIC_INLINE void LL_I2C_EnableIT_ERR(I2C_TypeDef *I2Cx)
  1063. {
  1064. SET_BIT(I2Cx->CR2, I2C_CR2_ITERREN);
  1065. }
  1066. /**
  1067. * @brief Disable Error interrupts.
  1068. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1069. * SMBus feature is supported by the I2Cx Instance.
  1070. * @note Any of these errors will generate interrupt :
  1071. * Bus Error detection (BERR)
  1072. * Arbitration Loss (ARLO)
  1073. * Acknowledge Failure(AF)
  1074. * Overrun/Underrun (OVR)
  1075. * SMBus Timeout detection (TIMEOUT)
  1076. * SMBus PEC error detection (PECERR)
  1077. * SMBus Alert pin event detection (SMBALERT)
  1078. * @rmtoll CR2 ITERREN LL_I2C_DisableIT_ERR
  1079. * @param I2Cx I2C Instance.
  1080. * @retval None
  1081. */
  1082. __STATIC_INLINE void LL_I2C_DisableIT_ERR(I2C_TypeDef *I2Cx)
  1083. {
  1084. CLEAR_BIT(I2Cx->CR2, I2C_CR2_ITERREN);
  1085. }
  1086. /**
  1087. * @brief Check if Error interrupts are enabled or disabled.
  1088. * @rmtoll CR2 ITERREN LL_I2C_IsEnabledIT_ERR
  1089. * @param I2Cx I2C Instance.
  1090. * @retval State of bit (1 or 0).
  1091. */
  1092. __STATIC_INLINE uint32_t LL_I2C_IsEnabledIT_ERR(I2C_TypeDef *I2Cx)
  1093. {
  1094. return (READ_BIT(I2Cx->CR2, I2C_CR2_ITERREN) == (I2C_CR2_ITERREN));
  1095. }
  1096. /**
  1097. * @}
  1098. */
  1099. /** @defgroup I2C_LL_EF_FLAG_management FLAG_management
  1100. * @{
  1101. */
  1102. /**
  1103. * @brief Indicate the status of Transmit data register empty flag.
  1104. * @note RESET: When next data is written in Transmit data register.
  1105. * SET: When Transmit data register is empty.
  1106. * @rmtoll SR1 TXE LL_I2C_IsActiveFlag_TXE
  1107. * @param I2Cx I2C Instance.
  1108. * @retval State of bit (1 or 0).
  1109. */
  1110. __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_TXE(I2C_TypeDef *I2Cx)
  1111. {
  1112. return (READ_BIT(I2Cx->SR1, I2C_SR1_TXE) == (I2C_SR1_TXE));
  1113. }
  1114. /**
  1115. * @brief Indicate the status of Byte Transfer Finished flag.
  1116. * RESET: When Data byte transfer not done.
  1117. * SET: When Data byte transfer succeeded.
  1118. * @rmtoll SR1 BTF LL_I2C_IsActiveFlag_BTF
  1119. * @param I2Cx I2C Instance.
  1120. * @retval State of bit (1 or 0).
  1121. */
  1122. __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_BTF(I2C_TypeDef *I2Cx)
  1123. {
  1124. return (READ_BIT(I2Cx->SR1, I2C_SR1_BTF) == (I2C_SR1_BTF));
  1125. }
  1126. /**
  1127. * @brief Indicate the status of Receive data register not empty flag.
  1128. * @note RESET: When Receive data register is read.
  1129. * SET: When the received data is copied in Receive data register.
  1130. * @rmtoll SR1 RXNE LL_I2C_IsActiveFlag_RXNE
  1131. * @param I2Cx I2C Instance.
  1132. * @retval State of bit (1 or 0).
  1133. */
  1134. __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_RXNE(I2C_TypeDef *I2Cx)
  1135. {
  1136. return (READ_BIT(I2Cx->SR1, I2C_SR1_RXNE) == (I2C_SR1_RXNE));
  1137. }
  1138. /**
  1139. * @brief Indicate the status of Start Bit (master mode).
  1140. * @note RESET: When No Start condition.
  1141. * SET: When Start condition is generated.
  1142. * @rmtoll SR1 SB LL_I2C_IsActiveFlag_SB
  1143. * @param I2Cx I2C Instance.
  1144. * @retval State of bit (1 or 0).
  1145. */
  1146. __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_SB(I2C_TypeDef *I2Cx)
  1147. {
  1148. return (READ_BIT(I2Cx->SR1, I2C_SR1_SB) == (I2C_SR1_SB));
  1149. }
  1150. /**
  1151. * @brief Indicate the status of Address sent (master mode) or Address matched flag (slave mode).
  1152. * @note RESET: Clear default value.
  1153. * SET: When the address is fully sent (master mode) or when the received slave address matched with one of the enabled slave address (slave mode).
  1154. * @rmtoll SR1 ADDR LL_I2C_IsActiveFlag_ADDR
  1155. * @param I2Cx I2C Instance.
  1156. * @retval State of bit (1 or 0).
  1157. */
  1158. __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_ADDR(I2C_TypeDef *I2Cx)
  1159. {
  1160. return (READ_BIT(I2Cx->SR1, I2C_SR1_ADDR) == (I2C_SR1_ADDR));
  1161. }
  1162. /**
  1163. * @brief Indicate the status of 10-bit header sent (master mode).
  1164. * @note RESET: When no ADD10 event occurred.
  1165. * SET: When the master has sent the first address byte (header).
  1166. * @rmtoll SR1 ADD10 LL_I2C_IsActiveFlag_ADD10
  1167. * @param I2Cx I2C Instance.
  1168. * @retval State of bit (1 or 0).
  1169. */
  1170. __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_ADD10(I2C_TypeDef *I2Cx)
  1171. {
  1172. return (READ_BIT(I2Cx->SR1, I2C_SR1_ADD10) == (I2C_SR1_ADD10));
  1173. }
  1174. /**
  1175. * @brief Indicate the status of Acknowledge failure flag.
  1176. * @note RESET: No acknowledge failure.
  1177. * SET: When an acknowledge failure is received after a byte transmission.
  1178. * @rmtoll SR1 AF LL_I2C_IsActiveFlag_AF
  1179. * @param I2Cx I2C Instance.
  1180. * @retval State of bit (1 or 0).
  1181. */
  1182. __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_AF(I2C_TypeDef *I2Cx)
  1183. {
  1184. return (READ_BIT(I2Cx->SR1, I2C_SR1_AF) == (I2C_SR1_AF));
  1185. }
  1186. /**
  1187. * @brief Indicate the status of Stop detection flag (slave mode).
  1188. * @note RESET: Clear default value.
  1189. * SET: When a Stop condition is detected.
  1190. * @rmtoll SR1 STOPF LL_I2C_IsActiveFlag_STOP
  1191. * @param I2Cx I2C Instance.
  1192. * @retval State of bit (1 or 0).
  1193. */
  1194. __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_STOP(I2C_TypeDef *I2Cx)
  1195. {
  1196. return (READ_BIT(I2Cx->SR1, I2C_SR1_STOPF) == (I2C_SR1_STOPF));
  1197. }
  1198. /**
  1199. * @brief Indicate the status of Bus error flag.
  1200. * @note RESET: Clear default value.
  1201. * SET: When a misplaced Start or Stop condition is detected.
  1202. * @rmtoll SR1 BERR LL_I2C_IsActiveFlag_BERR
  1203. * @param I2Cx I2C Instance.
  1204. * @retval State of bit (1 or 0).
  1205. */
  1206. __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_BERR(I2C_TypeDef *I2Cx)
  1207. {
  1208. return (READ_BIT(I2Cx->SR1, I2C_SR1_BERR) == (I2C_SR1_BERR));
  1209. }
  1210. /**
  1211. * @brief Indicate the status of Arbitration lost flag.
  1212. * @note RESET: Clear default value.
  1213. * SET: When arbitration lost.
  1214. * @rmtoll SR1 ARLO LL_I2C_IsActiveFlag_ARLO
  1215. * @param I2Cx I2C Instance.
  1216. * @retval State of bit (1 or 0).
  1217. */
  1218. __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_ARLO(I2C_TypeDef *I2Cx)
  1219. {
  1220. return (READ_BIT(I2Cx->SR1, I2C_SR1_ARLO) == (I2C_SR1_ARLO));
  1221. }
  1222. /**
  1223. * @brief Indicate the status of Overrun/Underrun flag.
  1224. * @note RESET: Clear default value.
  1225. * SET: When an overrun/underrun error occurs (Clock Stretching Disabled).
  1226. * @rmtoll SR1 OVR LL_I2C_IsActiveFlag_OVR
  1227. * @param I2Cx I2C Instance.
  1228. * @retval State of bit (1 or 0).
  1229. */
  1230. __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_OVR(I2C_TypeDef *I2Cx)
  1231. {
  1232. return (READ_BIT(I2Cx->SR1, I2C_SR1_OVR) == (I2C_SR1_OVR));
  1233. }
  1234. /**
  1235. * @brief Indicate the status of SMBus PEC error flag in reception.
  1236. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1237. * SMBus feature is supported by the I2Cx Instance.
  1238. * @rmtoll SR1 PECERR LL_I2C_IsActiveSMBusFlag_PECERR
  1239. * @param I2Cx I2C Instance.
  1240. * @retval State of bit (1 or 0).
  1241. */
  1242. __STATIC_INLINE uint32_t LL_I2C_IsActiveSMBusFlag_PECERR(I2C_TypeDef *I2Cx)
  1243. {
  1244. return (READ_BIT(I2Cx->SR1, I2C_SR1_PECERR) == (I2C_SR1_PECERR));
  1245. }
  1246. /**
  1247. * @brief Indicate the status of SMBus Timeout detection flag.
  1248. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1249. * SMBus feature is supported by the I2Cx Instance.
  1250. * @rmtoll SR1 TIMEOUT LL_I2C_IsActiveSMBusFlag_TIMEOUT
  1251. * @param I2Cx I2C Instance.
  1252. * @retval State of bit (1 or 0).
  1253. */
  1254. __STATIC_INLINE uint32_t LL_I2C_IsActiveSMBusFlag_TIMEOUT(I2C_TypeDef *I2Cx)
  1255. {
  1256. return (READ_BIT(I2Cx->SR1, I2C_SR1_TIMEOUT) == (I2C_SR1_TIMEOUT));
  1257. }
  1258. /**
  1259. * @brief Indicate the status of SMBus alert flag.
  1260. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1261. * SMBus feature is supported by the I2Cx Instance.
  1262. * @rmtoll SR1 SMBALERT LL_I2C_IsActiveSMBusFlag_ALERT
  1263. * @param I2Cx I2C Instance.
  1264. * @retval State of bit (1 or 0).
  1265. */
  1266. __STATIC_INLINE uint32_t LL_I2C_IsActiveSMBusFlag_ALERT(I2C_TypeDef *I2Cx)
  1267. {
  1268. return (READ_BIT(I2Cx->SR1, I2C_SR1_SMBALERT) == (I2C_SR1_SMBALERT));
  1269. }
  1270. /**
  1271. * @brief Indicate the status of Bus Busy flag.
  1272. * @note RESET: Clear default value.
  1273. * SET: When a Start condition is detected.
  1274. * @rmtoll SR2 BUSY LL_I2C_IsActiveFlag_BUSY
  1275. * @param I2Cx I2C Instance.
  1276. * @retval State of bit (1 or 0).
  1277. */
  1278. __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_BUSY(I2C_TypeDef *I2Cx)
  1279. {
  1280. return (READ_BIT(I2Cx->SR2, I2C_SR2_BUSY) == (I2C_SR2_BUSY));
  1281. }
  1282. /**
  1283. * @brief Indicate the status of Dual flag.
  1284. * @note RESET: Received address matched with OAR1.
  1285. * SET: Received address matched with OAR2.
  1286. * @rmtoll SR2 DUALF LL_I2C_IsActiveFlag_DUAL
  1287. * @param I2Cx I2C Instance.
  1288. * @retval State of bit (1 or 0).
  1289. */
  1290. __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_DUAL(I2C_TypeDef *I2Cx)
  1291. {
  1292. return (READ_BIT(I2Cx->SR2, I2C_SR2_DUALF) == (I2C_SR2_DUALF));
  1293. }
  1294. /**
  1295. * @brief Indicate the status of SMBus Host address reception (Slave mode).
  1296. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1297. * SMBus feature is supported by the I2Cx Instance.
  1298. * @note RESET: No SMBus Host address
  1299. * SET: SMBus Host address received.
  1300. * @note This status is cleared by hardware after a STOP condition or repeated START condition.
  1301. * @rmtoll SR2 SMBHOST LL_I2C_IsActiveSMBusFlag_SMBHOST
  1302. * @param I2Cx I2C Instance.
  1303. * @retval State of bit (1 or 0).
  1304. */
  1305. __STATIC_INLINE uint32_t LL_I2C_IsActiveSMBusFlag_SMBHOST(I2C_TypeDef *I2Cx)
  1306. {
  1307. return (READ_BIT(I2Cx->SR2, I2C_SR2_SMBHOST) == (I2C_SR2_SMBHOST));
  1308. }
  1309. /**
  1310. * @brief Indicate the status of SMBus Device default address reception (Slave mode).
  1311. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1312. * SMBus feature is supported by the I2Cx Instance.
  1313. * @note RESET: No SMBus Device default address
  1314. * SET: SMBus Device default address received.
  1315. * @note This status is cleared by hardware after a STOP condition or repeated START condition.
  1316. * @rmtoll SR2 SMBDEFAULT LL_I2C_IsActiveSMBusFlag_SMBDEFAULT
  1317. * @param I2Cx I2C Instance.
  1318. * @retval State of bit (1 or 0).
  1319. */
  1320. __STATIC_INLINE uint32_t LL_I2C_IsActiveSMBusFlag_SMBDEFAULT(I2C_TypeDef *I2Cx)
  1321. {
  1322. return (READ_BIT(I2Cx->SR2, I2C_SR2_SMBDEFAULT) == (I2C_SR2_SMBDEFAULT));
  1323. }
  1324. /**
  1325. * @brief Indicate the status of General call address reception (Slave mode).
  1326. * @note RESET: No Generall call address
  1327. * SET: General call address received.
  1328. * @note This status is cleared by hardware after a STOP condition or repeated START condition.
  1329. * @rmtoll SR2 GENCALL LL_I2C_IsActiveFlag_GENCALL
  1330. * @param I2Cx I2C Instance.
  1331. * @retval State of bit (1 or 0).
  1332. */
  1333. __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_GENCALL(I2C_TypeDef *I2Cx)
  1334. {
  1335. return (READ_BIT(I2Cx->SR2, I2C_SR2_GENCALL) == (I2C_SR2_GENCALL));
  1336. }
  1337. /**
  1338. * @brief Indicate the status of Master/Slave flag.
  1339. * @note RESET: Slave Mode.
  1340. * SET: Master Mode.
  1341. * @rmtoll SR2 MSL LL_I2C_IsActiveFlag_MSL
  1342. * @param I2Cx I2C Instance.
  1343. * @retval State of bit (1 or 0).
  1344. */
  1345. __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_MSL(I2C_TypeDef *I2Cx)
  1346. {
  1347. return (READ_BIT(I2Cx->SR2, I2C_SR2_MSL) == (I2C_SR2_MSL));
  1348. }
  1349. /**
  1350. * @brief Clear Address Matched flag.
  1351. * @note Clearing this flag is done by a read access to the I2Cx_SR1
  1352. * register followed by a read access to the I2Cx_SR2 register.
  1353. * @rmtoll SR1 ADDR LL_I2C_ClearFlag_ADDR
  1354. * @param I2Cx I2C Instance.
  1355. * @retval None
  1356. */
  1357. __STATIC_INLINE void LL_I2C_ClearFlag_ADDR(I2C_TypeDef *I2Cx)
  1358. {
  1359. __IO uint32_t tmpreg;
  1360. tmpreg = I2Cx->SR1;
  1361. (void) tmpreg;
  1362. tmpreg = I2Cx->SR2;
  1363. (void) tmpreg;
  1364. }
  1365. /**
  1366. * @brief Clear Acknowledge failure flag.
  1367. * @rmtoll SR1 AF LL_I2C_ClearFlag_AF
  1368. * @param I2Cx I2C Instance.
  1369. * @retval None
  1370. */
  1371. __STATIC_INLINE void LL_I2C_ClearFlag_AF(I2C_TypeDef *I2Cx)
  1372. {
  1373. CLEAR_BIT(I2Cx->SR1, I2C_SR1_AF);
  1374. }
  1375. /**
  1376. * @brief Clear Stop detection flag.
  1377. * @note Clearing this flag is done by a read access to the I2Cx_SR1
  1378. * register followed by a write access to I2Cx_CR1 register.
  1379. * @rmtoll SR1 STOPF LL_I2C_ClearFlag_STOP\n
  1380. * CR1 PE LL_I2C_ClearFlag_STOP
  1381. * @param I2Cx I2C Instance.
  1382. * @retval None
  1383. */
  1384. __STATIC_INLINE void LL_I2C_ClearFlag_STOP(I2C_TypeDef *I2Cx)
  1385. {
  1386. __IO uint32_t tmpreg;
  1387. tmpreg = I2Cx->SR1;
  1388. (void) tmpreg;
  1389. SET_BIT(I2Cx->CR1, I2C_CR1_PE);
  1390. }
  1391. /**
  1392. * @brief Clear Bus error flag.
  1393. * @rmtoll SR1 BERR LL_I2C_ClearFlag_BERR
  1394. * @param I2Cx I2C Instance.
  1395. * @retval None
  1396. */
  1397. __STATIC_INLINE void LL_I2C_ClearFlag_BERR(I2C_TypeDef *I2Cx)
  1398. {
  1399. CLEAR_BIT(I2Cx->SR1, I2C_SR1_BERR);
  1400. }
  1401. /**
  1402. * @brief Clear Arbitration lost flag.
  1403. * @rmtoll SR1 ARLO LL_I2C_ClearFlag_ARLO
  1404. * @param I2Cx I2C Instance.
  1405. * @retval None
  1406. */
  1407. __STATIC_INLINE void LL_I2C_ClearFlag_ARLO(I2C_TypeDef *I2Cx)
  1408. {
  1409. CLEAR_BIT(I2Cx->SR1, I2C_SR1_ARLO);
  1410. }
  1411. /**
  1412. * @brief Clear Overrun/Underrun flag.
  1413. * @rmtoll SR1 OVR LL_I2C_ClearFlag_OVR
  1414. * @param I2Cx I2C Instance.
  1415. * @retval None
  1416. */
  1417. __STATIC_INLINE void LL_I2C_ClearFlag_OVR(I2C_TypeDef *I2Cx)
  1418. {
  1419. CLEAR_BIT(I2Cx->SR1, I2C_SR1_OVR);
  1420. }
  1421. /**
  1422. * @brief Clear SMBus PEC error flag.
  1423. * @rmtoll SR1 PECERR LL_I2C_ClearSMBusFlag_PECERR
  1424. * @param I2Cx I2C Instance.
  1425. * @retval None
  1426. */
  1427. __STATIC_INLINE void LL_I2C_ClearSMBusFlag_PECERR(I2C_TypeDef *I2Cx)
  1428. {
  1429. CLEAR_BIT(I2Cx->SR1, I2C_SR1_PECERR);
  1430. }
  1431. /**
  1432. * @brief Clear SMBus Timeout detection flag.
  1433. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1434. * SMBus feature is supported by the I2Cx Instance.
  1435. * @rmtoll SR1 TIMEOUT LL_I2C_ClearSMBusFlag_TIMEOUT
  1436. * @param I2Cx I2C Instance.
  1437. * @retval None
  1438. */
  1439. __STATIC_INLINE void LL_I2C_ClearSMBusFlag_TIMEOUT(I2C_TypeDef *I2Cx)
  1440. {
  1441. CLEAR_BIT(I2Cx->SR1, I2C_SR1_TIMEOUT);
  1442. }
  1443. /**
  1444. * @brief Clear SMBus Alert flag.
  1445. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1446. * SMBus feature is supported by the I2Cx Instance.
  1447. * @rmtoll SR1 SMBALERT LL_I2C_ClearSMBusFlag_ALERT
  1448. * @param I2Cx I2C Instance.
  1449. * @retval None
  1450. */
  1451. __STATIC_INLINE void LL_I2C_ClearSMBusFlag_ALERT(I2C_TypeDef *I2Cx)
  1452. {
  1453. CLEAR_BIT(I2Cx->SR1, I2C_SR1_SMBALERT);
  1454. }
  1455. /**
  1456. * @}
  1457. */
  1458. /** @defgroup I2C_LL_EF_Data_Management Data_Management
  1459. * @{
  1460. */
  1461. /**
  1462. * @brief Enable Reset of I2C peripheral.
  1463. * @rmtoll CR1 SWRST LL_I2C_EnableReset
  1464. * @param I2Cx I2C Instance.
  1465. * @retval None
  1466. */
  1467. __STATIC_INLINE void LL_I2C_EnableReset(I2C_TypeDef *I2Cx)
  1468. {
  1469. SET_BIT(I2Cx->CR1, I2C_CR1_SWRST);
  1470. }
  1471. /**
  1472. * @brief Disable Reset of I2C peripheral.
  1473. * @rmtoll CR1 SWRST LL_I2C_DisableReset
  1474. * @param I2Cx I2C Instance.
  1475. * @retval None
  1476. */
  1477. __STATIC_INLINE void LL_I2C_DisableReset(I2C_TypeDef *I2Cx)
  1478. {
  1479. CLEAR_BIT(I2Cx->CR1, I2C_CR1_SWRST);
  1480. }
  1481. /**
  1482. * @brief Check if the I2C peripheral is under reset state or not.
  1483. * @rmtoll CR1 SWRST LL_I2C_IsResetEnabled
  1484. * @param I2Cx I2C Instance.
  1485. * @retval State of bit (1 or 0).
  1486. */
  1487. __STATIC_INLINE uint32_t LL_I2C_IsResetEnabled(I2C_TypeDef *I2Cx)
  1488. {
  1489. return (READ_BIT(I2Cx->CR1, I2C_CR1_SWRST) == (I2C_CR1_SWRST));
  1490. }
  1491. /**
  1492. * @brief Prepare the generation of a ACKnowledge or Non ACKnowledge condition after the address receive match code or next received byte.
  1493. * @note Usage in Slave or Master mode.
  1494. * @rmtoll CR1 ACK LL_I2C_AcknowledgeNextData
  1495. * @param I2Cx I2C Instance.
  1496. * @param TypeAcknowledge This parameter can be one of the following values:
  1497. * @arg @ref LL_I2C_ACK
  1498. * @arg @ref LL_I2C_NACK
  1499. * @retval None
  1500. */
  1501. __STATIC_INLINE void LL_I2C_AcknowledgeNextData(I2C_TypeDef *I2Cx, uint32_t TypeAcknowledge)
  1502. {
  1503. MODIFY_REG(I2Cx->CR1, I2C_CR1_ACK, TypeAcknowledge);
  1504. }
  1505. /**
  1506. * @brief Generate a START or RESTART condition
  1507. * @note The START bit can be set even if bus is BUSY or I2C is in slave mode.
  1508. * This action has no effect when RELOAD is set.
  1509. * @rmtoll CR1 START LL_I2C_GenerateStartCondition
  1510. * @param I2Cx I2C Instance.
  1511. * @retval None
  1512. */
  1513. __STATIC_INLINE void LL_I2C_GenerateStartCondition(I2C_TypeDef *I2Cx)
  1514. {
  1515. SET_BIT(I2Cx->CR1, I2C_CR1_START);
  1516. }
  1517. /**
  1518. * @brief Generate a STOP condition after the current byte transfer (master mode).
  1519. * @rmtoll CR1 STOP LL_I2C_GenerateStopCondition
  1520. * @param I2Cx I2C Instance.
  1521. * @retval None
  1522. */
  1523. __STATIC_INLINE void LL_I2C_GenerateStopCondition(I2C_TypeDef *I2Cx)
  1524. {
  1525. SET_BIT(I2Cx->CR1, I2C_CR1_STOP);
  1526. }
  1527. /**
  1528. * @brief Enable bit POS (master/host mode).
  1529. * @note In that case, the ACK bit controls the (N)ACK of the next byte received or the PEC bit indicates that the next byte in shift register is a PEC.
  1530. * @rmtoll CR1 POS LL_I2C_EnableBitPOS
  1531. * @param I2Cx I2C Instance.
  1532. * @retval None
  1533. */
  1534. __STATIC_INLINE void LL_I2C_EnableBitPOS(I2C_TypeDef *I2Cx)
  1535. {
  1536. SET_BIT(I2Cx->CR1, I2C_CR1_POS);
  1537. }
  1538. /**
  1539. * @brief Disable bit POS (master/host mode).
  1540. * @note In that case, the ACK bit controls the (N)ACK of the current byte received or the PEC bit indicates that the current byte in shift register is a PEC.
  1541. * @rmtoll CR1 POS LL_I2C_DisableBitPOS
  1542. * @param I2Cx I2C Instance.
  1543. * @retval None
  1544. */
  1545. __STATIC_INLINE void LL_I2C_DisableBitPOS(I2C_TypeDef *I2Cx)
  1546. {
  1547. CLEAR_BIT(I2Cx->CR1, I2C_CR1_POS);
  1548. }
  1549. /**
  1550. * @brief Check if bit POS is enabled or disabled.
  1551. * @rmtoll CR1 POS LL_I2C_IsEnabledBitPOS
  1552. * @param I2Cx I2C Instance.
  1553. * @retval State of bit (1 or 0).
  1554. */
  1555. __STATIC_INLINE uint32_t LL_I2C_IsEnabledBitPOS(I2C_TypeDef *I2Cx)
  1556. {
  1557. return (READ_BIT(I2Cx->CR1, I2C_CR1_POS) == (I2C_CR1_POS));
  1558. }
  1559. /**
  1560. * @brief Indicate the value of transfer direction.
  1561. * @note RESET: Bus is in read transfer (peripheral point of view).
  1562. * SET: Bus is in write transfer (peripheral point of view).
  1563. * @rmtoll SR2 TRA LL_I2C_GetTransferDirection
  1564. * @param I2Cx I2C Instance.
  1565. * @retval Returned value can be one of the following values:
  1566. * @arg @ref LL_I2C_DIRECTION_WRITE
  1567. * @arg @ref LL_I2C_DIRECTION_READ
  1568. */
  1569. __STATIC_INLINE uint32_t LL_I2C_GetTransferDirection(I2C_TypeDef *I2Cx)
  1570. {
  1571. return (uint32_t)(READ_BIT(I2Cx->SR2, I2C_SR2_TRA));
  1572. }
  1573. /**
  1574. * @brief Enable DMA last transfer.
  1575. * @note This action mean that next DMA EOT is the last transfer.
  1576. * @rmtoll CR2 LAST LL_I2C_EnableLastDMA
  1577. * @param I2Cx I2C Instance.
  1578. * @retval None
  1579. */
  1580. __STATIC_INLINE void LL_I2C_EnableLastDMA(I2C_TypeDef *I2Cx)
  1581. {
  1582. SET_BIT(I2Cx->CR2, I2C_CR2_LAST);
  1583. }
  1584. /**
  1585. * @brief Disable DMA last transfer.
  1586. * @note This action mean that next DMA EOT is not the last transfer.
  1587. * @rmtoll CR2 LAST LL_I2C_DisableLastDMA
  1588. * @param I2Cx I2C Instance.
  1589. * @retval None
  1590. */
  1591. __STATIC_INLINE void LL_I2C_DisableLastDMA(I2C_TypeDef *I2Cx)
  1592. {
  1593. CLEAR_BIT(I2Cx->CR2, I2C_CR2_LAST);
  1594. }
  1595. /**
  1596. * @brief Check if DMA last transfer is enabled or disabled.
  1597. * @rmtoll CR2 LAST LL_I2C_IsEnabledLastDMA
  1598. * @param I2Cx I2C Instance.
  1599. * @retval State of bit (1 or 0).
  1600. */
  1601. __STATIC_INLINE uint32_t LL_I2C_IsEnabledLastDMA(I2C_TypeDef *I2Cx)
  1602. {
  1603. return (READ_BIT(I2Cx->CR2, I2C_CR2_LAST) == (I2C_CR2_LAST));
  1604. }
  1605. /**
  1606. * @brief Enable transfer or internal comparison of the SMBus Packet Error byte (transmission or reception mode).
  1607. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1608. * SMBus feature is supported by the I2Cx Instance.
  1609. * @note This feature is cleared by hardware when the PEC byte is transferred or compared,
  1610. * or by a START or STOP condition, it is also cleared by software.
  1611. * @rmtoll CR1 PEC LL_I2C_EnableSMBusPECCompare
  1612. * @param I2Cx I2C Instance.
  1613. * @retval None
  1614. */
  1615. __STATIC_INLINE void LL_I2C_EnableSMBusPECCompare(I2C_TypeDef *I2Cx)
  1616. {
  1617. SET_BIT(I2Cx->CR1, I2C_CR1_PEC);
  1618. }
  1619. /**
  1620. * @brief Disable transfer or internal comparison of the SMBus Packet Error byte (transmission or reception mode).
  1621. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1622. * SMBus feature is supported by the I2Cx Instance.
  1623. * @rmtoll CR1 PEC LL_I2C_DisableSMBusPECCompare
  1624. * @param I2Cx I2C Instance.
  1625. * @retval None
  1626. */
  1627. __STATIC_INLINE void LL_I2C_DisableSMBusPECCompare(I2C_TypeDef *I2Cx)
  1628. {
  1629. CLEAR_BIT(I2Cx->CR1, I2C_CR1_PEC);
  1630. }
  1631. /**
  1632. * @brief Check if the SMBus Packet Error byte transfer or internal comparison is requested or not.
  1633. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1634. * SMBus feature is supported by the I2Cx Instance.
  1635. * @rmtoll CR1 PEC LL_I2C_IsEnabledSMBusPECCompare
  1636. * @param I2Cx I2C Instance.
  1637. * @retval State of bit (1 or 0).
  1638. */
  1639. __STATIC_INLINE uint32_t LL_I2C_IsEnabledSMBusPECCompare(I2C_TypeDef *I2Cx)
  1640. {
  1641. return (READ_BIT(I2Cx->CR1, I2C_CR1_PEC) == (I2C_CR1_PEC));
  1642. }
  1643. /**
  1644. * @brief Get the SMBus Packet Error byte calculated.
  1645. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1646. * SMBus feature is supported by the I2Cx Instance.
  1647. * @rmtoll SR2 PEC LL_I2C_GetSMBusPEC
  1648. * @param I2Cx I2C Instance.
  1649. * @retval Value between Min_Data=0x00 and Max_Data=0xFF
  1650. */
  1651. __STATIC_INLINE uint32_t LL_I2C_GetSMBusPEC(I2C_TypeDef *I2Cx)
  1652. {
  1653. return (uint32_t)(READ_BIT(I2Cx->SR2, I2C_SR2_PEC) >> I2C_SR2_PEC_Pos);
  1654. }
  1655. /**
  1656. * @brief Read Receive Data register.
  1657. * @rmtoll DR DR LL_I2C_ReceiveData8
  1658. * @param I2Cx I2C Instance.
  1659. * @retval Value between Min_Data=0x0 and Max_Data=0xFF
  1660. */
  1661. __STATIC_INLINE uint8_t LL_I2C_ReceiveData8(I2C_TypeDef *I2Cx)
  1662. {
  1663. return (uint8_t)(READ_BIT(I2Cx->DR, I2C_DR_DR));
  1664. }
  1665. /**
  1666. * @brief Write in Transmit Data Register .
  1667. * @rmtoll DR DR LL_I2C_TransmitData8
  1668. * @param I2Cx I2C Instance.
  1669. * @param Data Value between Min_Data=0x0 and Max_Data=0xFF
  1670. * @retval None
  1671. */
  1672. __STATIC_INLINE void LL_I2C_TransmitData8(I2C_TypeDef *I2Cx, uint8_t Data)
  1673. {
  1674. MODIFY_REG(I2Cx->DR, I2C_DR_DR, Data);
  1675. }
  1676. /**
  1677. * @}
  1678. */
  1679. #if defined(USE_FULL_LL_DRIVER)
  1680. /** @defgroup I2C_LL_EF_Init Initialization and de-initialization functions
  1681. * @{
  1682. */
  1683. uint32_t LL_I2C_Init(I2C_TypeDef *I2Cx, LL_I2C_InitTypeDef *I2C_InitStruct);
  1684. uint32_t LL_I2C_DeInit(I2C_TypeDef *I2Cx);
  1685. void LL_I2C_StructInit(LL_I2C_InitTypeDef *I2C_InitStruct);
  1686. /**
  1687. * @}
  1688. */
  1689. #endif /* USE_FULL_LL_DRIVER */
  1690. /**
  1691. * @}
  1692. */
  1693. /**
  1694. * @}
  1695. */
  1696. #endif /* I2C1 || I2C2 || I2C3 */
  1697. /**
  1698. * @}
  1699. */
  1700. #ifdef __cplusplus
  1701. }
  1702. #endif
  1703. #endif /* __STM32F4xx_LL_I2C_H */
  1704. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/