/**
@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 |
|_STM32F407xx_____________| |_____________STM32F407xx_|
This example shows how to configure GPIO, DMA and I2C peripherals using
2 STM32F4-Discovery RevB and RevC 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 168 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.
STM32F4-Discovery RevB & RevC 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.
- LED6 is turned ON when the reception process is completed.
- LED3 i
工程师老罗
- 粉丝: 4366
- 资源: 10
最新资源
- VMware虚拟机安装、备份与恢复全攻略
- 昆仑通态MCGS与3台英威腾GD变频器通讯 器件:昆仑通态触摸屏,3台英威腾GD系列变频器,附送接线说明和设置说明 功能:实现频率设定,启停控制,实际频率读取等,状态指示
- 机会约束最优潮流:不确定性下的风险感知网络控制 python源代码,代码按照高水平文章复现,保证正确 当不可控制的资源波动时,电力行业通常使用最优潮流(OPF)在输电网络的控制区域重新调度每小时可控的
- 最优控制电池储能模型 蓄电池储能模型的最优控制python源代码,代码按照高水平文章复现 包含五个python脚本,它从data .csv读取价格、负载和温度数据 然后用本文中描述的决策变量、目标和
- 项目管理表格,用来管理项目进度以及把控项目过程
- 一种分布式鲁棒优化的微电网单元分配方法 python源代码,代码按照高水平文章复现,保证正确 针对电网负荷和电力市场价格不确定的情况,提出了一种分布式鲁棒单元承诺方法 提出的关键推力的方法是利用Ku
- 不同操作系统下Node.js安装与环境配置教程:涵盖Windows、macOS和Linux系统
- VMware虚拟机安装与备份恢复全解析:覆盖下载、安装、配置到高级数据保护策略
- 变压器励磁模型 Matlab simulink 质量过硬 可用于模拟电压暂降等电能质量问题,适配于本家的IEEE 33节点模型
- 微信小程序开发全流程解析:从账号注册到API调用与发布
- 利用插电式电动汽车提高电网暂态稳定性 python联合PSS E源代码,代码按照高水平文章复现,保证正确 插电式电动汽车(pev)在放电模式下可以作为分布式能源和电力资源,作为车到网(V2G)设备运行
- 基于自适应在线学习的概率负荷预测python联合matlab源代码 负荷预测对于多种能源管理任务是至关重要的,例如调度发电能力,规划供应和需求,最小化能源交易成本 近年来,由于可再生能源、电动汽车和
- 示例:在 Python 中定义链表
- 平台采用小米1代扫地机 目前只有32端代码能实现延边避障防跌 落充电等功能 适合需要学习项目与代码规范的工程师 硬件驱动包含 陀螺仪姿态传感器bmi160、电源管理bq24733等 软件驱
- 电网经济和频率控制的多层,多时间尺度模型方法 Julia源代码,代码按照高水平文章复现,保证正确,可先发您文章看是否满足您的要求 由于分散的可再生能源和存储的不断增加,电力系统受到根本性变化的影响
- java将八进制转换为十进制的自定义方法
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈