/**
@page I2C_TwoBoards_RestartAdvComIT I2C example
@verbatim
******************** (C) COPYRIGHT 2017 STMicroelectronics *******************
* @file I2C/I2C_TwoBoards_RestartAdvComIT/readme.txt
* @author MCD Application Team
* @brief Description of the I2C_TwoBoards_RestartAdvComIT I2C 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
How to perform multiple I2C data buffer transmission/reception between two boards,
in interrupt mode and with restart condition.
_________________________ _________________________
| ______________| |______________ |
| | I2C1 | | I2C1| |
| | | | | |
| | SCL(PB6)|______________________|(PB6)SCL | |
| | | | | |
| | | | | |
| | | | | |
| | SDA(PB9)|______________________|(PB9)SDA | |
| | | | | |
| |______________| |______________| |
| __ | | __ |
| |__| | | |__| |
| BUTTON_KEY | | BUTTON_KEY |
| GND|______________________|GND |
|_STM32F429xx_____________| |_____________STM32F429xx_|
This example shows how to configure GPIO, DMA and I2C peripherals using
2 STM32F429I-Discovery boards for exchanging some datas
between an I2C Master device using Interrupt mode
and an I2C Slave device using Interrupt mode through the STM32F4xx I2C HAL API.
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 180 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 User push-button is used to initiate a communication between Master device to Slave.
User can initiate a new communication after each previous transfer completed.
The I2C communication is then initiated.
The project is splitted in two parts the Master Board and the Slave Board
- Master Board
The HAL_I2C_Master_Sequential_Transmit_IT() and the HAL_I2C_Master_Sequential_Receive_IT() functions
allow respectively the transmission and the reception of a predefined data buffer
in Master mode.
- Slave Board
The HAL_I2C_EnableListen_IT(), HAL_I2C_Slave_Sequential_Receive_IT() and the HAL_I2C_Slave_Sequential_Transmit_IT() functions
allow respectively the "Listen" the I2C bus for address match code event, reception and the transmission of a predefined data buffer
in Slave mode.
The user can choose between Master and Slave through "#define MASTER_BOARD"
in the "main.c" file.
If the Master board is used, the "#define MASTER_BOARD" must be uncommented.
If the Slave board is used the "#define MASTER_BOARD" must be commented.
Example execution:
On Master board side:
- Wait User push-button to be pressed.
This action initiate a write request by Master through HAL_I2C_Master_Sequential_Transmit_IT() or a write then read request
through HAL_I2C_Master_Sequential_Transmit_IT() then HAL_I2C_Master_Sequential_Receive_IT() routine depends on Command Code type.
Initialy at power on Slave device through Interrupt "Listen" the I2C bus to perform an acknowledge of Match Address when necessary.
This "Listen" action is initiated by calling HAL_I2C_EnableListen_IT().
Command code type is decomposed in two categories :
1- Action Command code
a. Type of command which need an internal action from Slave Device without sending any specific answer to Master.
b. I2C sequence is composed like that :
_____________________________________________________________________________________
|_START_|_Slave_Address_|_Wr_|_A_|_Command_Code_BYTE_1_|_A_|_Command_Code_BYTE_2_|_A_|....
________________________________
|_Command_Code_BYTE_M_|_A_|_STOP_|
First of all, through HAL_I2C_Master_Sequential_Transmit_IT() routine, Master device generate an I2C start condition
with the Slave address and a write bit condition.
In Slave side, when address Slave match code is received on I2C1, an event interrupt (ADDR) occurs.
I2C1 IRQ Handler routine is then calling HAL_I2C_AddrCallback() which check Address Match Code and direction Write (Transmit)
to call the correct HAL_I2C_Slave_Sequential_Receive_IT() function.
This will allow Slave to enter in receiver mode and then acknowledge Master to send the Command code bytes through Interrupt.
The Command code data is received and treated byte per byte through HAL_I2C_SlaveRxCpltCallback() in Slave side until a STOP condition.
And so in Master side, each time the Slave acknowledge the byte received,
Master transfer the next data from flash memory buffer to I2C1 TXDR register until "Action Command code" Transfer completed.
Master auto-generate a Stop condition when transfer is achieved.
The STOP condition generate a STOP interrupt and initiate the end of reception on Slave side.
Thanks to HAL_I2C_ListenCpltCallback(), Slave is informed of the end of Communication with Master
and "Listen" mode is also terminated.
STM32F429I-Discovery board's LEDs can be used to monitor the transfer status :
Slave board side only :
- LED3 is turned ON when an Address match code event is acknowledge.
- LED3 is turned ON when the reception process is completed.
- LED3 is then turned OFF
没有合适的资源?快使用搜索试试~ 我知道了~
I2C.rar_#I2C #STM32_Master/Slave_carriedhja
共123个文件
c:26个
h:19个
s:18个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 39 浏览量
2022-09-21
22:15:49
上传
评论
收藏 312KB RAR 举报
温馨提示
(Inter-Integrated Circuit), pronounced I-squared-C, is a synchronous, multi-master, multi-slave, packet switched, single-ended, serial computer bus invented in 1982 by Philips Semiconductor (now NXP Semiconductors).
资源推荐
资源详情
资源评论
收起资源包目录
I2C.rar_#I2C #STM32_Master/Slave_carriedhja (123个子文件)
main.c 24KB
main.c 21KB
main.c 17KB
system_stm32f4xx.c 15KB
system_stm32f4xx.c 15KB
system_stm32f4xx.c 15KB
system_stm32f4xx.c 15KB
system_stm32f4xx.c 15KB
system_stm32f4xx.c 15KB
main.c 15KB
main.c 15KB
main.c 12KB
stm32f4xx_hal_msp.c 8KB
stm32f4xx_it.c 7KB
stm32f4xx_it.c 6KB
stm32f4xx_it.c 6KB
stm32f4xx_it.c 6KB
stm32f4xx_it.c 6KB
stm32f4xx_it.c 6KB
stm32f4xx_hal_msp.c 5KB
stm32f4xx_hal_msp.c 5KB
stm32f4xx_hal_msp.c 5KB
stm32f4xx_hal_msp.c 5KB
stm32f4xx_hal_msp.c 5KB
Serial.c 2KB
Retarget.c 1KB
.cproject 12KB
.cproject 12KB
.cproject 11KB
.cproject 11KB
.cproject 11KB
.cproject 11KB
Project.ewd 41KB
Project.ewd 41KB
Project.ewd 35KB
Project.ewd 35KB
Project.ewd 35KB
Project.ewd 35KB
Project.ewp 29KB
Project.ewp 29KB
Project.ewp 28KB
Project.ewp 28KB
Project.ewp 28KB
Project.ewp 28KB
Project.eww 161B
Project.eww 161B
Project.eww 161B
Project.eww 161B
Project.eww 144B
Project.eww 144B
stm32f4xx_hal_conf.h 13KB
stm32f4xx_hal_conf.h 13KB
stm32f4xx_hal_conf.h 12KB
stm32f4xx_hal_conf.h 12KB
stm32f4xx_hal_conf.h 12KB
stm32f4xx_hal_conf.h 12KB
main.h 5KB
main.h 4KB
main.h 4KB
main.h 4KB
main.h 4KB
main.h 4KB
stm32f4xx_it.h 3KB
stm32f4xx_it.h 3KB
stm32f4xx_it.h 3KB
stm32f4xx_it.h 3KB
stm32f4xx_it.h 3KB
stm32f4xx_it.h 3KB
Serial.h 926B
stm32f429xx_flash.icf 2KB
stm32f429xx_flash.icf 2KB
stm32f429xx_flash.icf 2KB
stm32f429xx_flash.icf 2KB
stm32f429xx_flash.icf 2KB
stm32f429xx_flash.icf 2KB
STM32F439BGTx_FLASH.ld 5KB
STM32F429ZITx_FLASH.ld 5KB
STM32F429ZITx_FLASH.ld 5KB
STM32F429ZITx_FLASH.ld 5KB
STM32F429ZITx_FLASH.ld 5KB
STM32F429ZITx_FLASH.ld 5KB
.project 5KB
.project 5KB
.project 5KB
.project 5KB
.project 4KB
.project 4KB
startup_stm32f429xx.s 31KB
startup_stm32f429xx.s 31KB
startup_stm32f429xx.s 31KB
startup_stm32f429xx.s 31KB
startup_stm32f429xx.s 31KB
startup_stm32f429xx.s 31KB
startup_stm32f429xx.s 27KB
startup_stm32f429xx.s 27KB
startup_stm32f429xx.s 27KB
startup_stm32f429xx.s 27KB
startup_stm32f429xx.s 27KB
startup_stm32f429xx.s 27KB
startup_stm32f429xx.s 26KB
共 123 条
- 1
- 2
资源评论
朱moyimi
- 粉丝: 61
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功