I2C

所属分类:单片机开发
开发工具:WINDOWS
文件大小:14362KB
下载次数:6
上传日期:2017-08-25 11:45:29
上 传 者啦哈拉卅
说明:  基于STM32L452RET6的I2C例程函数
(I2C routine function based on STM32L452RET6)

文件列表:
I2C (0, 2017-07-03)
I2C\I2C_TwoBoards_AdvComIT (0, 2017-07-03)
I2C\I2C_TwoBoards_AdvComIT\EWARM (0, 2017-07-03)
I2C\I2C_TwoBoards_AdvComIT\EWARM\Project.ewd (43407, 2017-04-21)
I2C\I2C_TwoBoards_AdvComIT\EWARM\Project.ewp (29518, 2017-04-21)
I2C\I2C_TwoBoards_AdvComIT\EWARM\Project.eww (161, 2017-04-21)
I2C\I2C_TwoBoards_AdvComIT\EWARM\startup_stm32l452xx.s (21181, 2017-04-21)
I2C\I2C_TwoBoards_AdvComIT\EWARM\stm32l452xx_flash.icf (1646, 2017-04-21)
I2C\I2C_TwoBoards_AdvComIT\Inc (0, 2017-07-03)
I2C\I2C_TwoBoards_AdvComIT\Inc\main.h (4286, 2017-04-21)
I2C\I2C_TwoBoards_AdvComIT\Inc\stm32l4xx_hal_conf.h (13411, 2017-04-21)
I2C\I2C_TwoBoards_AdvComIT\Inc\stm32l4xx_it.h (3207, 2017-04-21)
I2C\I2C_TwoBoards_AdvComIT\MDK-ARM (0, 2017-08-08)
I2C\I2C_TwoBoards_AdvComIT\MDK-ARM\Project.uvguix.min (86507, 2017-08-08)
I2C\I2C_TwoBoards_AdvComIT\MDK-ARM\Project.uvoptx (15420, 2017-08-08)
I2C\I2C_TwoBoards_AdvComIT\MDK-ARM\Project.uvprojx (19067, 2017-08-08)
I2C\I2C_TwoBoards_AdvComIT\MDK-ARM\RTE (0, 2017-08-08)
I2C\I2C_TwoBoards_AdvComIT\MDK-ARM\RTE\RTE_Components.h (357, 2017-08-08)
I2C\I2C_TwoBoards_AdvComIT\MDK-ARM\STM32L452RE_NUCLEO (0, 2017-08-08)
I2C\I2C_TwoBoards_AdvComIT\MDK-ARM\STM32L452RE_NUCLEO\Project_STM32L452RE_NUCLEO.dep (58744, 2017-08-08)
I2C\I2C_TwoBoards_AdvComIT\MDK-ARM\STM32L452RE_NUCLEO\STM32L452RE_NUCLEO.axf (811188, 2017-08-08)
I2C\I2C_TwoBoards_AdvComIT\MDK-ARM\STM32L452RE_NUCLEO\STM32L452RE_NUCLEO.build_log.htm (2649, 2017-08-08)
I2C\I2C_TwoBoards_AdvComIT\MDK-ARM\STM32L452RE_NUCLEO\STM32L452RE_NUCLEO.htm (61184, 2017-08-08)
I2C\I2C_TwoBoards_AdvComIT\MDK-ARM\STM32L452RE_NUCLEO\STM32L452RE_NUCLEO.lnp (1100, 2017-08-08)
I2C\I2C_TwoBoards_AdvComIT\MDK-ARM\STM32L452RE_NUCLEO\STM32L452RE_NUCLEO.map (125917, 2017-08-08)
I2C\I2C_TwoBoards_AdvComIT\MDK-ARM\STM32L452RE_NUCLEO\STM32L452RE_NUCLEO.sct (479, 2017-08-08)
I2C\I2C_TwoBoards_AdvComIT\MDK-ARM\STM32L452RE_NUCLEO\main.crf (814616, 2017-08-08)
I2C\I2C_TwoBoards_AdvComIT\MDK-ARM\STM32L452RE_NUCLEO\main.d (3092, 2017-08-08)
I2C\I2C_TwoBoards_AdvComIT\MDK-ARM\STM32L452RE_NUCLEO\main.o (923348, 2017-08-08)
I2C\I2C_TwoBoards_AdvComIT\MDK-ARM\STM32L452RE_NUCLEO\startup_stm32l452xx.d (65, 2017-08-08)
I2C\I2C_TwoBoards_AdvComIT\MDK-ARM\STM32L452RE_NUCLEO\startup_stm32l452xx.o (7336, 2017-08-08)
I2C\I2C_TwoBoards_AdvComIT\MDK-ARM\STM32L452RE_NUCLEO\stm32l4xx_hal.crf (811097, 2017-08-08)
I2C\I2C_TwoBoards_AdvComIT\MDK-ARM\STM32L452RE_NUCLEO\stm32l4xx_hal.d (3288, 2017-08-08)
I2C\I2C_TwoBoards_AdvComIT\MDK-ARM\STM32L452RE_NUCLEO\stm32l4xx_hal.o (959712, 2017-08-08)
I2C\I2C_TwoBoards_AdvComIT\MDK-ARM\STM32L452RE_NUCLEO\stm32l4xx_hal_cortex.crf (809470, 2017-08-08)
I2C\I2C_TwoBoards_AdvComIT\MDK-ARM\STM32L452RE_NUCLEO\stm32l4xx_hal_cortex.d (3512, 2017-08-08)
I2C\I2C_TwoBoards_AdvComIT\MDK-ARM\STM32L452RE_NUCLEO\stm32l4xx_hal_cortex.o (938824, 2017-08-08)
I2C\I2C_TwoBoards_AdvComIT\MDK-ARM\STM32L452RE_NUCLEO\stm32l4xx_hal_dma.crf (814705, 2017-08-08)
I2C\I2C_TwoBoards_AdvComIT\MDK-ARM\STM32L452RE_NUCLEO\stm32l4xx_hal_dma.d (3416, 2017-08-08)
I2C\I2C_TwoBoards_AdvComIT\MDK-ARM\STM32L452RE_NUCLEO\stm32l4xx_hal_dma.o (933520, 2017-08-08)
... ...

/** @page I2C_TwoBoards_ComIT I2C Two Boards Communication IT Example @verbatim ******************** (C) COPYRIGHT 2016 STMicroelectronics ******************* * @file I2C/I2C_TwoBoards_ComIT/readme.txt * @author MCD Application Team * @version V1.8.0 * @date 21-April-2017 * @brief Description of the I2C Two Boards Communication IT example. ****************************************************************************** * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. Neither the name of STMicroelectronics nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ****************************************************************************** @endverbatim @par Example Description This example describes how to perform I2C data buffer transmission/reception between two boards using an interrupt. Board: STM32L452RE-Nucleo Rev C (embeds a STM32L452RET6 device) SCL Pin: PC0 (CN7, pin38) SDA Pin: PC1 (CN7, pin36) _________________________ _________________________ | ______________| |______________ | | |I2C3 | | I2C3| | | | | | | | | | SCL |_____________________| SCL | | | | | | | | | | | | | | | | | | | | | | SDA |_____________________| SDA | | | | | | | | | |______________| |______________| | | | | | | GND|_____________________|GND | |_STM32_Board 1___________| |_STM32_Board 2___________| At the beginning of the main program the HAL_Init() function is called to reset all the peripherals, initialize the Flash interface and the systick. Then the SystemClock_Config() function is used to configure the system clock (SYSCLK) to run at 80 MHz. The I2C peripheral configuration is ensured by the HAL_I2C_Init() function. This later is calling the HAL_I2C_MspInit()function which core is implementing the configuration of the needed I2C resources according to the used hardware (CLOCK, GPIO and NVIC). You may update this function to change I2C configuration. The I2C communication is then initiated. The project is split in two parts: the Master Board and the Slave Board - Master Board The HAL_I2C_Master_Receive_IT() and the HAL_I2C_Master_Transmit_IT() functions allow respectively the reception and the transmission of a predefined data buffer in Master mode using interrupt. - Slave Board The HAL_I2C_Slave_Receive_IT() and the HAL_I2C_Slave_Transmit_IT() functions allow respectively the reception and the transmission of a predefined data buffer in Slave mode using interrupt. The user can choose between Master and Slave through "#define MASTER_BOARD" in the "main.c" file: - Uncomment "#define MASTER_BOARD" to select Master board. - Comment "#define MASTER_BOARD" to select Slave board. For this example the aTxBuffer is predefined and the aRxBuffer size is same as aTxBuffer. In a first step after the user press the User push-button on the Master Board, I2C Master starts the communication by sending aTxBuffer through HAL_I2C_Master_Transmit_IT() to I2C Slave which receives aRxBuffer through HAL_I2C_Slave_Receive_IT(). The second step starts when the user press the User push-button on the Master Board, the I2C Slave sends aTxBuffer through HAL_I2C_Slave_Transmit_IT() to the I2C Master which receives aRxBuffer through HAL_I2C_Master_Receive_IT(). The end of this two steps are monitored through the HAL_I2C_GetState() function result. Finally, aTxBuffer and aRxBuffer are compared through Buffercmp() in order to check buffers correctness. STM32L452RE-Nucleo Rev C's LED can be used to monitor the transfer status: - LED2 is ON when the transmission process is complete. - LED2 is OFF when the reception process is complete. - LED2 is slowly blinking (1 sec. period) in case of error in initialization or transmission/reception process @note I2Cx instance used and associated resources can be updated in "main.h" file depending hardware configuration used. @note Care must be taken when using HAL_Delay(), this function provides accurate delay (in milliseconds) based on variable incremented in SysTick ISR. This implies that if HAL_Delay() is called from a peripheral ISR process, then the SysTick interrupt must have higher priority (numerically lower) than the peripheral interrupt. Otherwise the caller ISR process will be blocked. To change the SysTick interrupt priority you have to use HAL_NVIC_SetPriority() function. @note The application need to ensure that the SysTick time base is always set to 1 millisecond to have correct HAL operation. @par Directory contents - I2C/I2C_TwoBoards_ComIT/Inc/stm32l4xx_hal_conf.h HAL configuration file - I2C/I2C_TwoBoards_ComIT/Inc/stm32l4xx_it.h I2C interrupt handlers header file - I2C/I2C_TwoBoards_ComIT/Inc/main.h Header for main.c module - I2C/I2C_TwoBoards_ComIT/Src/stm32l4xx_it.c I2C interrupt handlers - I2C/I2C_TwoBoards_ComIT/Src/main.c Main program - I2C/I2C_TwoBoards_ComIT/Src/system_stm32l4xx.c STM32L4xx system source file - I2C/I2C_TwoBoards_ComIT/Src/stm32l4xx_hal_msp.c HAL MSP file @par Hardware and Software environment - This example runs on STM32L452xx devices. - This example has been tested with STM32L452RE-Nucleo Rev C board and can be easily tailored to any other supported device and development board. - STM32L452RE-Nucleo Rev C Set-up - Connect I2C_SCL line of Master board (PC0, CN7, pin38) to I2C_SCL line of Slave Board (PC0, CN7, pin38). - Connect I2C_SDA line of Master board (PC1, CN7, pin36) to I2C_SDA line of Slave Board (PC1, CN7, pin36). - Connect GND of Master board to GND of Slave Board. @par How to use it ? In order to make the program work, you must do the following : - Open your preferred toolchain - Rebuild all files and load your image into target memory o Uncomment "#define MASTER_BOARD" and load the project in Master Board o Comment "#define MASTER_BOARD" and load the project in Slave Board - Run the example *

© COPYRIGHT STMicroelectronics

*/

近期下载者

相关文件


收藏者