DIY Logging Volt/Ampmeter
i2c.c
Go to the documentation of this file.
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 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 
20 /* Includes ------------------------------------------------------------------*/
21 #include "i2c.h"
22 
23 /* USER CODE BEGIN 0 */
24 
25 /* USER CODE END 0 */
26 
28 
29 /* I2C1 init function */
30 void MX_I2C1_Init(void)
31 {
32 
34  hi2c1.Init.ClockSpeed = 100000;
42  if (HAL_I2C_Init(&hi2c1) != HAL_OK)
43  {
44  Error_Handler();
45  }
46 
47 }
48 
50 {
51 
52  GPIO_InitTypeDef GPIO_InitStruct = {0};
53  if(i2cHandle->Instance==I2C1)
54  {
55  /* USER CODE BEGIN I2C1_MspInit 0 */
56 
57  /* USER CODE END I2C1_MspInit 0 */
58 
60  /**I2C1 GPIO Configuration
61  PB6 ------> I2C1_SCL
62  PB7 ------> I2C1_SDA
63  */
64  GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7;
65  GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
66  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
67  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
68 
69  /* I2C1 clock enable */
71  /* USER CODE BEGIN I2C1_MspInit 1 */
72 
73  /* USER CODE END I2C1_MspInit 1 */
74  }
75 }
76 
78 {
79 
80  if(i2cHandle->Instance==I2C1)
81  {
82  /* USER CODE BEGIN I2C1_MspDeInit 0 */
83 
84  /* USER CODE END I2C1_MspDeInit 0 */
85  /* Peripheral clock disable */
87 
88  /**I2C1 GPIO Configuration
89  PB6 ------> I2C1_SCL
90  PB7 ------> I2C1_SDA
91  */
93 
95 
96  /* USER CODE BEGIN I2C1_MspDeInit 1 */
97 
98  /* USER CODE END I2C1_MspDeInit 1 */
99  }
100 }
101 
102 /* USER CODE BEGIN 1 */
103 
104 /* USER CODE END 1 */
105 
106 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
HAL_I2C_Init
HAL_StatusTypeDef HAL_I2C_Init(I2C_HandleTypeDef *hi2c)
I2C_InitTypeDef::OwnAddress1
uint32_t OwnAddress1
Definition: stm32f1xx_hal_i2c.h:56
__HAL_RCC_I2C1_CLK_ENABLE
#define __HAL_RCC_I2C1_CLK_ENABLE()
Definition: stm32f1xx_hal_rcc.h:424
I2C_InitTypeDef::AddressingMode
uint32_t AddressingMode
Definition: stm32f1xx_hal_i2c.h:59
GPIO_SPEED_FREQ_HIGH
#define GPIO_SPEED_FREQ_HIGH
Definition: stm32f1xx_hal_gpio.h:143
GPIO_InitTypeDef
GPIO Init structure definition.
Definition: stm32f1xx_hal_gpio.h:47
I2C_InitTypeDef::OwnAddress2
uint32_t OwnAddress2
Definition: stm32f1xx_hal_i2c.h:65
I2C_ADDRESSINGMODE_7BIT
#define I2C_ADDRESSINGMODE_7BIT
Definition: stm32f1xx_hal_i2c.h:299
I2C_InitTypeDef::DualAddressMode
uint32_t DualAddressMode
Definition: stm32f1xx_hal_i2c.h:62
I2C_DUTYCYCLE_2
#define I2C_DUTYCYCLE_2
Definition: stm32f1xx_hal_i2c.h:290
I2C_InitTypeDef::NoStretchMode
uint32_t NoStretchMode
Definition: stm32f1xx_hal_i2c.h:71
I2C_DUALADDRESS_DISABLE
#define I2C_DUALADDRESS_DISABLE
Definition: stm32f1xx_hal_i2c.h:308
hi2c1
I2C_HandleTypeDef hi2c1
Definition: i2c.c:27
HAL_GPIO_Init
void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_Init)
GPIO_InitTypeDef::Mode
uint32_t Mode
Definition: stm32f1xx_hal_gpio.h:52
I2C_GENERALCALL_DISABLE
#define I2C_GENERALCALL_DISABLE
Definition: stm32f1xx_hal_i2c.h:317
I2C_InitTypeDef::DutyCycle
uint32_t DutyCycle
Definition: stm32f1xx_hal_i2c.h:53
GPIO_PIN_6
#define GPIO_PIN_6
Definition: stm32f1xx_hal_gpio.h:89
__HAL_RCC_I2C1_CLK_DISABLE
#define __HAL_RCC_I2C1_CLK_DISABLE()
Definition: stm32f1xx_hal_rcc.h:452
I2C_HandleTypeDef::Instance
I2C_TypeDef * Instance
Definition: stm32f1xx_hal_i2c.h:191
HAL_GPIO_DeInit
void HAL_GPIO_DeInit(GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin)
GPIO_InitTypeDef::Speed
uint32_t Speed
Definition: stm32f1xx_hal_gpio.h:58
HAL_OK
@ HAL_OK
Definition: stm32f1xx_hal_def.h:41
I2C_InitTypeDef::GeneralCallMode
uint32_t GeneralCallMode
Definition: stm32f1xx_hal_i2c.h:68
GPIOB
#define GPIOB
Definition: stm32f103xb.h:666
HAL_I2C_MspInit
void HAL_I2C_MspInit(I2C_HandleTypeDef *i2cHandle)
Definition: i2c.c:49
I2C_HandleTypeDef::Init
I2C_InitTypeDef Init
Definition: stm32f1xx_hal_i2c.h:193
GPIO_MODE_AF_OD
#define GPIO_MODE_AF_OD
Definition: stm32f1xx_hal_gpio.h:120
Error_Handler
void Error_Handler(void)
This function is executed in case of error occurrence.
Definition: main.c:1102
I2C_HandleTypeDef
Definition: stm32f1xx_hal_i2c.h:188
I2C1
#define I2C1
Definition: stm32f103xb.h:657
I2C_InitTypeDef::ClockSpeed
uint32_t ClockSpeed
Definition: stm32f1xx_hal_i2c.h:50
I2C_NOSTRETCH_DISABLE
#define I2C_NOSTRETCH_DISABLE
Definition: stm32f1xx_hal_i2c.h:326
GPIO_PIN_7
#define GPIO_PIN_7
Definition: stm32f1xx_hal_gpio.h:90
i2c.h
This file contains all the function prototypes for the i2c.c file.
HAL_I2C_MspDeInit
void HAL_I2C_MspDeInit(I2C_HandleTypeDef *i2cHandle)
Definition: i2c.c:77
MX_I2C1_Init
void MX_I2C1_Init(void)
Definition: i2c.c:30
__HAL_RCC_GPIOB_CLK_ENABLE
#define __HAL_RCC_GPIOB_CLK_ENABLE()
Definition: stm32f1xx_hal_rcc.h:511
GPIO_InitTypeDef::Pin
uint32_t Pin
Definition: stm32f1xx_hal_gpio.h:49