/**
@page I2C_OneBoard_ComSlave7_10bits_IT I2C One Board Communication Slave 10-Bit
then Slave 7-Bit IT example
@verbatim
******************** (C) COPYRIGHT 2017 STMicroelectronics *******************
* @file Examples_MIX/I2C/I2C_OneBoard_ComSlave7_10bits_IT/readme.txt
* @author MCD Application Team
* @brief Description of the I2C One Board Master Communication with
* a Slave 10-Bit address then a Slave 7-Bit address 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
one master and 2 slaves with different address sizes (7-bit or 10-bit) and
different Max speed support (400Khz or 100Khz). This example
uses the STM32F4xx I2C HAL and LL API (LL API usage for performance improvement)
and an interrupt.
Board: NUCLEO-F411RE (embeds a STM32F411xx device)
SCL MASTER Pin: PB.10 (CN10, pin 25)
SDA MASTER Pin: PB.3 (CN10, pin 31)
SCL SLAVE Pin: PB.6 (CN10, pin 17)
SDA SLAVE Pin: PB.7 (CN7, pin 21)
____________________________________________
| ____________ ____________ |
| | I2C2 | | I2C1 | |
| | | | | |
| | SCL_MASTER|________|SCL_SLAVE | |
| | | | | |
| | | | | |
| | SDA_MASTER|________|SDA_SLAVE | |
| |____________| |____________| |
| __ |
| |__| |
| USER |
| |
|___________NUCLEO-F411RE_________|
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 100 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.
For this example two buffers are used
- aTxBuffer buffer contains the data to be transmitted
- aRxBuffer buffer is used to save the received data
Note that both buffers have same size
Example execution:
First step, press the User push-button, this action initiates a reception process (aRxBuffer) for
I2C Slave1 or Slave2 address through HAL_I2C_Slave_Receive_IT().
Then I2C Master starts the communication by sending aTxBuffer through HAL_I2C_Master_Transmit_IT()
for Slave1 (10-Bit address) at max speed supported 400Khz.
The end of this step is monitored through the HAL_I2C_GetState() function
result.
Finally, aTxBuffer and aRxBuffer are compared through Buffercmp() in order to
check buffers correctness.
Toggle LED2 when data is received correctly, otherwise LED2 is slowly blinking (1 sec. period)
and communication is stopped (using infinite loop)
Second step, press the User push-button, this action initiates a transmission process (aTxBuffer) for
I2C Slave1 or Slave2 address through HAL_I2C_Slave_Transmit_IT().
Then I2C Master starts the communication by receiving aRxBuffer through HAL_I2C_Master_Transmit_IT()
from Slave2 (7-Bit address) at max speed supported 100Khz.
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.
Toggle LED2 when data is received correctly, otherwise LED2 is slowly blinking (1 sec. period)
and communication is stopped (using infinite loop)
@note In Master side, only Acknowledge failure error is handled. When this error
occurs Master restart the current operation until Slave acknowledges it's
address.
@note I2C2 and I2C1 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
- Examples_MIX/I2C/I2C_OneBoard_ComSlave7_10bits_IT/Inc/stm32f4xx_hal_conf.h HAL configuration file
- Examples_MIX/I2C/I2C_OneBoard_ComSlave7_10bits_IT/Inc/stm32f4xx_it.h I2C interrupt handlers header file
- Examples_MIX/I2C/I2C_OneBoard_ComSlave7_10bits_IT/Inc/main.h Header for main.c module
- Examples_MIX/I2C/I2C_OneBoard_ComSlave7_10bits_IT/Src/stm32f4xx_it.c I2C interrupt handlers
- Examples_MIX/I2C/I2C_OneBoard_ComSlave7_10bits_IT/Src/main.c Main program
- Examples_MIX/I2C/I2C_OneBoard_ComSlave7_10bits_IT/Src/system_stm32f4xx.c STM32F4xx system source file
- Examples_MIX/I2C/I2C_OneBoard_ComSlave7_10bits_IT/Src/stm32f4xx_hal_msp.c HAL MSP file
@par Hardware and Software environment
- This example runs on STM32F411RE devices.
- This example has been tested with NUCLEO-F411RE board and can be
easily tailored to any other supported device and development board.
-NUCLEO-F411RE Set-up
- Connect GPIOs connected to I2C1 SCL/SDA (PB.6 and PB.7)
to respectively SCL and SDA pins of I2C2 (PB.10 and PB.3).
- I2C1_SCL PB.6 (CN10, pin 17) : connected to I2C2_SCL PB.10 (CN10, pin 25)
- I2C1_SDA PB.7 (CN7, pin 21) : connected to I2C2_SDA PB.3 (CN10, pin 31)
- Launch the program.
- Press User push-but
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
关于STM32使用硬件i2c读写AT24C256实验遇到的问题,这个代码只是一部分,下载后需要将他放在官方HAL库en.stm32cubef4 V1.23.0-》Projects-》STM32F411RE-Nucleo-》Examples_MIX-》I2C目录下,参照帖子里关于这个工程的问题总结,对遇到的问题进行了分析解决,帖子名字“关于STM32使用硬件i2c读写AT24C256实验遇到的问题”
资源推荐
资源详情
资源评论
收起资源包目录
STM32F4硬件i2c通信(使用HAL库) (143个子文件)
STM32F411-Nucleo.axf 537KB
Project.STM32F411-Nucleo.cspy.bat 2KB
Project.pbd.browse 1.83MB
main.c 18KB
system_stm32f4xx.c 10KB
stm32f4xx_hal_msp.c 8KB
stm32f4xx_it.c 7KB
.cproject 20KB
main.crf 556KB
stm32f4xx_hal_msp.crf 555KB
stm32f4xx_it.crf 554KB
stm32f4xx_hal_i2c.crf 546KB
stm32f4xx_hal_uart.crf 515KB
stm32f4xx_hal_rcc.crf 508KB
stm32f4xx_hal_dma.crf 506KB
stm32f4xx_hal_rcc_ex.crf 503KB
stm32f4xx_nucleo.crf 502KB
stm32f4xx_hal_gpio.crf 501KB
stm32f4xx_hal_pwr.crf 500KB
stm32f4xx_hal.crf 500KB
stm32f4xx_hal_pwr_ex.crf 500KB
stm32f4xx_hal_cortex.crf 499KB
system_stm32f4xx.crf 498KB
Project.crun 384B
stm32f4xx_hal_msp.d 4KB
stm32f4xx_it.d 4KB
stm32f4xx_hal_cortex.d 3KB
stm32f4xx_hal_pwr_ex.d 3KB
stm32f4xx_hal_rcc_ex.d 3KB
main.d 3KB
stm32f4xx_nucleo.d 3KB
stm32f4xx_hal_gpio.d 3KB
stm32f4xx_hal_uart.d 3KB
stm32f4xx_hal_pwr.d 3KB
stm32f4xx_hal_i2c.d 3KB
stm32f4xx_hal_rcc.d 3KB
stm32f4xx_hal_dma.d 3KB
system_stm32f4xx.d 3KB
stm32f4xx_hal.d 3KB
startup_stm32f411xe.d 63B
STM32F411-Nucleo_STM32F411RETx.dbgconf 2KB
Project.dbgdt 62KB
Project_STM32F411-Nucleo.dep 50KB
Project.dep 24KB
Project.dnx 4KB
Project.ewd 52KB
Project.ewp 40KB
Project.ewt 88KB
Project.eww 161B
stm32f4xx_hal_conf.h 12KB
main.h 5KB
stm32f4xx_it.h 3KB
RTE_Components.h 263B
STM32F411-Nucleo.hex 28KB
STM32F411-Nucleo.htm 63KB
STM32F411-Nucleo.build_log.htm 2KB
stm32f411xe_flash.icf 1KB
ExtDll.iex 19B
STM32F411RETx_FLASH.ld 4KB
Project.pbd.linf 3KB
STM32F411-Nucleo.lnp 933B
startup_stm32f411xe.lst 61KB
STM32F411-Nucleo.map 112KB
Project.map 25KB
stm32f4xx_hal_i2c.o 722KB
stm32f4xx_hal_uart.o 668KB
stm32f4xx_it.o 645KB
main.o 638KB
stm32f4xx_hal_msp.o 630KB
stm32f4xx_hal.o 613KB
stm32f4xx_hal_cortex.o 608KB
stm32f4xx_hal_dma.o 603KB
stm32f4xx_hal_rcc.o 600KB
stm32f4xx_hal_pwr.o 600KB
stm32f4xx_nucleo.o 593KB
stm32f4xx_hal_pwr_ex.o 590KB
stm32f4xx_hal_gpio.o 588KB
stm32f4xx_hal_rcc_ex.o 587KB
system_stm32f4xx.o 577KB
stm32f4xx_hal_i2c.o 316KB
stm32f4xx_hal_uart.o 136KB
startup_stm32f411xe.o 58KB
stm32f4xx_hal_cortex.o 49KB
stm32f4xx_hal.o 48KB
stm32f4xx_hal_dma.o 40KB
stm32f4xx_hal_rcc.o 38KB
stm32f4xx_hal_pwr.o 36KB
stm32f4xx_nucleo.o 30KB
stm32f4xx_it.o 27KB
stm32f4xx_hal_pwr_ex.o 26KB
main.o 25KB
stm32f4xx_hal_rcc_ex.o 23KB
stm32f4xx_hal_gpio.o 22KB
stm32f4xx_hal_msp.o 20KB
system_stm32f4xx.o 12KB
startup_stm32f411xe.o 7KB
Project.out 260KB
Project.pbd 1.83MB
stm32f4xx_hal_i2c.pbi 1.49MB
main.pbi 1.48MB
共 143 条
- 1
- 2
资源评论
John.Ma
- 粉丝: 36
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功