ICARUS OS (Intelligent Cooperative Architecture for Real-time Unified Systems) 0.1.0
Preemptive Real-Time Operating System for ARM Cortex-M7
Loading...
Searching...
No Matches
i2c.c
Go to the documentation of this file.
1/* USER CODE BEGIN Header */
19/* USER CODE END Header */
20/* Includes ------------------------------------------------------------------*/
21#include "bsp/i2c.h"
22#include "bsp/error.h"
23
24/* USER CODE BEGIN 0 */
25
26/* USER CODE END 0 */
27
28I2C_HandleTypeDef hi2c2;
29
30/* I2C2 init function */
31void MX_I2C2_Init(void)
32{
33
34 /* USER CODE BEGIN I2C2_Init 0 */
35
36 /* USER CODE END I2C2_Init 0 */
37
38 /* USER CODE BEGIN I2C2_Init 1 */
39
40 /* USER CODE END I2C2_Init 1 */
41 hi2c2.Instance = I2C2;
42 hi2c2.Init.Timing = 0x307075B1;
43 hi2c2.Init.OwnAddress1 = 0;
44 hi2c2.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
45 hi2c2.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
46 hi2c2.Init.OwnAddress2 = 0;
47 hi2c2.Init.OwnAddress2Masks = I2C_OA2_NOMASK;
48 hi2c2.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
49 hi2c2.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
50 if (HAL_I2C_Init(&hi2c2) != HAL_OK)
51 {
53 }
54
57 if (HAL_I2CEx_ConfigAnalogFilter(&hi2c2, I2C_ANALOGFILTER_ENABLE) != HAL_OK)
58 {
60 }
61
64 if (HAL_I2CEx_ConfigDigitalFilter(&hi2c2, 0) != HAL_OK)
65 {
67 }
68 /* USER CODE BEGIN I2C2_Init 2 */
69
70 /* USER CODE END I2C2_Init 2 */
71
72}
73
74void HAL_I2C_MspInit(I2C_HandleTypeDef* i2cHandle)
75{
76
77 GPIO_InitTypeDef GPIO_InitStruct = {0};
78 RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
79 if(i2cHandle->Instance==I2C2)
80 {
81 /* USER CODE BEGIN I2C2_MspInit 0 */
82
83 /* USER CODE END I2C2_MspInit 0 */
84
87 PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_I2C2;
88 PeriphClkInitStruct.I2c123ClockSelection = RCC_I2C123CLKSOURCE_D2PCLK1;
89 if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
90 {
92 }
93
94 __HAL_RCC_GPIOB_CLK_ENABLE();
99 GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_11;
100 GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
101 GPIO_InitStruct.Pull = GPIO_NOPULL;
102 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
103 GPIO_InitStruct.Alternate = GPIO_AF4_I2C2;
104 HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
105
106 /* I2C2 clock enable */
107 __HAL_RCC_I2C2_CLK_ENABLE();
108 /* USER CODE BEGIN I2C2_MspInit 1 */
109
110 /* USER CODE END I2C2_MspInit 1 */
111 }
112}
113
114void HAL_I2C_MspDeInit(I2C_HandleTypeDef* i2cHandle)
115{
116
117 if(i2cHandle->Instance==I2C2)
118 {
119 /* USER CODE BEGIN I2C2_MspDeInit 0 */
120
121 /* USER CODE END I2C2_MspDeInit 0 */
122 /* Peripheral clock disable */
123 __HAL_RCC_I2C2_CLK_DISABLE();
124
129 HAL_GPIO_DeInit(GPIOB, GPIO_PIN_10);
130
131 HAL_GPIO_DeInit(GPIOB, GPIO_PIN_11);
132
133 /* USER CODE BEGIN I2C2_MspDeInit 1 */
134
135 /* USER CODE END I2C2_MspDeInit 1 */
136 }
137}
138
139/* USER CODE BEGIN 1 */
140
141/* USER CODE END 1 */
ICARUS OS Error Handling Interface.
void Error_Handler(void)
System error handler for unrecoverable faults.
Definition error.c:50
void MX_I2C2_Init(void)
Definition i2c.c:31
void HAL_I2C_MspInit(I2C_HandleTypeDef *i2cHandle)
Definition i2c.c:74
I2C_HandleTypeDef hi2c2
Definition i2c.c:28
void HAL_I2C_MspDeInit(I2C_HandleTypeDef *i2cHandle)
Definition i2c.c:114
This file contains all the function prototypes for the i2c.c file.