annotate Common/Drivers/STM32F4xx_HAL_DRIVER_v120/Src/stm32f4xx_hal_i2c.c @ 105:68181cd61f20 kittz

fix comments
author Dmitry Romanov <kitt@bk.ru>
date Mon, 24 Dec 2018 16:19:09 +0300
parents 5f11787b4f42
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3 * @file stm32f4xx_hal_i2c.c
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
4 * @author MCD Application Team
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
5 * @version V1.2.0
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
6 * @date 26-December-2014
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
7 * @brief I2C HAL module driver.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
8 * This file provides firmware functions to manage the following
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
9 * functionalities of the Inter Integrated Circuit (I2C) peripheral:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
10 * + Initialization and de-initialization functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
11 * + IO operation functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
12 * + Peripheral Control functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
13 * + Peripheral State functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
14 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
15 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
16 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
17 ##### How to use this driver #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
18 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
19 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
20 The I2C HAL driver can be used as follows:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
21
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
22 (#) Declare a I2C_HandleTypeDef handle structure, for example:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
23 I2C_HandleTypeDef hi2c;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
24
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
25 (#)Initialize the I2C low level resources by implement the HAL_I2C_MspInit() API:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
26 (##) Enable the I2Cx interface clock
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
27 (##) I2C pins configuration
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
28 (+++) Enable the clock for the I2C GPIOs
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
29 (+++) Configure I2C pins as alternate function open-drain
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
30 (##) NVIC configuration if you need to use interrupt process
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
31 (+++) Configure the I2Cx interrupt priority
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
32 (+++) Enable the NVIC I2C IRQ Channel
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
33 (##) DMA Configuration if you need to use DMA process
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
34 (+++) Declare a DMA_HandleTypeDef handle structure for the transmit or receive stream
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
35 (+++) Enable the DMAx interface clock using
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
36 (+++) Configure the DMA handle parameters
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
37 (+++) Configure the DMA Tx or Rx Stream
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
38 (+++) Associate the initialized DMA handle to the hi2c DMA Tx or Rx handle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
39 (+++) Configure the priority and enable the NVIC for the transfer complete interrupt on
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
40 the DMA Tx or Rx Stream
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
41
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
42 (#) Configure the Communication Speed, Duty cycle, Addressing mode, Own Address1,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
43 Dual Addressing mode, Own Address2, General call and Nostretch mode in the hi2c Init structure.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
44
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
45 (#) Initialize the I2C registers by calling the HAL_I2C_Init(), configures also the low level Hardware
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
46 (GPIO, CLOCK, NVIC...etc) by calling the customized HAL_I2C_MspInit(&hi2c) API.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
47
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
48 (#) To check if target device is ready for communication, use the function HAL_I2C_IsDeviceReady()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
49
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
50 (#) For I2C IO and IO MEM operations, three operation modes are available within this driver :
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
51
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
52 *** Polling mode IO operation ***
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
53 =================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
54 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
55 (+) Transmit in master mode an amount of data in blocking mode using HAL_I2C_Master_Transmit()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
56 (+) Receive in master mode an amount of data in blocking mode using HAL_I2C_Master_Receive()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
57 (+) Transmit in slave mode an amount of data in blocking mode using HAL_I2C_Slave_Transmit()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
58 (+) Receive in slave mode an amount of data in blocking mode using HAL_I2C_Slave_Receive()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
59
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
60 *** Polling mode IO MEM operation ***
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
61 =====================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
62 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
63 (+) Write an amount of data in blocking mode to a specific memory address using HAL_I2C_Mem_Write()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
64 (+) Read an amount of data in blocking mode from a specific memory address using HAL_I2C_Mem_Read()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
65
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
66
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
67 *** Interrupt mode IO operation ***
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
68 ===================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
69 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
70 (+) Transmit in master mode an amount of data in non blocking mode using HAL_I2C_Master_Transmit_IT()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
71 (+) At transmission end of transfer HAL_I2C_MasterTxCpltCallback is executed and user can
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
72 add his own code by customization of function pointer HAL_I2C_MasterTxCpltCallback
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
73 (+) Receive in master mode an amount of data in non blocking mode using HAL_I2C_Master_Receive_IT()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
74 (+) At reception end of transfer HAL_I2C_MasterRxCpltCallback is executed and user can
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
75 add his own code by customization of function pointer HAL_I2C_MasterRxCpltCallback
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
76 (+) Transmit in slave mode an amount of data in non blocking mode using HAL_I2C_Slave_Transmit_IT()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
77 (+) At transmission end of transfer HAL_I2C_SlaveTxCpltCallback is executed and user can
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
78 add his own code by customization of function pointer HAL_I2C_SlaveTxCpltCallback
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
79 (+) Receive in slave mode an amount of data in non blocking mode using HAL_I2C_Slave_Receive_IT()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
80 (+) At reception end of transfer HAL_I2C_SlaveRxCpltCallback is executed and user can
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
81 add his own code by customization of function pointer HAL_I2C_SlaveRxCpltCallback
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
82 (+) In case of transfer Error, HAL_I2C_ErrorCallback() function is executed and user can
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
83 add his own code by customization of function pointer HAL_I2C_ErrorCallback
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
84
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
85 *** Interrupt mode IO MEM operation ***
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
86 =======================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
87 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
88 (+) Write an amount of data in no-blocking mode with Interrupt to a specific memory address using
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
89 HAL_I2C_Mem_Write_IT()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
90 (+) At MEM end of write transfer HAL_I2C_MemTxCpltCallback is executed and user can
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
91 add his own code by customization of function pointer HAL_I2C_MemTxCpltCallback
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
92 (+) Read an amount of data in no-blocking mode with Interrupt from a specific memory address using
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
93 HAL_I2C_Mem_Read_IT()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
94 (+) At MEM end of read transfer HAL_I2C_MemRxCpltCallback is executed and user can
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
95 add his own code by customization of function pointer HAL_I2C_MemRxCpltCallback
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
96 (+) In case of transfer Error, HAL_I2C_ErrorCallback() function is executed and user can
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
97 add his own code by customization of function pointer HAL_I2C_ErrorCallback
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
98
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
99 *** DMA mode IO operation ***
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
100 ==============================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
101 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
102 (+) Transmit in master mode an amount of data in non blocking mode (DMA) using
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
103 HAL_I2C_Master_Transmit_DMA()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
104 (+) At transmission end of transfer HAL_I2C_MasterTxCpltCallback is executed and user can
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
105 add his own code by customization of function pointer HAL_I2C_MasterTxCpltCallback
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
106 (+) Receive in master mode an amount of data in non blocking mode (DMA) using
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
107 HAL_I2C_Master_Receive_DMA()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
108 (+) At reception end of transfer HAL_I2C_MasterRxCpltCallback is executed and user can
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
109 add his own code by customization of function pointer HAL_I2C_MasterRxCpltCallback
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
110 (+) Transmit in slave mode an amount of data in non blocking mode (DMA) using
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
111 HAL_I2C_Slave_Transmit_DMA()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
112 (+) At transmission end of transfer HAL_I2C_SlaveTxCpltCallback is executed and user can
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
113 add his own code by customization of function pointer HAL_I2C_SlaveTxCpltCallback
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
114 (+) Receive in slave mode an amount of data in non blocking mode (DMA) using
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
115 HAL_I2C_Slave_Receive_DMA()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
116 (+) At reception end of transfer HAL_I2C_SlaveRxCpltCallback is executed and user can
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
117 add his own code by customization of function pointer HAL_I2C_SlaveRxCpltCallback
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
118 (+) In case of transfer Error, HAL_I2C_ErrorCallback() function is executed and user can
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
119 add his own code by customization of function pointer HAL_I2C_ErrorCallback
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
120
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
121 *** DMA mode IO MEM operation ***
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
122 =================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
123 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
124 (+) Write an amount of data in no-blocking mode with DMA to a specific memory address using
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
125 HAL_I2C_Mem_Write_DMA()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
126 (+) At MEM end of write transfer HAL_I2C_MemTxCpltCallback is executed and user can
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
127 add his own code by customization of function pointer HAL_I2C_MemTxCpltCallback
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
128 (+) Read an amount of data in no-blocking mode with DMA from a specific memory address using
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
129 HAL_I2C_Mem_Read_DMA()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
130 (+) At MEM end of read transfer HAL_I2C_MemRxCpltCallback is executed and user can
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
131 add his own code by customization of function pointer HAL_I2C_MemRxCpltCallback
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
132 (+) In case of transfer Error, HAL_I2C_ErrorCallback() function is executed and user can
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
133 add his own code by customization of function pointer HAL_I2C_ErrorCallback
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
134
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
135
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
136 *** I2C HAL driver macros list ***
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
137 ==================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
138 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
139 Below the list of most used macros in I2C HAL driver.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
140
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
141 (+) __HAL_I2C_ENABLE: Enable the I2C peripheral
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
142 (+) __HAL_I2C_DISABLE: Disable the I2C peripheral
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
143 (+) __HAL_I2C_GET_FLAG : Checks whether the specified I2C flag is set or not
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
144 (+) __HAL_I2C_CLEAR_FLAG : Clear the specified I2C pending flag
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
145 (+) __HAL_I2C_ENABLE_IT: Enable the specified I2C interrupt
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
146 (+) __HAL_I2C_DISABLE_IT: Disable the specified I2C interrupt
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
147
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
148 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
149 (@) You can refer to the I2C HAL driver header file for more useful macros
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
150
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
151
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
152 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
153 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
154 * @attention
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
155 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
156 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
157 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
158 * Redistribution and use in source and binary forms, with or without modification,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
159 * are permitted provided that the following conditions are met:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
160 * 1. Redistributions of source code must retain the above copyright notice,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
161 * this list of conditions and the following disclaimer.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
162 * 2. Redistributions in binary form must reproduce the above copyright notice,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
163 * this list of conditions and the following disclaimer in the documentation
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
164 * and/or other materials provided with the distribution.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
165 * 3. Neither the name of STMicroelectronics nor the names of its contributors
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
166 * may be used to endorse or promote products derived from this software
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
167 * without specific prior written permission.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
168 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
169 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
170 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
171 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
172 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
173 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
174 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
175 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
176 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
177 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
178 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
179 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
180 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
181 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
182
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
183 /* Includes ------------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
184 #include "stm32f4xx_hal.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
185
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
186 /** @addtogroup STM32F4xx_HAL_Driver
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
187 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
188 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
189
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
190 /** @defgroup I2C I2C
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
191 * @brief I2C HAL module driver
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
192 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
193 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
194
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
195 #ifdef HAL_I2C_MODULE_ENABLED
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
196
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
197 /* Private typedef -----------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
198 /* Private define ------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
199 /** @addtogroup I2C_Private_Constants
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
200 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
201 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
202 #define I2C_TIMEOUT_FLAG ((uint32_t)35) /* 35 ms */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
203 #define I2C_TIMEOUT_ADDR_SLAVE ((uint32_t)10000) /* 10 s */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
204 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
205 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
206 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
207
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
208 /* Private macro -------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
209 /* Private variables ---------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
210 /* Private function prototypes -----------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
211 /** @addtogroup I2C_Private_Functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
212 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
213 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
214 static void I2C_DMAMasterTransmitCplt(DMA_HandleTypeDef *hdma);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
215 static void I2C_DMAMasterReceiveCplt(DMA_HandleTypeDef *hdma);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
216 static void I2C_DMASlaveTransmitCplt(DMA_HandleTypeDef *hdma);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
217 static void I2C_DMASlaveReceiveCplt(DMA_HandleTypeDef *hdma);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
218 static void I2C_DMAMemTransmitCplt(DMA_HandleTypeDef *hdma);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
219 static void I2C_DMAMemReceiveCplt(DMA_HandleTypeDef *hdma);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
220 static void I2C_DMAError(DMA_HandleTypeDef *hdma);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
221
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
222 static HAL_StatusTypeDef I2C_MasterRequestWrite(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint32_t Timeout);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
223 static HAL_StatusTypeDef I2C_MasterRequestRead(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint32_t Timeout);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
224 static HAL_StatusTypeDef I2C_RequestMemoryWrite(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint32_t Timeout);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
225 static HAL_StatusTypeDef I2C_RequestMemoryRead(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint32_t Timeout);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
226 static HAL_StatusTypeDef I2C_WaitOnFlagUntilTimeout(I2C_HandleTypeDef *hi2c, uint32_t Flag, FlagStatus Status, uint32_t Timeout);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
227 static HAL_StatusTypeDef I2C_WaitOnMasterAddressFlagUntilTimeout(I2C_HandleTypeDef *hi2c, uint32_t Flag, uint32_t Timeout);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
228
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
229 static HAL_StatusTypeDef I2C_MasterTransmit_TXE(I2C_HandleTypeDef *hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
230 static HAL_StatusTypeDef I2C_MasterTransmit_BTF(I2C_HandleTypeDef *hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
231 static HAL_StatusTypeDef I2C_MasterReceive_RXNE(I2C_HandleTypeDef *hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
232 static HAL_StatusTypeDef I2C_MasterReceive_BTF(I2C_HandleTypeDef *hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
233
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
234 static HAL_StatusTypeDef I2C_SlaveTransmit_TXE(I2C_HandleTypeDef *hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
235 static HAL_StatusTypeDef I2C_SlaveTransmit_BTF(I2C_HandleTypeDef *hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
236 static HAL_StatusTypeDef I2C_SlaveReceive_RXNE(I2C_HandleTypeDef *hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
237 static HAL_StatusTypeDef I2C_SlaveReceive_BTF(I2C_HandleTypeDef *hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
238 static HAL_StatusTypeDef I2C_Slave_ADDR(I2C_HandleTypeDef *hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
239 static HAL_StatusTypeDef I2C_Slave_STOPF(I2C_HandleTypeDef *hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
240 static HAL_StatusTypeDef I2C_Slave_AF(I2C_HandleTypeDef *hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
241 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
242 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
243 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
244
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
245 /* Exported functions --------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
246 /** @defgroup I2C_Exported_Functions I2C Exported Functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
247 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
248 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
249
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
250 /** @defgroup I2C_Exported_Functions_Group1 Initialization and de-initialization functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
251 * @brief Initialization and Configuration functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
252 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
253 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
254 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
255 ##### Initialization and de-initialization functions #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
256 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
257 [..] This subsection provides a set of functions allowing to initialize and
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
258 de-initialize the I2Cx peripheral:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
259
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
260 (+) User must Implement HAL_I2C_MspInit() function in which he configures
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
261 all related peripherals resources (CLOCK, GPIO, DMA, IT and NVIC).
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
262
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
263 (+) Call the function HAL_I2C_Init() to configure the selected device with
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
264 the selected configuration:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
265 (++) Communication Speed
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
266 (++) Duty cycle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
267 (++) Addressing mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
268 (++) Own Address 1
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
269 (++) Dual Addressing mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
270 (++) Own Address 2
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
271 (++) General call mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
272 (++) Nostretch mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
273
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
274 (+) Call the function HAL_I2C_DeInit() to restore the default configuration
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
275 of the selected I2Cx peripheral.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
276
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
277 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
278 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
279 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
280
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
281 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
282 * @brief Initializes the I2C according to the specified parameters
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
283 * in the I2C_InitTypeDef and create the associated handle.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
284 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
285 * the configuration information for I2C module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
286 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
287 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
288 HAL_StatusTypeDef HAL_I2C_Init(I2C_HandleTypeDef *hi2c)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
289 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
290 uint32_t freqrange = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
291 uint32_t pclk1 = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
292
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
293 /* Check the I2C handle allocation */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
294 if(hi2c == NULL)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
295 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
296 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
297 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
298
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
299 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
300 assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
301 assert_param(IS_I2C_CLOCK_SPEED(hi2c->Init.ClockSpeed));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
302 assert_param(IS_I2C_DUTY_CYCLE(hi2c->Init.DutyCycle));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
303 assert_param(IS_I2C_OWN_ADDRESS1(hi2c->Init.OwnAddress1));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
304 assert_param(IS_I2C_ADDRESSING_MODE(hi2c->Init.AddressingMode));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
305 assert_param(IS_I2C_DUAL_ADDRESS(hi2c->Init.DualAddressMode));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
306 assert_param(IS_I2C_OWN_ADDRESS2(hi2c->Init.OwnAddress2));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
307 assert_param(IS_I2C_GENERAL_CALL(hi2c->Init.GeneralCallMode));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
308 assert_param(IS_I2C_NO_STRETCH(hi2c->Init.NoStretchMode));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
309
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
310 if(hi2c->State == HAL_I2C_STATE_RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
311 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
312 /* Init the low level hardware : GPIO, CLOCK, NVIC */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
313 HAL_I2C_MspInit(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
314 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
315
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
316 hi2c->State = HAL_I2C_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
317
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
318 /* Disable the selected I2C peripheral */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
319 __HAL_I2C_DISABLE(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
320
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
321 /* Get PCLK1 frequency */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
322 pclk1 = HAL_RCC_GetPCLK1Freq();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
323
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
324 /* Calculate frequency range */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
325 freqrange = I2C_FREQRANGE(pclk1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
326
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
327 /*---------------------------- I2Cx CR2 Configuration ----------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
328 /* Configure I2Cx: Frequency range */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
329 hi2c->Instance->CR2 = freqrange;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
330
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
331 /*---------------------------- I2Cx TRISE Configuration --------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
332 /* Configure I2Cx: Rise Time */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
333 hi2c->Instance->TRISE = I2C_RISE_TIME(freqrange, hi2c->Init.ClockSpeed);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
334
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
335 /*---------------------------- I2Cx CCR Configuration ----------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
336 /* Configure I2Cx: Speed */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
337 hi2c->Instance->CCR = I2C_SPEED(pclk1, hi2c->Init.ClockSpeed, hi2c->Init.DutyCycle);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
338
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
339 /*---------------------------- I2Cx CR1 Configuration ----------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
340 /* Configure I2Cx: Generalcall and NoStretch mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
341 hi2c->Instance->CR1 = (hi2c->Init.GeneralCallMode | hi2c->Init.NoStretchMode);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
342
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
343 /*---------------------------- I2Cx OAR1 Configuration ---------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
344 /* Configure I2Cx: Own Address1 and addressing mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
345 hi2c->Instance->OAR1 = (hi2c->Init.AddressingMode | hi2c->Init.OwnAddress1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
346
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
347 /*---------------------------- I2Cx OAR2 Configuration ---------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
348 /* Configure I2Cx: Dual mode and Own Address2 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
349 hi2c->Instance->OAR2 = (hi2c->Init.DualAddressMode | hi2c->Init.OwnAddress2);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
350
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
351 /* Enable the selected I2C peripheral */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
352 __HAL_I2C_ENABLE(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
353
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
354 hi2c->ErrorCode = HAL_I2C_ERROR_NONE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
355 hi2c->State = HAL_I2C_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
356
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
357 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
358 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
359
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
360 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
361 * @brief DeInitializes the I2C peripheral.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
362 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
363 * the configuration information for I2C module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
364 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
365 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
366 HAL_StatusTypeDef HAL_I2C_DeInit(I2C_HandleTypeDef *hi2c)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
367 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
368 /* Check the I2C handle allocation */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
369 if(hi2c == NULL)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
370 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
371 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
372 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
373
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
374 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
375 assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
376
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
377 hi2c->State = HAL_I2C_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
378
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
379 /* Disable the I2C Peripheral Clock */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
380 __HAL_I2C_DISABLE(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
381
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
382 /* DeInit the low level hardware: GPIO, CLOCK, NVIC */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
383 HAL_I2C_MspDeInit(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
384
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
385 hi2c->ErrorCode = HAL_I2C_ERROR_NONE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
386
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
387 hi2c->State = HAL_I2C_STATE_RESET;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
388
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
389 /* Release Lock */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
390 __HAL_UNLOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
391
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
392 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
393 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
394
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
395 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
396 * @brief I2C MSP Init.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
397 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
398 * the configuration information for I2C module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
399 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
400 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
401 __weak void HAL_I2C_MspInit(I2C_HandleTypeDef *hi2c)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
402 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
403 /* NOTE : This function Should not be modified, when the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
404 the HAL_I2C_MspInit could be implemented in the user file
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
405 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
406 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
407
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
408 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
409 * @brief I2C MSP DeInit
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
410 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
411 * the configuration information for I2C module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
412 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
413 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
414 __weak void HAL_I2C_MspDeInit(I2C_HandleTypeDef *hi2c)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
415 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
416 /* NOTE : This function Should not be modified, when the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
417 the HAL_I2C_MspDeInit could be implemented in the user file
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
418 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
419 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
420
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
421 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
422 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
423 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
424
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
425 /** @defgroup I2C_Exported_Functions_Group2 IO operation functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
426 * @brief Data transfers functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
427 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
428 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
429 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
430 ##### IO operation functions #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
431 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
432 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
433 This subsection provides a set of functions allowing to manage the I2C data
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
434 transfers.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
435
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
436 (#) There are two modes of transfer:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
437 (++) Blocking mode : The communication is performed in the polling mode.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
438 The status of all data processing is returned by the same function
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
439 after finishing transfer.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
440 (++) No-Blocking mode : The communication is performed using Interrupts
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
441 or DMA. These functions return the status of the transfer startup.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
442 The end of the data processing will be indicated through the
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
443 dedicated I2C IRQ when using Interrupt mode or the DMA IRQ when
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
444 using DMA mode.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
445
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
446 (#) Blocking mode functions are :
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
447 (++) HAL_I2C_Master_Transmit()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
448 (++) HAL_I2C_Master_Receive()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
449 (++) HAL_I2C_Slave_Transmit()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
450 (++) HAL_I2C_Slave_Receive()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
451 (++) HAL_I2C_Mem_Write()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
452 (++) HAL_I2C_Mem_Read()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
453 (++) HAL_I2C_IsDeviceReady()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
454
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
455 (#) No-Blocking mode functions with Interrupt are :
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
456 (++) HAL_I2C_Master_Transmit_IT()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
457 (++) HAL_I2C_Master_Receive_IT()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
458 (++) HAL_I2C_Slave_Transmit_IT()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
459 (++) HAL_I2C_Slave_Receive_IT()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
460 (++) HAL_I2C_Mem_Write_IT()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
461 (++) HAL_I2C_Mem_Read_IT()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
462
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
463 (#) No-Blocking mode functions with DMA are :
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
464 (++) HAL_I2C_Master_Transmit_DMA()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
465 (++) HAL_I2C_Master_Receive_DMA()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
466 (++) HAL_I2C_Slave_Transmit_DMA()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
467 (++) HAL_I2C_Slave_Receive_DMA()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
468 (++) HAL_I2C_Mem_Write_DMA()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
469 (++) HAL_I2C_Mem_Read_DMA()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
470
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
471 (#) A set of Transfer Complete Callbacks are provided in non Blocking mode:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
472 (++) HAL_I2C_MemTxCpltCallback()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
473 (++) HAL_I2C_MemRxCpltCallback()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
474 (++) HAL_I2C_MasterTxCpltCallback()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
475 (++) HAL_I2C_MasterRxCpltCallback()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
476 (++) HAL_I2C_SlaveTxCpltCallback()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
477 (++) HAL_I2C_SlaveRxCpltCallback()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
478 (++) HAL_I2C_ErrorCallback()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
479
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
480 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
481 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
482 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
483
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
484 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
485 * @brief Transmits in master mode an amount of data in blocking mode.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
486 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
487 * the configuration information for I2C module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
488 * @param DevAddress: Target device address
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
489 * @param pData: Pointer to data buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
490 * @param Size: Amount of data to be sent
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
491 * @param Timeout: Timeout duration
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
492 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
493 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
494 HAL_StatusTypeDef HAL_I2C_Master_Transmit(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t Timeout)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
495 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
496 if(hi2c->State == HAL_I2C_STATE_READY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
497 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
498 if((pData == NULL) || (Size == 0))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
499 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
500 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
501 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
502
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
503 if(__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BUSY) == SET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
504 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
505 return HAL_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
506 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
507
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
508 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
509 __HAL_LOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
510
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
511 hi2c->State = HAL_I2C_STATE_BUSY_TX;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
512 hi2c->ErrorCode = HAL_I2C_ERROR_NONE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
513
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
514 /* Send Slave Address */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
515 if(I2C_MasterRequestWrite(hi2c, DevAddress, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
516 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
517 if(hi2c->ErrorCode == HAL_I2C_ERROR_AF)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
518 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
519 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
520 __HAL_UNLOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
521 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
522 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
523 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
524 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
525 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
526 __HAL_UNLOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
527 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
528 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
529 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
530
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
531 /* Clear ADDR flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
532 __HAL_I2C_CLEAR_ADDRFLAG(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
533
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
534 while(Size > 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
535 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
536 /* Wait until TXE flag is set */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
537 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_TXE, RESET, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
538 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
539 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
540 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
541
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
542 /* Write data to DR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
543 hi2c->Instance->DR = (*pData++);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
544 Size--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
545
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
546 if((__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BTF) == SET) && (Size != 0))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
547 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
548 /* Write data to DR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
549 hi2c->Instance->DR = (*pData++);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
550 Size--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
551 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
552 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
553
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
554 /* Wait until TXE flag is set */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
555 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_TXE, RESET, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
556 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
557 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
558 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
559
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
560 /* Generate Stop */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
561 hi2c->Instance->CR1 |= I2C_CR1_STOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
562
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
563 /* Wait until BUSY flag is reset */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
564 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_BUSY, SET, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
565 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
566 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
567 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
568
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
569 hi2c->State = HAL_I2C_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
570
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
571 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
572 __HAL_UNLOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
573
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
574 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
575 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
576 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
577 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
578 return HAL_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
579 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
580 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
581
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
582 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
583 * @brief Receives in master mode an amount of data in blocking mode.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
584 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
585 * the configuration information for I2C module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
586 * @param DevAddress: Target device address
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
587 * @param pData: Pointer to data buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
588 * @param Size: Amount of data to be sent
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
589 * @param Timeout: Timeout duration
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
590 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
591 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
592 HAL_StatusTypeDef HAL_I2C_Master_Receive(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t Timeout)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
593 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
594 if(hi2c->State == HAL_I2C_STATE_READY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
595 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
596 if((pData == NULL) || (Size == 0))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
597 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
598 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
599 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
600
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
601 if(__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BUSY) == SET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
602 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
603 return HAL_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
604 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
605
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
606 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
607 __HAL_LOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
608
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
609 hi2c->State = HAL_I2C_STATE_BUSY_RX;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
610 hi2c->ErrorCode = HAL_I2C_ERROR_NONE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
611
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
612 /* Send Slave Address */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
613 if(I2C_MasterRequestRead(hi2c, DevAddress, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
614 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
615 if(hi2c->ErrorCode == HAL_I2C_ERROR_AF)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
616 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
617 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
618 __HAL_UNLOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
619 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
620 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
621 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
622 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
623 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
624 __HAL_UNLOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
625 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
626 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
627 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
628
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
629 if(Size == 1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
630 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
631 /* Disable Acknowledge */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
632 hi2c->Instance->CR1 &= ~I2C_CR1_ACK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
633
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
634 /* Clear ADDR flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
635 __HAL_I2C_CLEAR_ADDRFLAG(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
636
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
637 /* Generate Stop */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
638 hi2c->Instance->CR1 |= I2C_CR1_STOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
639 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
640 else if(Size == 2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
641 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
642 /* Disable Acknowledge */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
643 hi2c->Instance->CR1 &= ~I2C_CR1_ACK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
644
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
645 /* Enable Pos */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
646 hi2c->Instance->CR1 |= I2C_CR1_POS;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
647
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
648 /* Clear ADDR flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
649 __HAL_I2C_CLEAR_ADDRFLAG(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
650 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
651 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
652 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
653 /* Enable Acknowledge */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
654 hi2c->Instance->CR1 |= I2C_CR1_ACK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
655
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
656 /* Clear ADDR flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
657 __HAL_I2C_CLEAR_ADDRFLAG(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
658 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
659
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
660 while(Size > 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
661 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
662 if(Size <= 3)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
663 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
664 /* One byte */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
665 if(Size == 1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
666 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
667 /* Wait until RXNE flag is set */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
668 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_RXNE, RESET, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
669 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
670 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
671 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
672
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
673 /* Read data from DR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
674 (*pData++) = hi2c->Instance->DR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
675 Size--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
676 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
677 /* Two bytes */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
678 else if(Size == 2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
679 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
680 /* Wait until BTF flag is set */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
681 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_BTF, RESET, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
682 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
683 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
684 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
685
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
686 /* Generate Stop */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
687 hi2c->Instance->CR1 |= I2C_CR1_STOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
688
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
689 /* Read data from DR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
690 (*pData++) = hi2c->Instance->DR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
691 Size--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
692
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
693 /* Read data from DR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
694 (*pData++) = hi2c->Instance->DR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
695 Size--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
696 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
697 /* 3 Last bytes */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
698 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
699 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
700 /* Wait until BTF flag is set */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
701 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_BTF, RESET, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
702 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
703 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
704 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
705
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
706 /* Disable Acknowledge */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
707 hi2c->Instance->CR1 &= ~I2C_CR1_ACK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
708
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
709 /* Read data from DR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
710 (*pData++) = hi2c->Instance->DR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
711 Size--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
712
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
713 /* Wait until BTF flag is set */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
714 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_BTF, RESET, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
715 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
716 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
717 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
718
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
719 /* Generate Stop */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
720 hi2c->Instance->CR1 |= I2C_CR1_STOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
721
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
722 /* Read data from DR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
723 (*pData++) = hi2c->Instance->DR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
724 Size--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
725
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
726 /* Read data from DR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
727 (*pData++) = hi2c->Instance->DR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
728 Size--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
729 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
730 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
731 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
732 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
733 /* Wait until RXNE flag is set */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
734 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_RXNE, RESET, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
735 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
736 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
737 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
738
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
739 /* Read data from DR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
740 (*pData++) = hi2c->Instance->DR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
741 Size--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
742
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
743 if(__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BTF) == SET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
744 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
745 /* Read data from DR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
746 (*pData++) = hi2c->Instance->DR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
747 Size--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
748 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
749 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
750 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
751
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
752 /* Disable Pos */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
753 hi2c->Instance->CR1 &= ~I2C_CR1_POS;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
754
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
755 /* Wait until BUSY flag is reset */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
756 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_BUSY, SET, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
757 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
758 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
759 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
760
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
761 hi2c->State = HAL_I2C_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
762
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
763 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
764 __HAL_UNLOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
765
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
766 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
767 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
768 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
769 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
770 return HAL_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
771 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
772 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
773
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
774 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
775 * @brief Transmits in slave mode an amount of data in blocking mode.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
776 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
777 * the configuration information for I2C module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
778 * @param pData: Pointer to data buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
779 * @param Size: Amount of data to be sent
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
780 * @param Timeout: Timeout duration
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
781 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
782 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
783 HAL_StatusTypeDef HAL_I2C_Slave_Transmit(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size, uint32_t Timeout)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
784 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
785 if(hi2c->State == HAL_I2C_STATE_READY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
786 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
787 if((pData == NULL) || (Size == 0))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
788 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
789 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
790 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
791
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
792 if(__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BUSY) == SET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
793 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
794 return HAL_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
795 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
796
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
797 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
798 __HAL_LOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
799
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
800 hi2c->State = HAL_I2C_STATE_BUSY_TX;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
801 hi2c->ErrorCode = HAL_I2C_ERROR_NONE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
802
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
803 /* Enable Address Acknowledge */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
804 hi2c->Instance->CR1 |= I2C_CR1_ACK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
805
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
806 /* Wait until ADDR flag is set */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
807 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_ADDR, RESET, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
808 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
809 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
810 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
811
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
812 /* Clear ADDR flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
813 __HAL_I2C_CLEAR_ADDRFLAG(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
814
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
815 /* If 10bit addressing mode is selected */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
816 if(hi2c->Init.AddressingMode == I2C_ADDRESSINGMODE_10BIT)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
817 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
818 /* Wait until ADDR flag is set */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
819 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_ADDR, RESET, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
820 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
821 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
822 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
823
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
824 /* Clear ADDR flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
825 __HAL_I2C_CLEAR_ADDRFLAG(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
826 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
827
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
828 while(Size > 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
829 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
830 /* Wait until TXE flag is set */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
831 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_TXE, RESET, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
832 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
833 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
834 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
835
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
836 /* Write data to DR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
837 hi2c->Instance->DR = (*pData++);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
838 Size--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
839
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
840 if((__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BTF) == SET) && (Size != 0))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
841 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
842 /* Write data to DR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
843 hi2c->Instance->DR = (*pData++);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
844 Size--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
845 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
846 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
847
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
848 /* Wait until AF flag is set */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
849 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_AF, RESET, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
850 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
851 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
852 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
853
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
854 /* Clear AF flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
855 __HAL_I2C_CLEAR_FLAG(hi2c, I2C_FLAG_AF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
856
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
857 /* Disable Address Acknowledge */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
858 hi2c->Instance->CR1 &= ~I2C_CR1_ACK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
859
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
860 /* Wait until BUSY flag is reset */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
861 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_BUSY, SET, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
862 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
863 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
864 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
865
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
866 hi2c->State = HAL_I2C_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
867
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
868 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
869 __HAL_UNLOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
870
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
871 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
872 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
873 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
874 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
875 return HAL_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
876 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
877 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
878
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
879 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
880 * @brief Receive in slave mode an amount of data in blocking mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
881 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
882 * the configuration information for I2C module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
883 * @param pData: Pointer to data buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
884 * @param Size: Amount of data to be sent
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
885 * @param Timeout: Timeout duration
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
886 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
887 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
888 HAL_StatusTypeDef HAL_I2C_Slave_Receive(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size, uint32_t Timeout)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
889 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
890 if(hi2c->State == HAL_I2C_STATE_READY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
891 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
892 if((pData == NULL) || (Size == 0))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
893 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
894 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
895 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
896
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
897 if(__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BUSY) == SET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
898 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
899 return HAL_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
900 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
901
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
902 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
903 __HAL_LOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
904
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
905 hi2c->State = HAL_I2C_STATE_BUSY_RX;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
906 hi2c->ErrorCode = HAL_I2C_ERROR_NONE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
907
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
908 /* Enable Address Acknowledge */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
909 hi2c->Instance->CR1 |= I2C_CR1_ACK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
910
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
911 /* Wait until ADDR flag is set */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
912 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_ADDR, RESET, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
913 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
914 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
915 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
916
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
917 /* Clear ADDR flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
918 __HAL_I2C_CLEAR_ADDRFLAG(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
919
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
920 while(Size > 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
921 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
922 /* Wait until RXNE flag is set */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
923 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_RXNE, RESET, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
924 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
925 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
926 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
927
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
928 /* Read data from DR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
929 (*pData++) = hi2c->Instance->DR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
930 Size--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
931
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
932 if((__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BTF) == SET) && (Size != 0))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
933 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
934 /* Read data from DR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
935 (*pData++) = hi2c->Instance->DR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
936 Size--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
937 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
938 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
939
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
940 /* Wait until STOP flag is set */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
941 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_STOPF, RESET, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
942 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
943 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
944 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
945
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
946 /* Clear STOP flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
947 __HAL_I2C_CLEAR_STOPFLAG(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
948
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
949 /* Disable Address Acknowledge */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
950 hi2c->Instance->CR1 &= ~I2C_CR1_ACK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
951
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
952 /* Wait until BUSY flag is reset */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
953 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_BUSY, SET, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
954 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
955 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
956 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
957
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
958 hi2c->State = HAL_I2C_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
959
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
960 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
961 __HAL_UNLOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
962
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
963 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
964 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
965 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
966 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
967 return HAL_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
968 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
969 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
970
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
971 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
972 * @brief Transmit in master mode an amount of data in no-blocking mode with Interrupt
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
973 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
974 * the configuration information for I2C module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
975 * @param DevAddress: Target device address
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
976 * @param pData: Pointer to data buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
977 * @param Size: Amount of data to be sent
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
978 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
979 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
980 HAL_StatusTypeDef HAL_I2C_Master_Transmit_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
981 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
982 if(hi2c->State == HAL_I2C_STATE_READY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
983 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
984 if((pData == NULL) || (Size == 0))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
985 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
986 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
987 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
988
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
989 if(__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BUSY) == SET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
990 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
991 return HAL_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
992 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
993
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
994 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
995 __HAL_LOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
996
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
997 hi2c->State = HAL_I2C_STATE_BUSY_TX;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
998 hi2c->ErrorCode = HAL_I2C_ERROR_NONE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
999
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1000 hi2c->pBuffPtr = pData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1001 hi2c->XferSize = Size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1002 hi2c->XferCount = Size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1003
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1004 /* Send Slave Address */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1005 if(I2C_MasterRequestWrite(hi2c, DevAddress, I2C_TIMEOUT_FLAG) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1006 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1007 if(hi2c->ErrorCode == HAL_I2C_ERROR_AF)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1008 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1009 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1010 __HAL_UNLOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1011 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1012 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1013 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1014 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1015 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1016 __HAL_UNLOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1017 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1018 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1019 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1020
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1021 /* Clear ADDR flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1022 __HAL_I2C_CLEAR_ADDRFLAG(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1023
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1024 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1025 __HAL_UNLOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1026
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1027 /* Note : The I2C interrupts must be enabled after unlocking current process
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1028 to avoid the risk of I2C interrupt handle execution before current
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1029 process unlock */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1030
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1031 /* Enable EVT, BUF and ERR interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1032 __HAL_I2C_ENABLE_IT(hi2c, I2C_IT_EVT | I2C_IT_BUF | I2C_IT_ERR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1033
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1034 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1035 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1036 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1037 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1038 return HAL_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1039 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1040 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1041
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1042 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1043 * @brief Receive in master mode an amount of data in no-blocking mode with Interrupt
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1044 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1045 * the configuration information for I2C module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1046 * @param DevAddress: Target device address
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1047 * @param pData: Pointer to data buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1048 * @param Size: Amount of data to be sent
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1049 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1050 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1051 HAL_StatusTypeDef HAL_I2C_Master_Receive_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1052 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1053 if(hi2c->State == HAL_I2C_STATE_READY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1054 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1055 if((pData == NULL) || (Size == 0))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1056 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1057 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1058 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1059
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1060 if(__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BUSY) == SET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1061 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1062 return HAL_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1063 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1064
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1065 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1066 __HAL_LOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1067
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1068 hi2c->State = HAL_I2C_STATE_BUSY_RX;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1069 hi2c->ErrorCode = HAL_I2C_ERROR_NONE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1070
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1071 hi2c->pBuffPtr = pData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1072 hi2c->XferSize = Size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1073 hi2c->XferCount = Size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1074
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1075 /* Send Slave Address */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1076 if(I2C_MasterRequestRead(hi2c, DevAddress, I2C_TIMEOUT_FLAG) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1077 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1078 if(hi2c->ErrorCode == HAL_I2C_ERROR_AF)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1079 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1080 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1081 __HAL_UNLOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1082 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1083 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1084 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1085 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1086 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1087 __HAL_UNLOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1088 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1089 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1090 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1091
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1092 if(hi2c->XferCount == 1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1093 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1094 /* Disable Acknowledge */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1095 hi2c->Instance->CR1 &= ~I2C_CR1_ACK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1096
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1097 /* Clear ADDR flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1098 __HAL_I2C_CLEAR_ADDRFLAG(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1099
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1100 /* Generate Stop */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1101 hi2c->Instance->CR1 |= I2C_CR1_STOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1102 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1103 else if(hi2c->XferCount == 2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1104 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1105 /* Disable Acknowledge */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1106 hi2c->Instance->CR1 &= ~I2C_CR1_ACK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1107
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1108 /* Enable Pos */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1109 hi2c->Instance->CR1 |= I2C_CR1_POS;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1110
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1111 /* Clear ADDR flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1112 __HAL_I2C_CLEAR_ADDRFLAG(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1113 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1114 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1115 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1116 /* Enable Acknowledge */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1117 hi2c->Instance->CR1 |= I2C_CR1_ACK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1118
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1119 /* Clear ADDR flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1120 __HAL_I2C_CLEAR_ADDRFLAG(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1121 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1122
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1123 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1124 __HAL_UNLOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1125
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1126 /* Note : The I2C interrupts must be enabled after unlocking current process
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1127 to avoid the risk of I2C interrupt handle execution before current
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1128 process unlock */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1129
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1130 /* Enable EVT, BUF and ERR interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1131 __HAL_I2C_ENABLE_IT(hi2c, I2C_IT_EVT | I2C_IT_BUF | I2C_IT_ERR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1132
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1133 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1134 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1135 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1136 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1137 return HAL_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1138 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1139 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1140
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1141 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1142 * @brief Transmit in slave mode an amount of data in no-blocking mode with Interrupt
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1143 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1144 * the configuration information for I2C module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1145 * @param pData: Pointer to data buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1146 * @param Size: Amount of data to be sent
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1147 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1148 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1149 HAL_StatusTypeDef HAL_I2C_Slave_Transmit_IT(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1150 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1151 if(hi2c->State == HAL_I2C_STATE_READY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1152 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1153 if((pData == NULL) || (Size == 0))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1154 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1155 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1156 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1157
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1158 if(__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BUSY) == SET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1159 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1160 return HAL_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1161 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1162
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1163 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1164 __HAL_LOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1165
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1166 hi2c->State = HAL_I2C_STATE_BUSY_TX;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1167 hi2c->ErrorCode = HAL_I2C_ERROR_NONE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1168
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1169 hi2c->pBuffPtr = pData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1170 hi2c->XferSize = Size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1171 hi2c->XferCount = Size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1172
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1173 /* Enable Address Acknowledge */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1174 hi2c->Instance->CR1 |= I2C_CR1_ACK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1175
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1176 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1177 __HAL_UNLOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1178
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1179 /* Note : The I2C interrupts must be enabled after unlocking current process
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1180 to avoid the risk of I2C interrupt handle execution before current
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1181 process unlock */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1182
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1183 /* Enable EVT, BUF and ERR interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1184 __HAL_I2C_ENABLE_IT(hi2c, I2C_IT_EVT | I2C_IT_BUF | I2C_IT_ERR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1185
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1186 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1187 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1188 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1189 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1190 return HAL_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1191 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1192 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1193
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1194 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1195 * @brief Receive in slave mode an amount of data in no-blocking mode with Interrupt
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1196 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1197 * the configuration information for I2C module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1198 * @param pData: Pointer to data buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1199 * @param Size: Amount of data to be sent
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1200 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1201 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1202 HAL_StatusTypeDef HAL_I2C_Slave_Receive_IT(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1203 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1204 if(hi2c->State == HAL_I2C_STATE_READY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1205 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1206 if((pData == NULL) || (Size == 0))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1207 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1208 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1209 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1210
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1211 if(__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BUSY) == SET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1212 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1213 return HAL_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1214 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1215
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1216 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1217 __HAL_LOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1218
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1219 hi2c->State = HAL_I2C_STATE_BUSY_RX;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1220 hi2c->ErrorCode = HAL_I2C_ERROR_NONE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1221
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1222 hi2c->pBuffPtr = pData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1223 hi2c->XferSize = Size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1224 hi2c->XferCount = Size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1225
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1226 /* Enable Address Acknowledge */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1227 hi2c->Instance->CR1 |= I2C_CR1_ACK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1228
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1229 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1230 __HAL_UNLOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1231
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1232 /* Note : The I2C interrupts must be enabled after unlocking current process
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1233 to avoid the risk of I2C interrupt handle execution before current
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1234 process unlock */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1235
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1236 /* Enable EVT, BUF and ERR interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1237 __HAL_I2C_ENABLE_IT(hi2c, I2C_IT_EVT | I2C_IT_BUF | I2C_IT_ERR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1238
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1239 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1240 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1241 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1242 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1243 return HAL_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1244 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1245 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1246
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1247 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1248 * @brief Transmit in master mode an amount of data in no-blocking mode with DMA
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1249 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1250 * the configuration information for I2C module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1251 * @param DevAddress: Target device address
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1252 * @param pData: Pointer to data buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1253 * @param Size: Amount of data to be sent
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1254 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1255 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1256 HAL_StatusTypeDef HAL_I2C_Master_Transmit_DMA(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1257 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1258 if(hi2c->State == HAL_I2C_STATE_READY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1259 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1260 if((pData == NULL) || (Size == 0))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1261 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1262 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1263 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1264
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1265 if(__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BUSY) == SET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1266 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1267 return HAL_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1268 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1269
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1270 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1271 __HAL_LOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1272
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1273 hi2c->State = HAL_I2C_STATE_BUSY_TX;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1274 hi2c->ErrorCode = HAL_I2C_ERROR_NONE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1275
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1276 hi2c->pBuffPtr = pData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1277 hi2c->XferSize = Size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1278 hi2c->XferCount = Size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1279
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1280 /* Set the I2C DMA transfer complete callback */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1281 hi2c->hdmatx->XferCpltCallback = I2C_DMAMasterTransmitCplt;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1282
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1283 /* Set the DMA error callback */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1284 hi2c->hdmatx->XferErrorCallback = I2C_DMAError;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1285
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1286 /* Enable the DMA Stream */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1287 HAL_DMA_Start_IT(hi2c->hdmatx, (uint32_t)pData, (uint32_t)&hi2c->Instance->DR, Size);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1288
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1289 /* Send Slave Address */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1290 if(I2C_MasterRequestWrite(hi2c, DevAddress, I2C_TIMEOUT_FLAG) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1291 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1292 if(hi2c->ErrorCode == HAL_I2C_ERROR_AF)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1293 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1294 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1295 __HAL_UNLOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1296 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1297 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1298 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1299 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1300 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1301 __HAL_UNLOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1302 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1303 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1304 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1305
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1306 /* Enable DMA Request */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1307 hi2c->Instance->CR2 |= I2C_CR2_DMAEN;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1308
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1309 /* Clear ADDR flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1310 __HAL_I2C_CLEAR_ADDRFLAG(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1311
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1312 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1313 __HAL_UNLOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1314
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1315 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1316 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1317 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1318 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1319 return HAL_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1320 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1321 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1322
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1323 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1324 * @brief Receive in master mode an amount of data in no-blocking mode with DMA
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1325 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1326 * the configuration information for I2C module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1327 * @param DevAddress: Target device address
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1328 * @param pData: Pointer to data buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1329 * @param Size: Amount of data to be sent
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1330 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1331 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1332 HAL_StatusTypeDef HAL_I2C_Master_Receive_DMA(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1333 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1334 if(hi2c->State == HAL_I2C_STATE_READY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1335 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1336 if((pData == NULL) || (Size == 0))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1337 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1338 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1339 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1340
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1341 if(__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BUSY) == SET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1342 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1343 return HAL_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1344 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1345
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1346 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1347 __HAL_LOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1348
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1349 hi2c->State = HAL_I2C_STATE_BUSY_RX;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1350 hi2c->ErrorCode = HAL_I2C_ERROR_NONE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1351
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1352 hi2c->pBuffPtr = pData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1353 hi2c->XferSize = Size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1354 hi2c->XferCount = Size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1355
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1356 /* Set the I2C DMA transfer complete callback */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1357 hi2c->hdmarx->XferCpltCallback = I2C_DMAMasterReceiveCplt;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1358
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1359 /* Set the DMA error callback */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1360 hi2c->hdmarx->XferErrorCallback = I2C_DMAError;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1361
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1362 /* Enable the DMA Stream */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1363 HAL_DMA_Start_IT(hi2c->hdmarx, (uint32_t)&hi2c->Instance->DR, (uint32_t)pData, Size);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1364
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1365 /* Send Slave Address */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1366 if(I2C_MasterRequestRead(hi2c, DevAddress, I2C_TIMEOUT_FLAG) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1367 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1368 if(hi2c->ErrorCode == HAL_I2C_ERROR_AF)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1369 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1370 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1371 __HAL_UNLOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1372 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1373 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1374 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1375 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1376 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1377 __HAL_UNLOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1378 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1379 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1380 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1381
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1382 if(Size == 1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1383 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1384 /* Disable Acknowledge */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1385 hi2c->Instance->CR1 &= ~I2C_CR1_ACK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1386 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1387 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1388 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1389 /* Enable Last DMA bit */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1390 hi2c->Instance->CR2 |= I2C_CR2_LAST;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1391 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1392
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1393 /* Enable DMA Request */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1394 hi2c->Instance->CR2 |= I2C_CR2_DMAEN;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1395
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1396 /* Clear ADDR flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1397 __HAL_I2C_CLEAR_ADDRFLAG(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1398
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1399 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1400 __HAL_UNLOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1401
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1402 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1403 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1404 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1405 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1406 return HAL_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1407 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1408 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1409
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1410 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1411 * @brief Transmit in slave mode an amount of data in no-blocking mode with DMA
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1412 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1413 * the configuration information for I2C module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1414 * @param pData: Pointer to data buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1415 * @param Size: Amount of data to be sent
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1416 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1417 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1418 HAL_StatusTypeDef HAL_I2C_Slave_Transmit_DMA(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1419 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1420 if(hi2c->State == HAL_I2C_STATE_READY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1421 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1422 if((pData == NULL) || (Size == 0))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1423 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1424 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1425 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1426
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1427 if(__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BUSY) == SET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1428 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1429 return HAL_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1430 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1431
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1432 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1433 __HAL_LOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1434
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1435 hi2c->State = HAL_I2C_STATE_BUSY_TX;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1436 hi2c->ErrorCode = HAL_I2C_ERROR_NONE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1437
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1438 hi2c->pBuffPtr = pData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1439 hi2c->XferSize = Size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1440 hi2c->XferCount = Size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1441
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1442 /* Set the I2C DMA transfer complete callback */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1443 hi2c->hdmatx->XferCpltCallback = I2C_DMASlaveTransmitCplt;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1444
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1445 /* Set the DMA error callback */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1446 hi2c->hdmatx->XferErrorCallback = I2C_DMAError;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1447
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1448 /* Enable the DMA Stream */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1449 HAL_DMA_Start_IT(hi2c->hdmatx, (uint32_t)pData, (uint32_t)&hi2c->Instance->DR, Size);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1450
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1451 /* Enable DMA Request */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1452 hi2c->Instance->CR2 |= I2C_CR2_DMAEN;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1453
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1454 /* Enable Address Acknowledge */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1455 hi2c->Instance->CR1 |= I2C_CR1_ACK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1456
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1457 /* Wait until ADDR flag is set */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1458 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_ADDR, RESET, I2C_TIMEOUT_ADDR_SLAVE) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1459 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1460 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1461 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1462
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1463 /* If 7bit addressing mode is selected */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1464 if(hi2c->Init.AddressingMode == I2C_ADDRESSINGMODE_7BIT)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1465 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1466 /* Clear ADDR flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1467 __HAL_I2C_CLEAR_ADDRFLAG(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1468 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1469 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1470 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1471 /* Clear ADDR flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1472 __HAL_I2C_CLEAR_ADDRFLAG(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1473
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1474 /* Wait until ADDR flag is set */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1475 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_ADDR, RESET, I2C_TIMEOUT_ADDR_SLAVE) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1476 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1477 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1478 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1479
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1480 /* Clear ADDR flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1481 __HAL_I2C_CLEAR_ADDRFLAG(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1482 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1483
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1484 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1485 __HAL_UNLOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1486
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1487 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1488 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1489 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1490 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1491 return HAL_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1492 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1493 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1494
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1495 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1496 * @brief Receive in slave mode an amount of data in no-blocking mode with DMA
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1497 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1498 * the configuration information for I2C module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1499 * @param pData: Pointer to data buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1500 * @param Size: Amount of data to be sent
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1501 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1502 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1503 HAL_StatusTypeDef HAL_I2C_Slave_Receive_DMA(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1504 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1505 if(hi2c->State == HAL_I2C_STATE_READY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1506 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1507 if((pData == NULL) || (Size == 0))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1508 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1509 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1510 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1511
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1512 if(__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BUSY) == SET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1513 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1514 return HAL_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1515 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1516
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1517 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1518 __HAL_LOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1519
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1520 hi2c->State = HAL_I2C_STATE_BUSY_RX;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1521 hi2c->ErrorCode = HAL_I2C_ERROR_NONE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1522
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1523 hi2c->pBuffPtr = pData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1524 hi2c->XferSize = Size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1525 hi2c->XferCount = Size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1526
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1527 /* Set the I2C DMA transfer complete callback */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1528 hi2c->hdmarx->XferCpltCallback = I2C_DMASlaveReceiveCplt;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1529
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1530 /* Set the DMA error callback */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1531 hi2c->hdmarx->XferErrorCallback = I2C_DMAError;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1532
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1533 /* Enable the DMA Stream */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1534 HAL_DMA_Start_IT(hi2c->hdmarx, (uint32_t)&hi2c->Instance->DR, (uint32_t)pData, Size);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1535
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1536 /* Enable DMA Request */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1537 hi2c->Instance->CR2 |= I2C_CR2_DMAEN;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1538
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1539 /* Enable Address Acknowledge */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1540 hi2c->Instance->CR1 |= I2C_CR1_ACK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1541
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1542 /* Wait until ADDR flag is set */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1543 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_ADDR, RESET, I2C_TIMEOUT_ADDR_SLAVE) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1544 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1545 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1546 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1547
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1548 /* Clear ADDR flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1549 __HAL_I2C_CLEAR_ADDRFLAG(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1550
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1551 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1552 __HAL_UNLOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1553
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1554 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1555 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1556 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1557 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1558 return HAL_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1559 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1560 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1561 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1562 * @brief Write an amount of data in blocking mode to a specific memory address
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1563 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1564 * the configuration information for I2C module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1565 * @param DevAddress: Target device address
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1566 * @param MemAddress: Internal memory address
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1567 * @param MemAddSize: Size of internal memory address
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1568 * @param pData: Pointer to data buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1569 * @param Size: Amount of data to be sent
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1570 * @param Timeout: Timeout duration
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1571 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1572 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1573 HAL_StatusTypeDef HAL_I2C_Mem_Write(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size, uint32_t Timeout)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1574 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1575 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1576 assert_param(IS_I2C_MEMADD_SIZE(MemAddSize));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1577
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1578 if(hi2c->State == HAL_I2C_STATE_READY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1579 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1580 if((pData == NULL) || (Size == 0))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1581 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1582 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1583 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1584
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1585 if(__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BUSY) == SET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1586 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1587 return HAL_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1588 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1589
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1590 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1591 __HAL_LOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1592
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1593 hi2c->State = HAL_I2C_STATE_MEM_BUSY_TX;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1594 hi2c->ErrorCode = HAL_I2C_ERROR_NONE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1595
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1596 /* Send Slave Address and Memory Address */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1597 if(I2C_RequestMemoryWrite(hi2c, DevAddress, MemAddress, MemAddSize, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1598 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1599 if(hi2c->ErrorCode == HAL_I2C_ERROR_AF)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1600 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1601 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1602 __HAL_UNLOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1603 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1604 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1605 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1606 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1607 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1608 __HAL_UNLOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1609 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1610 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1611 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1612
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1613 while(Size > 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1614 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1615 /* Wait until TXE flag is set */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1616 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_TXE, RESET, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1617 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1618 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1619 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1620
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1621 /* Write data to DR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1622 hi2c->Instance->DR = (*pData++);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1623 Size--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1624
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1625 if((__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BTF) == SET) && (Size != 0))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1626 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1627 /* Write data to DR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1628 hi2c->Instance->DR = (*pData++);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1629 Size--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1630 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1631 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1632
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1633 /* Wait until TXE flag is set */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1634 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_TXE, RESET, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1635 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1636 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1637 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1638
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1639 /* Generate Stop */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1640 hi2c->Instance->CR1 |= I2C_CR1_STOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1641
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1642 /* Wait until BUSY flag is reset */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1643 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_BUSY, SET, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1644 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1645 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1646 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1647
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1648 hi2c->State = HAL_I2C_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1649
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1650 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1651 __HAL_UNLOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1652
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1653 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1654 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1655 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1656 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1657 return HAL_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1658 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1659 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1660
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1661 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1662 * @brief Read an amount of data in blocking mode from a specific memory address
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1663 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1664 * the configuration information for I2C module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1665 * @param DevAddress: Target device address
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1666 * @param MemAddress: Internal memory address
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1667 * @param MemAddSize: Size of internal memory address
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1668 * @param pData: Pointer to data buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1669 * @param Size: Amount of data to be sent
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1670 * @param Timeout: Timeout duration
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1671 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1672 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1673 HAL_StatusTypeDef HAL_I2C_Mem_Read(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size, uint32_t Timeout)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1674 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1675 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1676 assert_param(IS_I2C_MEMADD_SIZE(MemAddSize));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1677
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1678 if(hi2c->State == HAL_I2C_STATE_READY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1679 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1680 if((pData == NULL) || (Size == 0))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1681 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1682 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1683 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1684
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1685 if(__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BUSY) == SET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1686 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1687 return HAL_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1688 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1689
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1690 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1691 __HAL_LOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1692
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1693 hi2c->State = HAL_I2C_STATE_MEM_BUSY_RX;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1694 hi2c->ErrorCode = HAL_I2C_ERROR_NONE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1695
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1696 /* Send Slave Address and Memory Address */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1697 if(I2C_RequestMemoryRead(hi2c, DevAddress, MemAddress, MemAddSize, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1698 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1699 if(hi2c->ErrorCode == HAL_I2C_ERROR_AF)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1700 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1701 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1702 __HAL_UNLOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1703 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1704 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1705 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1706 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1707 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1708 __HAL_UNLOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1709 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1710 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1711 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1712
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1713 if(Size == 1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1714 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1715 /* Disable Acknowledge */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1716 hi2c->Instance->CR1 &= ~I2C_CR1_ACK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1717
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1718 /* Clear ADDR flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1719 __HAL_I2C_CLEAR_ADDRFLAG(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1720
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1721 /* Generate Stop */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1722 hi2c->Instance->CR1 |= I2C_CR1_STOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1723 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1724 else if(Size == 2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1725 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1726 /* Disable Acknowledge */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1727 hi2c->Instance->CR1 &= ~I2C_CR1_ACK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1728
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1729 /* Enable Pos */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1730 hi2c->Instance->CR1 |= I2C_CR1_POS;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1731
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1732 /* Clear ADDR flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1733 __HAL_I2C_CLEAR_ADDRFLAG(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1734 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1735 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1736 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1737 /* Clear ADDR flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1738 __HAL_I2C_CLEAR_ADDRFLAG(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1739 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1740
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1741 while(Size > 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1742 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1743 if(Size <= 3)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1744 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1745 /* One byte */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1746 if(Size== 1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1747 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1748 /* Wait until RXNE flag is set */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1749 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_RXNE, RESET, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1750 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1751 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1752 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1753
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1754 /* Read data from DR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1755 (*pData++) = hi2c->Instance->DR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1756 Size--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1757 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1758 /* Two bytes */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1759 else if(Size == 2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1760 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1761 /* Wait until BTF flag is set */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1762 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_BTF, RESET, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1763 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1764 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1765 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1766
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1767 /* Generate Stop */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1768 hi2c->Instance->CR1 |= I2C_CR1_STOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1769
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1770 /* Read data from DR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1771 (*pData++) = hi2c->Instance->DR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1772 Size--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1773
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1774 /* Read data from DR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1775 (*pData++) = hi2c->Instance->DR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1776 Size--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1777 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1778 /* 3 Last bytes */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1779 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1780 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1781 /* Wait until BTF flag is set */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1782 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_BTF, RESET, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1783 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1784 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1785 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1786
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1787 /* Disable Acknowledge */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1788 hi2c->Instance->CR1 &= ~I2C_CR1_ACK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1789
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1790 /* Read data from DR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1791 (*pData++) = hi2c->Instance->DR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1792 Size--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1793
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1794 /* Wait until BTF flag is set */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1795 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_BTF, RESET, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1796 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1797 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1798 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1799
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1800 /* Generate Stop */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1801 hi2c->Instance->CR1 |= I2C_CR1_STOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1802
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1803 /* Read data from DR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1804 (*pData++) = hi2c->Instance->DR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1805 Size--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1806
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1807 /* Read data from DR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1808 (*pData++) = hi2c->Instance->DR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1809 Size--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1810 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1811 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1812 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1813 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1814 /* Wait until RXNE flag is set */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1815 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_RXNE, RESET, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1816 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1817 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1818 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1819
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1820 /* Read data from DR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1821 (*pData++) = hi2c->Instance->DR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1822 Size--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1823
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1824 if(__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BTF) == SET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1825 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1826 /* Read data from DR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1827 (*pData++) = hi2c->Instance->DR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1828 Size--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1829 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1830 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1831 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1832
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1833 /* Disable Pos */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1834 hi2c->Instance->CR1 &= ~I2C_CR1_POS;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1835
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1836 /* Wait until BUSY flag is reset */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1837 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_BUSY, SET, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1838 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1839 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1840 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1841
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1842 hi2c->State = HAL_I2C_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1843
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1844 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1845 __HAL_UNLOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1846
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1847 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1848 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1849 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1850 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1851 return HAL_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1852 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1853 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1854 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1855 * @brief Write an amount of data in no-blocking mode with Interrupt to a specific memory address
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1856 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1857 * the configuration information for I2C module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1858 * @param DevAddress: Target device address
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1859 * @param MemAddress: Internal memory address
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1860 * @param MemAddSize: Size of internal memory address
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1861 * @param pData: Pointer to data buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1862 * @param Size: Amount of data to be sent
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1863 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1864 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1865 HAL_StatusTypeDef HAL_I2C_Mem_Write_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1866 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1867 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1868 assert_param(IS_I2C_MEMADD_SIZE(MemAddSize));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1869
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1870 if(hi2c->State == HAL_I2C_STATE_READY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1871 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1872 if((pData == NULL) || (Size == 0))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1873 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1874 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1875 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1876
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1877 if(__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BUSY) == SET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1878 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1879 return HAL_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1880 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1881
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1882 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1883 __HAL_LOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1884
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1885 hi2c->State = HAL_I2C_STATE_MEM_BUSY_TX;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1886 hi2c->ErrorCode = HAL_I2C_ERROR_NONE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1887
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1888 hi2c->pBuffPtr = pData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1889 hi2c->XferSize = Size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1890 hi2c->XferCount = Size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1891
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1892 /* Send Slave Address and Memory Address */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1893 if(I2C_RequestMemoryWrite(hi2c, DevAddress, MemAddress, MemAddSize, I2C_TIMEOUT_FLAG) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1894 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1895 if(hi2c->ErrorCode == HAL_I2C_ERROR_AF)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1896 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1897 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1898 __HAL_UNLOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1899 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1900 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1901 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1902 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1903 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1904 __HAL_UNLOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1905 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1906 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1907 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1908
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1909 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1910 __HAL_UNLOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1911
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1912 /* Note : The I2C interrupts must be enabled after unlocking current process
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1913 to avoid the risk of I2C interrupt handle execution before current
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1914 process unlock */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1915
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1916 /* Enable EVT, BUF and ERR interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1917 __HAL_I2C_ENABLE_IT(hi2c, I2C_IT_EVT | I2C_IT_BUF | I2C_IT_ERR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1918
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1919 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1920 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1921 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1922 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1923 return HAL_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1924 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1925 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1926
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1927 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1928 * @brief Read an amount of data in no-blocking mode with Interrupt from a specific memory address
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1929 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1930 * the configuration information for I2C module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1931 * @param DevAddress: Target device address
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1932 * @param MemAddress: Internal memory address
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1933 * @param MemAddSize: Size of internal memory address
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1934 * @param pData: Pointer to data buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1935 * @param Size: Amount of data to be sent
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1936 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1937 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1938 HAL_StatusTypeDef HAL_I2C_Mem_Read_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1939 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1940 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1941 assert_param(IS_I2C_MEMADD_SIZE(MemAddSize));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1942
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1943 if(hi2c->State == HAL_I2C_STATE_READY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1944 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1945 if((pData == NULL) || (Size == 0))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1946 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1947 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1948 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1949
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1950 if(__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BUSY) == SET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1951 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1952 return HAL_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1953 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1954
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1955 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1956 __HAL_LOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1957
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1958 hi2c->State = HAL_I2C_STATE_MEM_BUSY_RX;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1959 hi2c->ErrorCode = HAL_I2C_ERROR_NONE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1960
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1961 hi2c->pBuffPtr = pData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1962 hi2c->XferSize = Size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1963 hi2c->XferCount = Size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1964
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1965 /* Send Slave Address and Memory Address */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1966 if(I2C_RequestMemoryRead(hi2c, DevAddress, MemAddress, MemAddSize, I2C_TIMEOUT_FLAG) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1967 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1968 if(hi2c->ErrorCode == HAL_I2C_ERROR_AF)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1969 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1970 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1971 __HAL_UNLOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1972 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1973 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1974 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1975 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1976 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1977 __HAL_UNLOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1978 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1979 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1980 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1981
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1982 if(hi2c->XferCount == 1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1983 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1984 /* Disable Acknowledge */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1985 hi2c->Instance->CR1 &= ~I2C_CR1_ACK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1986
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1987 /* Clear ADDR flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1988 __HAL_I2C_CLEAR_ADDRFLAG(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1989
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1990 /* Generate Stop */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1991 hi2c->Instance->CR1 |= I2C_CR1_STOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1992 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1993 else if(hi2c->XferCount == 2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1994 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1995 /* Disable Acknowledge */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1996 hi2c->Instance->CR1 &= ~I2C_CR1_ACK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1997
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1998 /* Enable Pos */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1999 hi2c->Instance->CR1 |= I2C_CR1_POS;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2000
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2001 /* Clear ADDR flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2002 __HAL_I2C_CLEAR_ADDRFLAG(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2003 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2004 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2005 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2006 /* Enable Acknowledge */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2007 hi2c->Instance->CR1 |= I2C_CR1_ACK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2008
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2009 /* Clear ADDR flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2010 __HAL_I2C_CLEAR_ADDRFLAG(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2011 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2012
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2013 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2014 __HAL_UNLOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2015
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2016 /* Note : The I2C interrupts must be enabled after unlocking current process
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2017 to avoid the risk of I2C interrupt handle execution before current
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2018 process unlock */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2019
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2020 /* Enable EVT, BUF and ERR interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2021 __HAL_I2C_ENABLE_IT(hi2c, I2C_IT_EVT | I2C_IT_BUF | I2C_IT_ERR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2022
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2023 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2024 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2025 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2026 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2027 return HAL_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2028 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2029 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2030 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2031 * @brief Write an amount of data in no-blocking mode with DMA to a specific memory address
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2032 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2033 * the configuration information for I2C module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2034 * @param DevAddress: Target device address
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2035 * @param MemAddress: Internal memory address
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2036 * @param MemAddSize: Size of internal memory address
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2037 * @param pData: Pointer to data buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2038 * @param Size: Amount of data to be sent
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2039 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2040 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2041 HAL_StatusTypeDef HAL_I2C_Mem_Write_DMA(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2042 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2043 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2044 assert_param(IS_I2C_MEMADD_SIZE(MemAddSize));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2045
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2046 if(hi2c->State == HAL_I2C_STATE_READY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2047 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2048 if((pData == NULL) || (Size == 0))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2049 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2050 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2051 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2052
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2053 if(__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BUSY) == SET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2054 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2055 return HAL_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2056 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2057
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2058 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2059 __HAL_LOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2060
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2061 hi2c->State = HAL_I2C_STATE_MEM_BUSY_TX;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2062 hi2c->ErrorCode = HAL_I2C_ERROR_NONE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2063
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2064 hi2c->pBuffPtr = pData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2065 hi2c->XferSize = Size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2066 hi2c->XferCount = Size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2067
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2068 /* Set the I2C DMA transfer complete callback */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2069 hi2c->hdmatx->XferCpltCallback = I2C_DMAMemTransmitCplt;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2070
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2071 /* Set the DMA error callback */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2072 hi2c->hdmatx->XferErrorCallback = I2C_DMAError;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2073
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2074 /* Enable the DMA Stream */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2075 HAL_DMA_Start_IT(hi2c->hdmatx, (uint32_t)pData, (uint32_t)&hi2c->Instance->DR, Size);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2076
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2077 /* Send Slave Address and Memory Address */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2078 if(I2C_RequestMemoryWrite(hi2c, DevAddress, MemAddress, MemAddSize, I2C_TIMEOUT_FLAG) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2079 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2080 if(hi2c->ErrorCode == HAL_I2C_ERROR_AF)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2081 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2082 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2083 __HAL_UNLOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2084 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2085 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2086 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2087 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2088 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2089 __HAL_UNLOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2090 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2091 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2092 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2093
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2094 /* Enable DMA Request */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2095 hi2c->Instance->CR2 |= I2C_CR2_DMAEN;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2096
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2097 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2098 __HAL_UNLOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2099
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2100 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2101 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2102 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2103 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2104 return HAL_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2105 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2106 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2107
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2108 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2109 * @brief Reads an amount of data in no-blocking mode with DMA from a specific memory address.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2110 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2111 * the configuration information for I2C module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2112 * @param DevAddress: Target device address
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2113 * @param MemAddress: Internal memory address
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2114 * @param MemAddSize: Size of internal memory address
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2115 * @param pData: Pointer to data buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2116 * @param Size: Amount of data to be read
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2117 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2118 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2119 HAL_StatusTypeDef HAL_I2C_Mem_Read_DMA(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2120 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2121 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2122 assert_param(IS_I2C_MEMADD_SIZE(MemAddSize));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2123
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2124 if(hi2c->State == HAL_I2C_STATE_READY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2125 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2126 if((pData == NULL) || (Size == 0))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2127 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2128 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2129 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2130
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2131 if(__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BUSY) == SET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2132 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2133 return HAL_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2134 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2135
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2136 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2137 __HAL_LOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2138
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2139 hi2c->State = HAL_I2C_STATE_MEM_BUSY_RX;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2140 hi2c->ErrorCode = HAL_I2C_ERROR_NONE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2141
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2142 hi2c->pBuffPtr = pData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2143 hi2c->XferSize = Size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2144 hi2c->XferCount = Size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2145
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2146 /* Set the I2C DMA transfer complete callback */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2147 hi2c->hdmarx->XferCpltCallback = I2C_DMAMemReceiveCplt;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2148
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2149 /* Set the DMA error callback */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2150 hi2c->hdmarx->XferErrorCallback = I2C_DMAError;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2151
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2152 /* Enable the DMA Stream */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2153 HAL_DMA_Start_IT(hi2c->hdmarx, (uint32_t)&hi2c->Instance->DR, (uint32_t)pData, Size);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2154
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2155 /* Send Slave Address and Memory Address */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2156 if(I2C_RequestMemoryRead(hi2c, DevAddress, MemAddress, MemAddSize, I2C_TIMEOUT_FLAG) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2157 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2158 if(hi2c->ErrorCode == HAL_I2C_ERROR_AF)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2159 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2160 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2161 __HAL_UNLOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2162 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2163 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2164 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2165 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2166 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2167 __HAL_UNLOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2168 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2169 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2170 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2171
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2172 if(Size == 1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2173 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2174 /* Disable Acknowledge */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2175 hi2c->Instance->CR1 &= ~I2C_CR1_ACK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2176 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2177 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2178 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2179 /* Enable Last DMA bit */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2180 hi2c->Instance->CR2 |= I2C_CR2_LAST;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2181 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2182
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2183 /* Enable DMA Request */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2184 hi2c->Instance->CR2 |= I2C_CR2_DMAEN;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2185
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2186 /* Clear ADDR flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2187 __HAL_I2C_CLEAR_ADDRFLAG(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2188
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2189 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2190 __HAL_UNLOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2191
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2192 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2193 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2194 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2195 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2196 return HAL_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2197 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2198 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2199
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2200 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2201 * @brief Checks if target device is ready for communication.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2202 * @note This function is used with Memory devices
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2203 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2204 * the configuration information for I2C module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2205 * @param DevAddress: Target device address
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2206 * @param Trials: Number of trials
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2207 * @param Timeout: Timeout duration
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2208 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2209 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2210 HAL_StatusTypeDef HAL_I2C_IsDeviceReady(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint32_t Trials, uint32_t Timeout)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2211 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2212 uint32_t tickstart = 0, tmp1 = 0, tmp2 = 0, tmp3 = 0, I2C_Trials = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2213
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2214 if(hi2c->State == HAL_I2C_STATE_READY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2215 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2216 if(__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BUSY) == SET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2217 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2218 return HAL_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2219 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2220
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2221 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2222 __HAL_LOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2223
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2224 hi2c->State = HAL_I2C_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2225 hi2c->ErrorCode = HAL_I2C_ERROR_NONE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2226
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2227 do
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2228 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2229 /* Generate Start */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2230 hi2c->Instance->CR1 |= I2C_CR1_START;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2231
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2232 /* Wait until SB flag is set */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2233 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_SB, RESET, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2234 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2235 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2236 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2237
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2238 /* Send slave address */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2239 hi2c->Instance->DR = I2C_7BIT_ADD_WRITE(DevAddress);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2240
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2241 /* Wait until ADDR or AF flag are set */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2242 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2243 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2244
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2245 tmp1 = __HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_ADDR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2246 tmp2 = __HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_AF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2247 tmp3 = hi2c->State;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2248 while((tmp1 == RESET) && (tmp2 == RESET) && (tmp3 != HAL_I2C_STATE_TIMEOUT))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2249 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2250 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2251 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2252 hi2c->State = HAL_I2C_STATE_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2253 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2254 tmp1 = __HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_ADDR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2255 tmp2 = __HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_AF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2256 tmp3 = hi2c->State;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2257 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2258
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2259 hi2c->State = HAL_I2C_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2260
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2261 /* Check if the ADDR flag has been set */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2262 if(__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_ADDR) == SET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2263 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2264 /* Generate Stop */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2265 hi2c->Instance->CR1 |= I2C_CR1_STOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2266
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2267 /* Clear ADDR Flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2268 __HAL_I2C_CLEAR_ADDRFLAG(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2269
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2270 /* Wait until BUSY flag is reset */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2271 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_BUSY, SET, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2272 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2273 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2274 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2275
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2276 hi2c->State = HAL_I2C_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2277
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2278 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2279 __HAL_UNLOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2280
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2281 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2282 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2283 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2284 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2285 /* Generate Stop */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2286 hi2c->Instance->CR1 |= I2C_CR1_STOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2287
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2288 /* Clear AF Flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2289 __HAL_I2C_CLEAR_FLAG(hi2c, I2C_FLAG_AF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2290
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2291 /* Wait until BUSY flag is reset */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2292 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_BUSY, SET, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2293 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2294 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2295 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2296 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2297 }while(I2C_Trials++ < Trials);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2298
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2299 hi2c->State = HAL_I2C_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2300
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2301 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2302 __HAL_UNLOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2303
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2304 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2305 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2306 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2307 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2308 return HAL_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2309 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2310 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2311
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2312 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2313 * @brief This function handles I2C event interrupt request.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2314 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2315 * the configuration information for I2C module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2316 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2317 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2318 void HAL_I2C_EV_IRQHandler(I2C_HandleTypeDef *hi2c)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2319 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2320 uint32_t tmp1 = 0, tmp2 = 0, tmp3 = 0, tmp4 = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2321 /* Master mode selected */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2322 if(__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_MSL) == SET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2323 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2324 /* I2C in mode Transmitter -----------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2325 if(__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_TRA) == SET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2326 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2327 tmp1 = __HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_TXE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2328 tmp2 = __HAL_I2C_GET_IT_SOURCE(hi2c, I2C_IT_BUF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2329 tmp3 = __HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BTF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2330 tmp4 = __HAL_I2C_GET_IT_SOURCE(hi2c, I2C_IT_EVT);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2331 /* TXE set and BTF reset -----------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2332 if((tmp1 == SET) && (tmp2 == SET) && (tmp3 == RESET))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2333 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2334 I2C_MasterTransmit_TXE(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2335 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2336 /* BTF set -------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2337 else if((tmp3 == SET) && (tmp4 == SET))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2338 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2339 I2C_MasterTransmit_BTF(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2340 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2341 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2342 /* I2C in mode Receiver --------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2343 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2344 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2345 tmp1 = __HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_RXNE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2346 tmp2 = __HAL_I2C_GET_IT_SOURCE(hi2c, I2C_IT_BUF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2347 tmp3 = __HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BTF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2348 tmp4 = __HAL_I2C_GET_IT_SOURCE(hi2c, I2C_IT_EVT);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2349 /* RXNE set and BTF reset -----------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2350 if((tmp1 == SET) && (tmp2 == SET) && (tmp3 == RESET))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2351 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2352 I2C_MasterReceive_RXNE(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2353 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2354 /* BTF set -------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2355 else if((tmp3 == SET) && (tmp4 == SET))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2356 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2357 I2C_MasterReceive_BTF(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2358 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2359 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2360 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2361 /* Slave mode selected */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2362 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2363 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2364 tmp1 = __HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_ADDR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2365 tmp2 = __HAL_I2C_GET_IT_SOURCE(hi2c, (I2C_IT_EVT));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2366 tmp3 = __HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_STOPF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2367 tmp4 = __HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_TRA);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2368 /* ADDR set --------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2369 if((tmp1 == SET) && (tmp2 == SET))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2370 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2371 I2C_Slave_ADDR(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2372 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2373 /* STOPF set --------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2374 else if((tmp3 == SET) && (tmp2 == SET))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2375 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2376 I2C_Slave_STOPF(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2377 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2378 /* I2C in mode Transmitter -----------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2379 else if(tmp4 == SET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2380 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2381 tmp1 = __HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_TXE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2382 tmp2 = __HAL_I2C_GET_IT_SOURCE(hi2c, I2C_IT_BUF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2383 tmp3 = __HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BTF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2384 tmp4 = __HAL_I2C_GET_IT_SOURCE(hi2c, I2C_IT_EVT);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2385 /* TXE set and BTF reset -----------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2386 if((tmp1 == SET) && (tmp2 == SET) && (tmp3 == RESET))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2387 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2388 I2C_SlaveTransmit_TXE(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2389 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2390 /* BTF set -------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2391 else if((tmp3 == SET) && (tmp4 == SET))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2392 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2393 I2C_SlaveTransmit_BTF(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2394 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2395 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2396 /* I2C in mode Receiver --------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2397 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2398 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2399 tmp1 = __HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_RXNE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2400 tmp2 = __HAL_I2C_GET_IT_SOURCE(hi2c, I2C_IT_BUF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2401 tmp3 = __HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BTF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2402 tmp4 = __HAL_I2C_GET_IT_SOURCE(hi2c, I2C_IT_EVT);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2403 /* RXNE set and BTF reset ----------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2404 if((tmp1 == SET) && (tmp2 == SET) && (tmp3 == RESET))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2405 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2406 I2C_SlaveReceive_RXNE(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2407 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2408 /* BTF set -------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2409 else if((tmp3 == SET) && (tmp4 == SET))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2410 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2411 I2C_SlaveReceive_BTF(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2412 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2413 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2414 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2415 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2416
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2417 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2418 * @brief This function handles I2C error interrupt request.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2419 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2420 * the configuration information for I2C module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2421 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2422 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2423 void HAL_I2C_ER_IRQHandler(I2C_HandleTypeDef *hi2c)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2424 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2425 uint32_t tmp1 = 0, tmp2 = 0, tmp3 = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2426
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2427 tmp1 = __HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BERR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2428 tmp2 = __HAL_I2C_GET_IT_SOURCE(hi2c, I2C_IT_ERR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2429 /* I2C Bus error interrupt occurred ----------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2430 if((tmp1 == SET) && (tmp2 == SET))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2431 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2432 hi2c->ErrorCode |= HAL_I2C_ERROR_BERR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2433
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2434 /* Clear BERR flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2435 __HAL_I2C_CLEAR_FLAG(hi2c, I2C_FLAG_BERR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2436 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2437
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2438 tmp1 = __HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_ARLO);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2439 tmp2 = __HAL_I2C_GET_IT_SOURCE(hi2c, I2C_IT_ERR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2440 /* I2C Arbitration Loss error interrupt occurred ---------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2441 if((tmp1 == SET) && (tmp2 == SET))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2442 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2443 hi2c->ErrorCode |= HAL_I2C_ERROR_ARLO;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2444
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2445 /* Clear ARLO flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2446 __HAL_I2C_CLEAR_FLAG(hi2c, I2C_FLAG_ARLO);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2447 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2448
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2449 tmp1 = __HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_AF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2450 tmp2 = __HAL_I2C_GET_IT_SOURCE(hi2c, I2C_IT_ERR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2451 /* I2C Acknowledge failure error interrupt occurred ------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2452 if((tmp1 == SET) && (tmp2 == SET))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2453 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2454 tmp1 = __HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_MSL);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2455 tmp2 = hi2c->XferCount;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2456 tmp3 = hi2c->State;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2457 if((tmp1 == RESET) && (tmp2 == 0) && (tmp3 == HAL_I2C_STATE_BUSY_TX))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2458 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2459 I2C_Slave_AF(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2460 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2461 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2462 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2463 hi2c->ErrorCode |= HAL_I2C_ERROR_AF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2464 /* Clear AF flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2465 __HAL_I2C_CLEAR_FLAG(hi2c, I2C_FLAG_AF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2466 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2467 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2468
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2469 tmp1 = __HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_OVR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2470 tmp2 = __HAL_I2C_GET_IT_SOURCE(hi2c, I2C_IT_ERR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2471 /* I2C Over-Run/Under-Run interrupt occurred -------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2472 if((tmp1 == SET) && (tmp2 == SET))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2473 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2474 hi2c->ErrorCode |= HAL_I2C_ERROR_OVR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2475 /* Clear OVR flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2476 __HAL_I2C_CLEAR_FLAG(hi2c, I2C_FLAG_OVR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2477 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2478
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2479 if(hi2c->ErrorCode != HAL_I2C_ERROR_NONE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2480 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2481 hi2c->State = HAL_I2C_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2482
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2483 /* Disable Pos bit in I2C CR1 when error occurred in Master/Mem Receive IT Process */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2484 hi2c->Instance->CR1 &= ~I2C_CR1_POS;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2485
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2486 HAL_I2C_ErrorCallback(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2487 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2488 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2489
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2490 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2491 * @brief Master Tx Transfer completed callbacks.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2492 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2493 * the configuration information for I2C module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2494 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2495 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2496 __weak void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *hi2c)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2497 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2498 /* NOTE : This function Should not be modified, when the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2499 the HAL_I2C_TxCpltCallback could be implemented in the user file
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2500 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2501 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2502
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2503 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2504 * @brief Master Rx Transfer completed callbacks.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2505 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2506 * the configuration information for I2C module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2507 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2508 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2509 __weak void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *hi2c)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2510 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2511 /* NOTE : This function Should not be modified, when the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2512 the HAL_I2C_TxCpltCallback could be implemented in the user file
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2513 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2514 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2515
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2516 /** @brief Slave Tx Transfer completed callbacks.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2517 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2518 * the configuration information for I2C module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2519 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2520 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2521 __weak void HAL_I2C_SlaveTxCpltCallback(I2C_HandleTypeDef *hi2c)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2522 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2523 /* NOTE : This function Should not be modified, when the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2524 the HAL_I2C_TxCpltCallback could be implemented in the user file
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2525 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2526 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2527
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2528 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2529 * @brief Slave Rx Transfer completed callbacks.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2530 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2531 * the configuration information for I2C module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2532 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2533 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2534 __weak void HAL_I2C_SlaveRxCpltCallback(I2C_HandleTypeDef *hi2c)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2535 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2536 /* NOTE : This function Should not be modified, when the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2537 the HAL_I2C_TxCpltCallback could be implemented in the user file
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2538 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2539 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2540
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2541 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2542 * @brief Memory Tx Transfer completed callbacks.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2543 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2544 * the configuration information for I2C module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2545 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2546 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2547 __weak void HAL_I2C_MemTxCpltCallback(I2C_HandleTypeDef *hi2c)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2548 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2549 /* NOTE : This function Should not be modified, when the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2550 the HAL_I2C_TxCpltCallback could be implemented in the user file
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2551 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2552 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2553
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2554 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2555 * @brief Memory Rx Transfer completed callbacks.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2556 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2557 * the configuration information for I2C module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2558 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2559 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2560 __weak void HAL_I2C_MemRxCpltCallback(I2C_HandleTypeDef *hi2c)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2561 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2562 /* NOTE : This function Should not be modified, when the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2563 the HAL_I2C_TxCpltCallback could be implemented in the user file
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2564 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2565 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2566
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2567 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2568 * @brief I2C error callbacks.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2569 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2570 * the configuration information for I2C module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2571 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2572 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2573 __weak void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *hi2c)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2574 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2575 /* NOTE : This function Should not be modified, when the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2576 the HAL_I2C_ErrorCallback could be implemented in the user file
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2577 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2578 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2579
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2580 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2581 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2582 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2583
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2584 /** @defgroup I2C_Exported_Functions_Group3 Peripheral State and Errors functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2585 * @brief Peripheral State and Errors functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2586 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2587 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2588 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2589 ##### Peripheral State and Errors functions #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2590 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2591 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2592 This subsection permits to get in run-time the status of the peripheral
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2593 and the data flow.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2594
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2595 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2596 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2597 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2598
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2599 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2600 * @brief Returns the I2C state.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2601 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2602 * the configuration information for I2C module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2603 * @retval HAL state
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2604 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2605 HAL_I2C_StateTypeDef HAL_I2C_GetState(I2C_HandleTypeDef *hi2c)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2606 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2607 return hi2c->State;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2608 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2609
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2610 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2611 * @brief Return the I2C error code
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2612 * @param hi2c : pointer to a I2C_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2613 * the configuration information for the specified I2C.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2614 * @retval I2C Error Code
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2615 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2616 uint32_t HAL_I2C_GetError(I2C_HandleTypeDef *hi2c)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2617 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2618 return hi2c->ErrorCode;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2619 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2620
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2621 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2622 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2623 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2624
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2625 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2626 * @brief Handle TXE flag for Master
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2627 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2628 * the configuration information for I2C module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2629 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2630 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2631 static HAL_StatusTypeDef I2C_MasterTransmit_TXE(I2C_HandleTypeDef *hi2c)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2632 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2633 /* Write data to DR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2634 hi2c->Instance->DR = (*hi2c->pBuffPtr++);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2635 hi2c->XferCount--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2636
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2637 if(hi2c->XferCount == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2638 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2639 /* Disable BUF interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2640 __HAL_I2C_DISABLE_IT(hi2c, I2C_IT_BUF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2641 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2642
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2643 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2644 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2645
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2646 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2647 * @brief Handle BTF flag for Master transmitter
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2648 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2649 * the configuration information for I2C module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2650 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2651 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2652 static HAL_StatusTypeDef I2C_MasterTransmit_BTF(I2C_HandleTypeDef *hi2c)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2653 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2654 if(hi2c->XferCount != 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2655 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2656 /* Write data to DR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2657 hi2c->Instance->DR = (*hi2c->pBuffPtr++);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2658 hi2c->XferCount--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2659 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2660 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2661 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2662 /* Disable EVT, BUF and ERR interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2663 __HAL_I2C_DISABLE_IT(hi2c, I2C_IT_EVT | I2C_IT_BUF | I2C_IT_ERR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2664
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2665 /* Generate Stop */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2666 hi2c->Instance->CR1 |= I2C_CR1_STOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2667
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2668 /* Wait until BUSY flag is reset */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2669 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_BUSY, SET, I2C_TIMEOUT_FLAG) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2670 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2671 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2672 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2673
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2674 if(hi2c->State == HAL_I2C_STATE_MEM_BUSY_TX)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2675 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2676 hi2c->State = HAL_I2C_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2677
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2678 HAL_I2C_MemTxCpltCallback(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2679 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2680 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2681 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2682 hi2c->State = HAL_I2C_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2683
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2684 HAL_I2C_MasterTxCpltCallback(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2685 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2686 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2687 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2688 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2689
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2690 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2691 * @brief Handle RXNE flag for Master
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2692 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2693 * the configuration information for I2C module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2694 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2695 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2696 static HAL_StatusTypeDef I2C_MasterReceive_RXNE(I2C_HandleTypeDef *hi2c)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2697 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2698 uint32_t tmp = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2699
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2700 tmp = hi2c->XferCount;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2701 if(tmp > 3)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2702 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2703 /* Read data from DR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2704 (*hi2c->pBuffPtr++) = hi2c->Instance->DR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2705 hi2c->XferCount--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2706 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2707 else if((tmp == 2) || (tmp == 3))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2708 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2709 /* Disable BUF interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2710 __HAL_I2C_DISABLE_IT(hi2c, I2C_IT_BUF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2711 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2712 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2713 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2714 /* Disable EVT, BUF and ERR interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2715 __HAL_I2C_DISABLE_IT(hi2c, I2C_IT_EVT | I2C_IT_BUF | I2C_IT_ERR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2716
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2717 /* Read data from DR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2718 (*hi2c->pBuffPtr++) = hi2c->Instance->DR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2719 hi2c->XferCount--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2720
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2721 /* Wait until BUSY flag is reset */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2722 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_BUSY, SET, I2C_TIMEOUT_FLAG) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2723 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2724 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2725 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2726
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2727 /* Disable Pos */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2728 hi2c->Instance->CR1 &= ~I2C_CR1_POS;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2729
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2730 if(hi2c->State == HAL_I2C_STATE_MEM_BUSY_RX)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2731 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2732 hi2c->State = HAL_I2C_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2733
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2734 HAL_I2C_MemRxCpltCallback(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2735 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2736 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2737 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2738 hi2c->State = HAL_I2C_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2739
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2740 HAL_I2C_MasterRxCpltCallback(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2741 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2742 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2743 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2744 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2745
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2746 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2747 * @brief Handle BTF flag for Master receiver
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2748 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2749 * the configuration information for I2C module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2750 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2751 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2752 static HAL_StatusTypeDef I2C_MasterReceive_BTF(I2C_HandleTypeDef *hi2c)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2753 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2754 if(hi2c->XferCount == 3)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2755 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2756 /* Disable Acknowledge */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2757 hi2c->Instance->CR1 &= ~I2C_CR1_ACK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2758
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2759 /* Read data from DR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2760 (*hi2c->pBuffPtr++) = hi2c->Instance->DR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2761 hi2c->XferCount--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2762 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2763 else if(hi2c->XferCount == 2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2764 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2765 /* Generate Stop */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2766 hi2c->Instance->CR1 |= I2C_CR1_STOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2767
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2768 /* Read data from DR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2769 (*hi2c->pBuffPtr++) = hi2c->Instance->DR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2770 hi2c->XferCount--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2771
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2772 /* Read data from DR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2773 (*hi2c->pBuffPtr++) = hi2c->Instance->DR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2774 hi2c->XferCount--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2775
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2776 /* Disable EVT and ERR interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2777 __HAL_I2C_DISABLE_IT(hi2c, I2C_IT_EVT | I2C_IT_ERR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2778
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2779 /* Wait until BUSY flag is reset */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2780 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_BUSY, SET, I2C_TIMEOUT_FLAG) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2781 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2782 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2783 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2784
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2785 /* Disable Pos */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2786 hi2c->Instance->CR1 &= ~I2C_CR1_POS;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2787
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2788 if(hi2c->State == HAL_I2C_STATE_MEM_BUSY_RX)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2789 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2790 hi2c->State = HAL_I2C_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2791
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2792 HAL_I2C_MemRxCpltCallback(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2793 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2794 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2795 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2796 hi2c->State = HAL_I2C_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2797
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2798 HAL_I2C_MasterRxCpltCallback(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2799 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2800 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2801 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2802 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2803 /* Read data from DR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2804 (*hi2c->pBuffPtr++) = hi2c->Instance->DR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2805 hi2c->XferCount--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2806 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2807 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2808 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2809
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2810 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2811 * @brief Handle TXE flag for Slave
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2812 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2813 * the configuration information for I2C module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2814 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2815 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2816 static HAL_StatusTypeDef I2C_SlaveTransmit_TXE(I2C_HandleTypeDef *hi2c)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2817 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2818 if(hi2c->XferCount != 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2819 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2820 /* Write data to DR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2821 hi2c->Instance->DR = (*hi2c->pBuffPtr++);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2822 hi2c->XferCount--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2823 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2824 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2825 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2826
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2827 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2828 * @brief Handle BTF flag for Slave transmitter
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2829 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2830 * the configuration information for I2C module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2831 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2832 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2833 static HAL_StatusTypeDef I2C_SlaveTransmit_BTF(I2C_HandleTypeDef *hi2c)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2834 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2835 if(hi2c->XferCount != 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2836 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2837 /* Write data to DR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2838 hi2c->Instance->DR = (*hi2c->pBuffPtr++);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2839 hi2c->XferCount--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2840 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2841 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2842 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2843
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2844 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2845 * @brief Handle RXNE flag for Slave
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2846 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2847 * the configuration information for I2C module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2848 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2849 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2850 static HAL_StatusTypeDef I2C_SlaveReceive_RXNE(I2C_HandleTypeDef *hi2c)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2851 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2852 if(hi2c->XferCount != 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2853 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2854 /* Read data from DR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2855 (*hi2c->pBuffPtr++) = hi2c->Instance->DR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2856 hi2c->XferCount--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2857 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2858 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2859 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2860
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2861 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2862 * @brief Handle BTF flag for Slave receiver
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2863 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2864 * the configuration information for I2C module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2865 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2866 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2867 static HAL_StatusTypeDef I2C_SlaveReceive_BTF(I2C_HandleTypeDef *hi2c)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2868 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2869 if(hi2c->XferCount != 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2870 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2871 /* Read data from DR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2872 (*hi2c->pBuffPtr++) = hi2c->Instance->DR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2873 hi2c->XferCount--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2874 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2875 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2876 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2877
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2878 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2879 * @brief Handle ADD flag for Slave
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2880 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2881 * the configuration information for I2C module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2882 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2883 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2884 static HAL_StatusTypeDef I2C_Slave_ADDR(I2C_HandleTypeDef *hi2c)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2885 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2886 /* Clear ADDR flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2887 __HAL_I2C_CLEAR_ADDRFLAG(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2888
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2889 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2890 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2891
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2892 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2893 * @brief Handle STOPF flag for Slave
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2894 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2895 * the configuration information for I2C module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2896 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2897 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2898 static HAL_StatusTypeDef I2C_Slave_STOPF(I2C_HandleTypeDef *hi2c)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2899 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2900 /* Disable EVT, BUF and ERR interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2901 __HAL_I2C_DISABLE_IT(hi2c, I2C_IT_EVT | I2C_IT_BUF | I2C_IT_ERR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2902
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2903 /* Clear STOPF flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2904 __HAL_I2C_CLEAR_STOPFLAG(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2905
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2906 /* Disable Acknowledge */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2907 hi2c->Instance->CR1 &= ~I2C_CR1_ACK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2908
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2909 /* Wait until BUSY flag is reset */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2910 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_BUSY, SET, I2C_TIMEOUT_FLAG) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2911 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2912 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2913 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2914
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2915 hi2c->State = HAL_I2C_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2916
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2917 HAL_I2C_SlaveRxCpltCallback(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2918
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2919 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2920 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2921
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2922 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2923 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2924 * the configuration information for I2C module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2925 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2926 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2927 static HAL_StatusTypeDef I2C_Slave_AF(I2C_HandleTypeDef *hi2c)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2928 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2929 /* Disable EVT, BUF and ERR interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2930 __HAL_I2C_DISABLE_IT(hi2c, I2C_IT_EVT | I2C_IT_BUF | I2C_IT_ERR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2931
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2932 /* Clear AF flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2933 __HAL_I2C_CLEAR_FLAG(hi2c, I2C_FLAG_AF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2934
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2935 /* Disable Acknowledge */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2936 hi2c->Instance->CR1 &= ~I2C_CR1_ACK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2937
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2938 /* Wait until BUSY flag is reset */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2939 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_BUSY, SET, I2C_TIMEOUT_FLAG) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2940 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2941 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2942 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2943
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2944 hi2c->State = HAL_I2C_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2945
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2946 HAL_I2C_SlaveTxCpltCallback(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2947
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2948 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2949 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2950
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2951 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2952 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2953 * the configuration information for I2C module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2954 * @param DevAddress: Target device address
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2955 * @param Timeout: Timeout duration
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2956 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2957 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2958 static HAL_StatusTypeDef I2C_MasterRequestWrite(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint32_t Timeout)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2959 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2960 /* Generate Start */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2961 hi2c->Instance->CR1 |= I2C_CR1_START;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2962
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2963 /* Wait until SB flag is set */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2964 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_SB, RESET, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2965 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2966 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2967 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2968
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2969 if(hi2c->Init.AddressingMode == I2C_ADDRESSINGMODE_7BIT)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2970 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2971 /* Send slave address */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2972 hi2c->Instance->DR = I2C_7BIT_ADD_WRITE(DevAddress);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2973 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2974 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2975 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2976 /* Send header of slave address */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2977 hi2c->Instance->DR = I2C_10BIT_HEADER_WRITE(DevAddress);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2978
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2979 /* Wait until ADD10 flag is set */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2980 if(I2C_WaitOnMasterAddressFlagUntilTimeout(hi2c, I2C_FLAG_ADD10, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2981 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2982 if(hi2c->ErrorCode == HAL_I2C_ERROR_AF)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2983 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2984 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2985 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2986 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2987 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2988 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2989 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2990 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2991
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2992 /* Send slave address */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2993 hi2c->Instance->DR = I2C_10BIT_ADDRESS(DevAddress);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2994 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2995
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2996 /* Wait until ADDR flag is set */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2997 if(I2C_WaitOnMasterAddressFlagUntilTimeout(hi2c, I2C_FLAG_ADDR, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2998 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2999 if(hi2c->ErrorCode == HAL_I2C_ERROR_AF)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3000 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3001 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3002 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3003 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3004 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3005 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3006 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3007 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3008
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3009 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3010 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3011
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3012 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3013 * @brief Master sends target device address for read request.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3014 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3015 * the configuration information for I2C module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3016 * @param DevAddress: Target device address
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3017 * @param Timeout: Timeout duration
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3018 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3019 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3020 static HAL_StatusTypeDef I2C_MasterRequestRead(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint32_t Timeout)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3021 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3022 /* Enable Acknowledge */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3023 hi2c->Instance->CR1 |= I2C_CR1_ACK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3024
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3025 /* Generate Start */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3026 hi2c->Instance->CR1 |= I2C_CR1_START;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3027
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3028 /* Wait until SB flag is set */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3029 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_SB, RESET, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3030 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3031 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3032 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3033
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3034 if(hi2c->Init.AddressingMode == I2C_ADDRESSINGMODE_7BIT)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3035 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3036 /* Send slave address */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3037 hi2c->Instance->DR = I2C_7BIT_ADD_READ(DevAddress);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3038 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3039 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3040 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3041 /* Send header of slave address */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3042 hi2c->Instance->DR = I2C_10BIT_HEADER_WRITE(DevAddress);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3043
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3044 /* Wait until ADD10 flag is set */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3045 if(I2C_WaitOnMasterAddressFlagUntilTimeout(hi2c, I2C_FLAG_ADD10, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3046 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3047 if(hi2c->ErrorCode == HAL_I2C_ERROR_AF)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3048 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3049 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3050 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3051 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3052 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3053 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3054 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3055 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3056
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3057 /* Send slave address */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3058 hi2c->Instance->DR = I2C_10BIT_ADDRESS(DevAddress);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3059
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3060 /* Wait until ADDR flag is set */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3061 if(I2C_WaitOnMasterAddressFlagUntilTimeout(hi2c, I2C_FLAG_ADDR, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3062 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3063 if(hi2c->ErrorCode == HAL_I2C_ERROR_AF)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3064 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3065 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3066 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3067 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3068 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3069 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3070 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3071 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3072
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3073 /* Clear ADDR flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3074 __HAL_I2C_CLEAR_ADDRFLAG(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3075
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3076 /* Generate Restart */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3077 hi2c->Instance->CR1 |= I2C_CR1_START;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3078
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3079 /* Wait until SB flag is set */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3080 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_SB, RESET, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3081 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3082 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3083 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3084
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3085 /* Send header of slave address */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3086 hi2c->Instance->DR = I2C_10BIT_HEADER_READ(DevAddress);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3087 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3088
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3089 /* Wait until ADDR flag is set */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3090 if(I2C_WaitOnMasterAddressFlagUntilTimeout(hi2c, I2C_FLAG_ADDR, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3091 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3092 if(hi2c->ErrorCode == HAL_I2C_ERROR_AF)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3093 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3094 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3095 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3096 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3097 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3098 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3099 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3100 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3101
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3102 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3103 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3104
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3105 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3106 * @brief Master sends target device address followed by internal memory address for write request.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3107 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3108 * the configuration information for I2C module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3109 * @param DevAddress: Target device address
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3110 * @param MemAddress: Internal memory address
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3111 * @param MemAddSize: Size of internal memory address
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3112 * @param Timeout: Timeout duration
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3113 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3114 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3115 static HAL_StatusTypeDef I2C_RequestMemoryWrite(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint32_t Timeout)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3116 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3117 /* Generate Start */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3118 hi2c->Instance->CR1 |= I2C_CR1_START;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3119
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3120 /* Wait until SB flag is set */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3121 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_SB, RESET, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3122 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3123 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3124 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3125
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3126 /* Send slave address */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3127 hi2c->Instance->DR = I2C_7BIT_ADD_WRITE(DevAddress);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3128
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3129 /* Wait until ADDR flag is set */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3130 if(I2C_WaitOnMasterAddressFlagUntilTimeout(hi2c, I2C_FLAG_ADDR, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3131 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3132 if(hi2c->ErrorCode == HAL_I2C_ERROR_AF)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3133 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3134 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3135 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3136 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3137 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3138 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3139 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3140 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3141
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3142 /* Clear ADDR flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3143 __HAL_I2C_CLEAR_ADDRFLAG(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3144
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3145 /* Wait until TXE flag is set */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3146 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_TXE, RESET, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3147 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3148 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3149 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3150
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3151 /* If Memory address size is 8Bit */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3152 if(MemAddSize == I2C_MEMADD_SIZE_8BIT)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3153 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3154 /* Send Memory Address */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3155 hi2c->Instance->DR = I2C_MEM_ADD_LSB(MemAddress);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3156 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3157 /* If Memory address size is 16Bit */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3158 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3159 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3160 /* Send MSB of Memory Address */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3161 hi2c->Instance->DR = I2C_MEM_ADD_MSB(MemAddress);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3162
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3163 /* Wait until TXE flag is set */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3164 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_TXE, RESET, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3165 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3166 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3167 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3168
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3169 /* Send LSB of Memory Address */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3170 hi2c->Instance->DR = I2C_MEM_ADD_LSB(MemAddress);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3171 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3172
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3173 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3174 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3175
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3176 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3177 * @brief Master sends target device address followed by internal memory address for read request.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3178 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3179 * the configuration information for I2C module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3180 * @param DevAddress: Target device address
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3181 * @param MemAddress: Internal memory address
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3182 * @param MemAddSize: Size of internal memory address
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3183 * @param Timeout: Timeout duration
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3184 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3185 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3186 static HAL_StatusTypeDef I2C_RequestMemoryRead(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint32_t Timeout)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3187 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3188 /* Enable Acknowledge */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3189 hi2c->Instance->CR1 |= I2C_CR1_ACK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3190
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3191 /* Generate Start */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3192 hi2c->Instance->CR1 |= I2C_CR1_START;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3193
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3194 /* Wait until SB flag is set */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3195 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_SB, RESET, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3196 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3197 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3198 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3199
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3200 /* Send slave address */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3201 hi2c->Instance->DR = I2C_7BIT_ADD_WRITE(DevAddress);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3202
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3203 /* Wait until ADDR flag is set */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3204 if(I2C_WaitOnMasterAddressFlagUntilTimeout(hi2c, I2C_FLAG_ADDR, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3205 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3206 if(hi2c->ErrorCode == HAL_I2C_ERROR_AF)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3207 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3208 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3209 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3210 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3211 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3212 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3213 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3214 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3215
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3216 /* Clear ADDR flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3217 __HAL_I2C_CLEAR_ADDRFLAG(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3218
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3219 /* Wait until TXE flag is set */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3220 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_TXE, RESET, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3221 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3222 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3223 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3224
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3225 /* If Memory address size is 8Bit */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3226 if(MemAddSize == I2C_MEMADD_SIZE_8BIT)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3227 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3228 /* Send Memory Address */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3229 hi2c->Instance->DR = I2C_MEM_ADD_LSB(MemAddress);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3230 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3231 /* If Memory address size is 16Bit */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3232 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3233 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3234 /* Send MSB of Memory Address */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3235 hi2c->Instance->DR = I2C_MEM_ADD_MSB(MemAddress);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3236
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3237 /* Wait until TXE flag is set */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3238 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_TXE, RESET, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3239 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3240 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3241 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3242
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3243 /* Send LSB of Memory Address */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3244 hi2c->Instance->DR = I2C_MEM_ADD_LSB(MemAddress);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3245 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3246
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3247 /* Wait until TXE flag is set */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3248 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_TXE, RESET, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3249 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3250 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3251 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3252
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3253 /* Generate Restart */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3254 hi2c->Instance->CR1 |= I2C_CR1_START;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3255
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3256 /* Wait until SB flag is set */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3257 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_SB, RESET, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3258 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3259 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3260 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3261
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3262 /* Send slave address */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3263 hi2c->Instance->DR = I2C_7BIT_ADD_READ(DevAddress);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3264
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3265 /* Wait until ADDR flag is set */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3266 if(I2C_WaitOnMasterAddressFlagUntilTimeout(hi2c, I2C_FLAG_ADDR, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3267 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3268 if(hi2c->ErrorCode == HAL_I2C_ERROR_AF)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3269 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3270 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3271 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3272 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3273 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3274 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3275 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3276 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3277
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3278 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3279 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3280
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3281 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3282 * @brief DMA I2C master transmit process complete callback.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3283 * @param hdma: DMA handle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3284 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3285 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3286 static void I2C_DMAMasterTransmitCplt(DMA_HandleTypeDef *hdma)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3287 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3288 I2C_HandleTypeDef* hi2c = (I2C_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3289
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3290 /* Wait until BTF flag is reset */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3291 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_BTF, RESET, I2C_TIMEOUT_FLAG) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3292 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3293 hi2c->ErrorCode |= HAL_I2C_ERROR_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3294 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3295
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3296 /* Generate Stop */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3297 hi2c->Instance->CR1 |= I2C_CR1_STOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3298
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3299 /* Disable DMA Request */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3300 hi2c->Instance->CR2 &= ~I2C_CR2_DMAEN;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3301
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3302 hi2c->XferCount = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3303
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3304 /* Wait until BUSY flag is reset */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3305 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_BUSY, SET, I2C_TIMEOUT_FLAG) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3306 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3307 hi2c->ErrorCode |= HAL_I2C_ERROR_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3308 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3309
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3310 hi2c->State = HAL_I2C_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3311
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3312 /* Check if Errors has been detected during transfer */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3313 if(hi2c->ErrorCode != HAL_I2C_ERROR_NONE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3314 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3315 HAL_I2C_ErrorCallback(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3316 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3317 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3318 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3319 HAL_I2C_MasterTxCpltCallback(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3320 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3321 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3322
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3323 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3324 * @brief DMA I2C slave transmit process complete callback.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3325 * @param hdma: DMA handle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3326 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3327 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3328 static void I2C_DMASlaveTransmitCplt(DMA_HandleTypeDef *hdma)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3329 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3330 I2C_HandleTypeDef* hi2c = (I2C_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3331
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3332 /* Wait until AF flag is reset */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3333 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_AF, RESET, I2C_TIMEOUT_FLAG) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3334 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3335 hi2c->ErrorCode |= HAL_I2C_ERROR_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3336 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3337
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3338 /* Clear AF flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3339 __HAL_I2C_CLEAR_FLAG(hi2c, I2C_FLAG_AF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3340
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3341 /* Disable Address Acknowledge */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3342 hi2c->Instance->CR1 &= ~I2C_CR1_ACK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3343
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3344 /* Disable DMA Request */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3345 hi2c->Instance->CR2 &= ~I2C_CR2_DMAEN;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3346
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3347 hi2c->XferCount = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3348
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3349 /* Wait until BUSY flag is reset */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3350 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_BUSY, SET, I2C_TIMEOUT_FLAG) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3351 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3352 hi2c->ErrorCode |= HAL_I2C_ERROR_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3353 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3354
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3355 hi2c->State = HAL_I2C_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3356
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3357 /* Check if Errors has been detected during transfer */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3358 if(hi2c->ErrorCode != HAL_I2C_ERROR_NONE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3359 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3360 HAL_I2C_ErrorCallback(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3361 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3362 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3363 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3364 HAL_I2C_SlaveTxCpltCallback(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3365 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3366 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3367
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3368 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3369 * @brief DMA I2C master receive process complete callback
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3370 * @param hdma: DMA handle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3371 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3372 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3373 static void I2C_DMAMasterReceiveCplt(DMA_HandleTypeDef *hdma)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3374 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3375 I2C_HandleTypeDef* hi2c = (I2C_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3376
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3377 /* Generate Stop */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3378 hi2c->Instance->CR1 |= I2C_CR1_STOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3379
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3380 /* Disable Last DMA */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3381 hi2c->Instance->CR2 &= ~I2C_CR2_LAST;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3382
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3383 /* Disable Acknowledge */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3384 hi2c->Instance->CR1 &= ~I2C_CR1_ACK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3385
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3386 /* Disable DMA Request */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3387 hi2c->Instance->CR2 &= ~I2C_CR2_DMAEN;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3388
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3389 hi2c->XferCount = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3390
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3391 /* Wait until BUSY flag is reset */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3392 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_BUSY, SET, I2C_TIMEOUT_FLAG) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3393 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3394 hi2c->ErrorCode |= HAL_I2C_ERROR_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3395 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3396
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3397 hi2c->State = HAL_I2C_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3398
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3399 /* Check if Errors has been detected during transfer */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3400 if(hi2c->ErrorCode != HAL_I2C_ERROR_NONE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3401 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3402 HAL_I2C_ErrorCallback(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3403 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3404 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3405 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3406 HAL_I2C_MasterRxCpltCallback(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3407 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3408 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3409
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3410 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3411 * @brief DMA I2C slave receive process complete callback.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3412 * @param hdma: DMA handle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3413 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3414 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3415 static void I2C_DMASlaveReceiveCplt(DMA_HandleTypeDef *hdma)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3416 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3417 I2C_HandleTypeDef* hi2c = (I2C_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3418
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3419 /* Wait until STOPF flag is reset */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3420 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_STOPF, RESET, I2C_TIMEOUT_FLAG) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3421 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3422 hi2c->ErrorCode |= HAL_I2C_ERROR_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3423 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3424
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3425 /* Clear STOPF flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3426 __HAL_I2C_CLEAR_STOPFLAG(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3427
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3428 /* Disable Address Acknowledge */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3429 hi2c->Instance->CR1 &= ~I2C_CR1_ACK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3430
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3431 /* Disable DMA Request */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3432 hi2c->Instance->CR2 &= ~I2C_CR2_DMAEN;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3433
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3434 hi2c->XferCount = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3435
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3436 /* Wait until BUSY flag is reset */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3437 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_BUSY, SET, I2C_TIMEOUT_FLAG) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3438 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3439 hi2c->ErrorCode |= HAL_I2C_ERROR_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3440 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3441
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3442 hi2c->State = HAL_I2C_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3443
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3444 /* Check if Errors has been detected during transfer */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3445 if(hi2c->ErrorCode != HAL_I2C_ERROR_NONE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3446 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3447 HAL_I2C_ErrorCallback(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3448 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3449 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3450 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3451 HAL_I2C_SlaveRxCpltCallback(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3452 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3453 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3454
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3455 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3456 * @brief DMA I2C Memory Write process complete callback
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3457 * @param hdma: DMA handle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3458 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3459 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3460 static void I2C_DMAMemTransmitCplt(DMA_HandleTypeDef *hdma)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3461 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3462 I2C_HandleTypeDef* hi2c = (I2C_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3463
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3464 /* Wait until BTF flag is reset */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3465 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_BTF, RESET, I2C_TIMEOUT_FLAG) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3466 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3467 hi2c->ErrorCode |= HAL_I2C_ERROR_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3468 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3469
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3470 /* Generate Stop */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3471 hi2c->Instance->CR1 |= I2C_CR1_STOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3472
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3473 /* Disable DMA Request */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3474 hi2c->Instance->CR2 &= ~I2C_CR2_DMAEN;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3475
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3476 hi2c->XferCount = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3477
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3478 /* Wait until BUSY flag is reset */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3479 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_BUSY, SET, I2C_TIMEOUT_FLAG) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3480 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3481 hi2c->ErrorCode |= HAL_I2C_ERROR_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3482 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3483
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3484 hi2c->State = HAL_I2C_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3485
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3486 /* Check if Errors has been detected during transfer */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3487 if(hi2c->ErrorCode != HAL_I2C_ERROR_NONE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3488 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3489 HAL_I2C_ErrorCallback(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3490 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3491 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3492 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3493 HAL_I2C_MemTxCpltCallback(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3494 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3495 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3496
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3497 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3498 * @brief DMA I2C Memory Read process complete callback
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3499 * @param hdma: DMA handle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3500 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3501 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3502 static void I2C_DMAMemReceiveCplt(DMA_HandleTypeDef *hdma)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3503 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3504 I2C_HandleTypeDef* hi2c = (I2C_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3505
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3506 /* Generate Stop */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3507 hi2c->Instance->CR1 |= I2C_CR1_STOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3508
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3509 /* Disable Last DMA */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3510 hi2c->Instance->CR2 &= ~I2C_CR2_LAST;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3511
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3512 /* Disable Acknowledge */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3513 hi2c->Instance->CR1 &= ~I2C_CR1_ACK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3514
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3515 /* Disable DMA Request */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3516 hi2c->Instance->CR2 &= ~I2C_CR2_DMAEN;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3517
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3518 hi2c->XferCount = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3519
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3520 /* Wait until BUSY flag is reset */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3521 if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_BUSY, SET, I2C_TIMEOUT_FLAG) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3522 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3523 hi2c->ErrorCode |= HAL_I2C_ERROR_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3524 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3525
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3526 hi2c->State = HAL_I2C_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3527
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3528 /* Check if Errors has been detected during transfer */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3529 if(hi2c->ErrorCode != HAL_I2C_ERROR_NONE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3530 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3531 HAL_I2C_ErrorCallback(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3532 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3533 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3534 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3535 HAL_I2C_MemRxCpltCallback(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3536 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3537 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3538
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3539 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3540 * @brief DMA I2C communication error callback.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3541 * @param hdma: DMA handle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3542 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3543 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3544 static void I2C_DMAError(DMA_HandleTypeDef *hdma)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3545 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3546 I2C_HandleTypeDef* hi2c = (I2C_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3547
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3548 /* Disable Acknowledge */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3549 hi2c->Instance->CR1 &= ~I2C_CR1_ACK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3550
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3551 hi2c->XferCount = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3552
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3553 hi2c->State = HAL_I2C_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3554
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3555 hi2c->ErrorCode |= HAL_I2C_ERROR_DMA;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3556
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3557 HAL_I2C_ErrorCallback(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3558 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3559
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3560 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3561 * @brief This function handles I2C Communication Timeout.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3562 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3563 * the configuration information for I2C module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3564 * @param Flag: specifies the I2C flag to check.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3565 * @param Status: The new Flag status (SET or RESET).
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3566 * @param Timeout: Timeout duration
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3567 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3568 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3569 static HAL_StatusTypeDef I2C_WaitOnFlagUntilTimeout(I2C_HandleTypeDef *hi2c, uint32_t Flag, FlagStatus Status, uint32_t Timeout)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3570 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3571 uint32_t tickstart = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3572
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3573 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3574 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3575
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3576 /* Wait until flag is set */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3577 if(Status == RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3578 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3579 while(__HAL_I2C_GET_FLAG(hi2c, Flag) == RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3580 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3581 /* Check for the Timeout */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3582 if(Timeout != HAL_MAX_DELAY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3583 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3584 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3585 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3586 hi2c->State= HAL_I2C_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3587
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3588 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3589 __HAL_UNLOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3590
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3591 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3592 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3593 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3594 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3595 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3596 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3597 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3598 while(__HAL_I2C_GET_FLAG(hi2c, Flag) != RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3599 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3600 /* Check for the Timeout */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3601 if(Timeout != HAL_MAX_DELAY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3602 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3603 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3604 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3605 hi2c->State= HAL_I2C_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3606
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3607 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3608 __HAL_UNLOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3609
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3610 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3611 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3612 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3613 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3614 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3615 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3616 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3617
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3618 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3619 * @brief This function handles I2C Communication Timeout for Master addressing phase.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3620 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3621 * the configuration information for I2C module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3622 * @param Flag: specifies the I2C flag to check.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3623 * @param Timeout: Timeout duration
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3624 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3625 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3626 static HAL_StatusTypeDef I2C_WaitOnMasterAddressFlagUntilTimeout(I2C_HandleTypeDef *hi2c, uint32_t Flag, uint32_t Timeout)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3627 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3628 uint32_t tickstart = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3629
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3630 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3631 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3632
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3633 while(__HAL_I2C_GET_FLAG(hi2c, Flag) == RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3634 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3635 if(__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_AF) == SET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3636 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3637 /* Generate Stop */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3638 hi2c->Instance->CR1 |= I2C_CR1_STOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3639
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3640 /* Clear AF Flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3641 __HAL_I2C_CLEAR_FLAG(hi2c, I2C_FLAG_AF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3642
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3643 hi2c->ErrorCode = HAL_I2C_ERROR_AF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3644 hi2c->State= HAL_I2C_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3645
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3646 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3647 __HAL_UNLOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3648
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3649 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3650 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3651
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3652 /* Check for the Timeout */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3653 if(Timeout != HAL_MAX_DELAY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3654 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3655 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3656 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3657 hi2c->State= HAL_I2C_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3658
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3659 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3660 __HAL_UNLOCK(hi2c);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3661
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3662 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3663 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3664 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3665 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3666 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3667 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3668
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3669 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3670 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3671 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3672
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3673 #endif /* HAL_I2C_MODULE_ENABLED */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3674
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3675 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3676 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3677 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3678
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3679 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3680 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3681 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3682
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3683 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/