i2c.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /**
  2. ******************************************************************************
  3. * @file i2c.c
  4. * @brief This file provides code for the configuration
  5. * of the I2C instances.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under Ultimate Liberty license
  13. * SLA0044, the "License"; You may not use this file except in compliance with
  14. * the License. You may obtain a copy of the License at:
  15. * www.st.com/SLA0044
  16. *
  17. ******************************************************************************
  18. */
  19. /* Includes ------------------------------------------------------------------*/
  20. #include "i2c.h"
  21. /* USER CODE BEGIN 0 */
  22. /* USER CODE END 0 */
  23. /* I2C1 init function */
  24. void MX_I2C1_Init(void)
  25. {
  26. LL_I2C_InitTypeDef I2C_InitStruct = {0};
  27. LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
  28. LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA);
  29. /**I2C1 GPIO Configuration
  30. PA9 ------> I2C1_SCL
  31. PA10 ------> I2C1_SDA
  32. */
  33. GPIO_InitStruct.Pin = LL_GPIO_PIN_9|LL_GPIO_PIN_10;
  34. GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
  35. GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH;
  36. GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN;
  37. GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
  38. GPIO_InitStruct.Alternate = LL_GPIO_AF_4;
  39. LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  40. /* Peripheral clock enable */
  41. LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_I2C1);
  42. /** I2C Initialization
  43. */
  44. I2C_InitStruct.PeripheralMode = LL_I2C_MODE_I2C;
  45. I2C_InitStruct.Timing = 0x10707DBC;
  46. I2C_InitStruct.AnalogFilter = LL_I2C_ANALOGFILTER_ENABLE;
  47. I2C_InitStruct.DigitalFilter = 0;
  48. I2C_InitStruct.OwnAddress1 = 0;
  49. I2C_InitStruct.TypeAcknowledge = LL_I2C_ACK;
  50. I2C_InitStruct.OwnAddrSize = LL_I2C_OWNADDRESS1_7BIT;
  51. LL_I2C_Init(I2C1, &I2C_InitStruct);
  52. LL_I2C_EnableAutoEndMode(I2C1);
  53. LL_I2C_SetOwnAddress2(I2C1, 0, LL_I2C_OWNADDRESS2_NOMASK);
  54. LL_I2C_DisableOwnAddress2(I2C1);
  55. LL_I2C_DisableGeneralCall(I2C1);
  56. LL_I2C_EnableClockStretching(I2C1);
  57. }
  58. /* USER CODE BEGIN 1 */
  59. /* USER CODE END 1 */
  60. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/