i2c.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. /* USER CODE BEGIN I2C1_Init 0 */
  26. /* USER CODE END I2C1_Init 0 */
  27. LL_I2C_InitTypeDef I2C_InitStruct = {0};
  28. LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
  29. LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA);
  30. /**I2C1 GPIO Configuration
  31. PA9 ------> I2C1_SCL
  32. PA10 ------> I2C1_SDA
  33. */
  34. GPIO_InitStruct.Pin = LL_GPIO_PIN_9 | LL_GPIO_PIN_10;
  35. GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
  36. GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH;
  37. GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN;
  38. GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
  39. GPIO_InitStruct.Alternate = LL_GPIO_AF_4;
  40. LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  41. /* Peripheral clock enable */
  42. LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_I2C1);
  43. /* USER CODE BEGIN I2C1_Init 1 */
  44. /* USER CODE END I2C1_Init 1 */
  45. /** I2C Initialization
  46. */
  47. I2C_InitStruct.PeripheralMode = LL_I2C_MODE_I2C;
  48. I2C_InitStruct.Timing = 0x10707DBC;
  49. I2C_InitStruct.AnalogFilter = LL_I2C_ANALOGFILTER_ENABLE;
  50. I2C_InitStruct.DigitalFilter = 0;
  51. I2C_InitStruct.OwnAddress1 = 0;
  52. I2C_InitStruct.TypeAcknowledge = LL_I2C_ACK;
  53. I2C_InitStruct.OwnAddrSize = LL_I2C_OWNADDRESS1_7BIT;
  54. LL_I2C_Init(I2C1, &I2C_InitStruct);
  55. LL_I2C_EnableAutoEndMode(I2C1);
  56. LL_I2C_SetOwnAddress2(I2C1, 0, LL_I2C_OWNADDRESS2_NOMASK);
  57. LL_I2C_DisableOwnAddress2(I2C1);
  58. LL_I2C_DisableGeneralCall(I2C1);
  59. LL_I2C_EnableClockStretching(I2C1);
  60. /* USER CODE BEGIN I2C1_Init 2 */
  61. /* USER CODE END I2C1_Init 2 */
  62. }
  63. /* USER CODE BEGIN 1 */
  64. /* USER CODE END 1 */
  65. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/