I2C模块使用教程

前言 (4)第1章 I2C模块规格说明 (5)1.1 综述 (5)1.2 特性 (5)1.3 模块架构 (7)1.4 配套资料说明 (7)1.5 模块原理图 (8)第2章 Arduino 基础 (9)2.1 Arduino硬件 (9)2.2 Arduino软件 (10)2.3 示例程序:LED控制 (12)第3章实时时钟 (17)3.1 DS1307介绍 (17)3.2 接线图 (17)3.3 DS1307的使用 (18)第4章外部存储 (23)4.1 AT24C32介绍 (23)4.2 接线图 (23)4.3 AT24C32的使用 (23)第5章温度侦测 (28)5.1 LM75介绍 (28)5.2 接线图 (28)5.3 LM75的使用 (29)结语 (33)为什么叫I2C模块?和一元硬币差不多大小的一块PCB上放了三个芯片,分管三个功能:时间计算、温度侦测、数据存储。

这三个芯片都是通过I2C总线通信的。

我们知道,I2C理论上可以级联2的7次方即128个设备,该模块级联了三个典型且通用I2C设备(这里为三个独立芯片),并且预留了级联更多I2C设备的接口,所以叫I2C模块。

为什么做这个I2C模块?在淘宝上搜索“I2C模块”,搜索结果中的I2C模块,一般是用一两个芯片实现对应的一两个功能,有的板上还集成非I2C相关的功能,不是纯粹的I2C模块,配套教程则比较杂乱。

于是我们决定做一个纯粹的、功能多一点的I2C模块,和Arduino配套,配上精心书写的“一份”教程。

我们强调教程的“一份”,是因为这份教程针对I2C的使用做了集中且系统的教学,不用再去搜索其他资料。

教程中使用到的Arduino库经过我们的开发,把相关功能都做好了封装,在代码中直接调用即可,无论是用来学习还是做产品开发,都简单和高效。

为了大家更好的学习,模块实行软硬件开源。

By MAKERTIPS2013年7月于广州大学城第1章 I2C模块规格说明1.1 综述I2C模块集成了三个芯片,分别实现三个功能:1、时间计算:DS13072、温度侦测:LM753、数据存储:AT24C32图1.1 I2C模块功能说明3D图1.2 特性1、使用实时时钟芯片DS1307计算时间2、使用温度传感器芯片LM75侦测温度3、使用EEPROM存储芯片AT24C32 存储数据4、通过精简的I2C总线实现以上功能5、使用CR2032锂电池为时钟芯片供电,可使用2年LM75DS1307AT24C326、设计小巧,PCB尺寸28mm*25mm7、引出LM75的OS脚,可作为温度中断输出8、通过排针J1或J2,可以级联其他I2C设备图1.2 小巧的I2C模块1.3 模块架构I2C(Inter-Integrated Circuit)总线是由PHILIPS公司开发的两线式串行总线,用于连接微控制器及其外围设备。

如图1.2所示,I2C模块上已经有Device A、Device B和Device C,只要外接一个MCU(这里我们用Arduino),就完成了连接。

图1.3 I2C模块架构1.4 配套资料说明存放代码文件、库文件存放三个芯片的数据手册教程文档1.5 模块原理图模块原理图如下图1.5所示,U1、U2、U3是芯片,J1、J2是排针。

图1.5 模块原理图第2章 Arduino 基础在开始I2C模块的教学之前,简单说明一下Arduino的硬件连接与软件环境,并学习第一个Arduino 程序。

2.1 Arduino硬件通过USB线,把Arduino 与电脑连接起来。

将Arduino和I2C模块连接起来。

2.2 Arduino软件我们使用官方推荐的Arduino IDE 进行开发,IDE是集成开发环境的意思。

注意不同版本的IDE 所带的编译工具链有差异,可能存在某一份代码或者库能在这个IDE编译,而在两外一个则不行的情况,所以大家在记录、存档和分享Arduino 工程项目时,注意注明代码或者库在哪个IDE下编译。

本教程所有代码在Arduino 1.0.3下编译通过。

各版本IDE官方获取渠道:/en/Main/Software图2.1 Arduino 集成开发环境在开始运行Arduino程序之前,先将I2C模块要用到的库文件放到Arduino IDE的“libraries”目录下2.3 示例程序:LED控制以下开始我们的第一个程序,打开教程文件“Tutorial_1_LED.ino”可以在IDE中看到代码如下://设定LED 管脚const int LED = 13;void setup (void){//初始化串口Serial.begin(9600);//设置LED管脚为输出pinMode(LED, OUTPUT);//输出低电平(LED熄灭)digitalWrite(LED, LOW);}void loop() {//判断是否有新串口数据if (Serial.available() > 0) {//读取数据char instruct = Serial.read();if (instruct == 'Y')//点亮LEDdigitalWrite(LED, HIGH);else//熄灭LEDdigitalWrite(LED, LOW);}}打开IDE后,先选定Arduino板子的版本,请根据实际使用的版本做选择接着选定使用的串口号,请根据实际情况选择,这里是COM3在IDE 里编译代码并上传到Arduino,打开串口查看器,输入大写的“Y”,板上的LED将会亮起,输入其他字符,LED将会熄灭。

下面,我们来看下代码。

const int LED = 13; //设定LED 管脚这表示声明并赋值一个变量,也就是LED,它被给予初始值13,为什么是13呢?因为这代表着Arduino的第13个管脚,这条语句执行后,下面代码里所有的LED 都代表这13这个值。

在这里,也可以这样写 "#define LED 13",结果是一样的,但是语句的含义不一样,大家有兴趣可以去了解一下。

下面就是几乎所有Arduino 代码都有的两个部分,setup 函数与 loop 函数:setup()这个函数是用来初始化的,它可以用来初始化变量、芯片管脚、库等,这个函数在每次Arduino启动时(接通电源或者复位)执行,并且只执行一次。

所以跟初始化有关的代码一般都放在这里。

loop()顾名思义,这个函数是用来循环的,在这个函数里面的代码将不断地被执行,也就说里面的代码从开始执行到结尾,再重新从开始执行,直至电源被关断或者重启。

通常,loop函数里面呈现着整个代码运作的流程。

我们来分析setup函数里面的代码。

Serial.begin(9600); //初始化串口这句代码的意思是启动串口通讯,Serial 是Arduino 的一个核心库,专门处理串口通讯。

begin() 是Serial实例的一个方法,如果你觉得这些面向对象的词语有些难理解,可以不必在意。

其中9600 这个数是通讯的波特率,其他数值有19200、38400、57600、115200等等,数字越高表示通讯的速度越快,在设定这些数值时,务必确认电脑上的串口也是同样的波特率,不然通讯不会成功。

pinMode(LED, OUTPUT); //设置LED管脚为输出这句代码的意思是把连接到LED的管脚设成输出模式。

Arduino 上芯片的管脚可以有多种不同的模式:输入、输出等其他功能。

一个管脚同时只能处在一个模式下,例如只能一会是输出,一会儿是输入,而不能同时作为输入输出口。

pinMode() 函数也是Arduino 其中一个核心函数,它接收两个参数,一个是所设定的管脚,这里是LED,即管脚13,另一个参数是模式,在这里是OUTPUT,即输出模式。

digitalWrite(LED, LOW); //输出低电平(LED熄灭)这句代码的意思是在连接LED的管脚上输出低电平。

digitalWrite() 是Arduino 用来输出数字电平(电压)的函数,它接收两个参数,一个是输出的管脚,这里是LED,即管脚13,另一个参数是输出的电平,这里是LOW,即低电平,这个参数只能使用两个值,HIGH、LOW分表代表高电平和低电平。

在这个Arduino 板上的LED连接方式决定了它得到低电平时灭,高电平时亮。

所以这句代码的效果是LED 被熄灭。

if (Serial.available() > 0) //判断是否有新串口数据这句代码的意思是判断串口是否有接收到新数据,即电脑是否有发送了新数据给Arduino。

available() 是Serial实例的另一个方法,如果有新数据,available() 将会返回一个大于0的值,没有数据则返回0。

char instruct = Serial.read(); //读取数据这句代码的意思是读取串口数据,当available() 返回值大于0的时候,我们才可以用read() 来读取数据,每次读取一个字节,如果有不止一个字节的数据,则要连续调用read(),直至available() 返回0。

好啦,剩下的代码大家应该比较好理解了,这章到此结束,从下一章开始对I2C 模块进行实例编程!第3章实时时钟实时时钟(Real Time Clock,简称RTC)是指可以像时钟一样输出实际时间的电子设备,一般会是集成电路,因此也称为时钟芯片。

简单来说,实时时钟就是可以给我们提供当前时间和日期的设备。

实现实时时钟的方案有很多,这里我们介绍用DS1307这块芯片来实现实时时钟的方案,同时介绍I2C协议和库的使用,以及有关时间的相关程序。

3.1 DS1307介绍DS1307 是一款十分常用的实时时钟芯片,它可以记录年、月、日、时、分、秒等信息,提供至2100年的记录。

可使用电池供电,也就是说,即使Arduino 在断电状态下,时钟芯片仍然是在运行的。

它使用十分常用的两线式串行总线(I2C),只要两根线即可和Arduino 通信。

3.2 接线图按图示连接Arduino 和I2C模块。

除了I2C的两根通讯线外,还要提供电源,所以一共要接4根线,注意不要接反VCC和GND。

3.3 DS1307的使用运行Arduino IDE,打开以下文件可以在Arduino IDE中看到以下代码:#include <Wire.h>#include <RTClib.h>void printDateTime(DateTime dateTime);//创建实例RTC_DS1307 RTC;void setup (void){Serial.begin(9600);//初始化总线Wire.begin();//初始化实时时钟RTC.begin();}void loop() {if (Serial.available() > 0) {int instruct = Serial.read();switch (instruct) {case'D': {//获取当前日期和时间DateTime now = RTC.now();//通过串口传送当前的日期和时间printDateTime(now);break;} case'S'://设置成6月RTC.set(RTC_MONTH, 6);//设置成16点RTC.set(RTC_HOUR, 16);break;}}}void printDateTime(DateTime dateTime) {//传送年份Serial.print(dateTime.year(), DEC);Serial.print('/');//传送月份Serial.print(dateTime.month(), DEC);Serial.print('/');//传送月份中的第几天Serial.print(dateTime.day(), DEC);Serial.print(' ');//传送小时Serial.print(dateTime.hour(), DEC);Serial.print(':');//传送分钟Serial.print(dateTime.minute(), DEC);Serial.print(':');//传送秒Serial.print(dateTime.second(), DEC);Serial.println();}编译并上传到Arduino,打开串口监控器,当输入字符“D”时,会返回当前的时间而当输入字符“S”时,则会设置RTC为代码中指定的时间。

合集下载

实时时钟模块(I2C总线)PT7C4311说明书

实时时钟模块(I2C总线)PT7C4311说明书

Real-time Clock Module (I2C Bus)Features→→→→→→→→→→→→→→→→→。

DescriptionFunction BlockNotes:1. No purposely added lead. Fully EU Directive 2002/95/EC (RoHS), 2011/65/EU (RoHS 2) & 2015/863/EU (RoHS 3) compliant.2. See https:///quality/lead-free/ for more information about Diodes Incorporated’s definitions of Halogen - and Antimony-free, "Green" and Lead-free.3. Halogen- and Antimony-free "Green” products are defined as those which contain <900ppm bromine, <900ppm chlorine (<1500ppm total Br + Cl) and <1000ppmSOMaximum RatingsDC Electrical Characteristics(Unless otherwise specified, V= 1.5 ~ 5.5 V, T = -40 °C to +85 °C.)1.After switchover (V SO), V BAT (min) can be2.0V for crystal with R S=40kΩ.2.Switch-over and deselect point.3.Valid for Ambient Operating Temperature: T A = -40 to 85°C; V CC = 2.0 to 5.5V (except where noted). VCC fall time should not exceed 5mV/μs.4.All voltages referenced to GND.5.In 3.3V application, if initial battery voltage is ≥ 3.4V, it may be necessary to reduce battery voltage (i.e., through wave soldering thebattery) in order to avoid inadvertent switchover/reselection for VCC – 10% operation.6.For rechargeable backup, V BAT (max) may be considered to be V CC.AC Electrical CharacteristicsTiming DiagramRecommended Layout for Crystal1212 the equation as below:Cpar + [(C1+C G)*(C2+C D)]/ [(C1+C G)+(C2+C D)] =C LCpar is all parasitical capacitor between X1 and X2.C L is crystal’s load capacitance.Note: The crystal, traces and crystal input pinsshould be isolated from RF generating signals.Function DescriptionOverview of Functions1.Clock function2.Interface with CPU3.Oscillator enable/disable4.Calibration functionRegisters*1. PT7C4311 uses 6 bits for address. That is if write data to 41H, the data will be written to 01H address register.*2. Stop bit. When this bit is set to 1, oscillator and time count chain are both stopped.*3. CEB: Century Enable Bit. CB: Century Bit.*4. Control FT/OUT pin output DC level when 512Hz square wave is disabled.*5. Frequency Test. 512Hz square wave output is enabled at FT/OUT pin, which is using for frequency test.*6. Sign Bit. “1” indicates positive calibration; “0”indicates negative calibration.*7. Using for modifying count frequency. If 20ppm is wanted to slow down the count frequency, 10 (01010) should be loaded. *8. Initialize the control and status register to 10000000 if calibration function is not required.Clock calibrationCalibration:3.Time Counter∙∙∙* Note 2: Do not care.* Note 3: Century Enable Bit and Century Bit.4.Days of the week Counter5.Calendar Counter∙∙Communication1.I2C Bus Interfacea)Overview of I2C-BUSb)System ConfigurationFig.1 System configurationc)Starting and Stopping I2C Bus Communications∙∙∙d)Data Transfers and Acknowledge Responses during I2C-BUS Communication∙Data transfers*Note: with caution that if the SDA data is changed while the SCL line is at high level, it will be treated as a START, RESTART, or STOP condition.Fig.2 Starting and stopping on I2C busData acknowledge response (ACK signal)e)Slave Address2.I2C Bus’s Basic Transfer FormatSCL from Master1289SDA from transmitter(sending side)SDA from receiver(receiving side)Release SDALow activeACK signala)Write via I2C busb)Read via I2C bus∙Standard read∙Simplified readNote:1.The above steps are an example of transfers of one or two bytes only. There is no limit to the number of bytes transferredduring actual communications.2.49H, 4AH are used as test mode address. Customer should not use the addresses.Part MarkingW Package ZE PackagePackaging Mechanical 8- SOIC (W)8- TDFN (ZE)Ordering Information1.No purposely added lead. Fully EU Directive 2002/95/EC (RoHS), 2011/65/EU (RoHS 2) & 2015/863/EU (RoHS 3) compliant.2.See https:///quality/lead-free/ for more information about Diodes Incorporated’s definitions of Halogen- and Antimony-free, "Green" andLead-free.3.Halogen- and Antimony-free "Green” produ cts are defined as those which contain <900ppm bromine, <900ppm chlorine (<1500ppm total Br + Cl) and<1000ppm antimony compounds.4. E = Pb-free and Green5.X suffix = Tape/ReelIMPORTANT NOTICEDIODES INCORPORATED MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH REGARDS TO THIS DOCUMENT, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE (AND THEIR EQUIVALENTS UNDER THE LAWS OF ANY JURISDICTION).Diodes Incorporated and its subsidiaries reserve the right to make modifications, enhancements, improvements, corrections or other changes without further notice tothis document and any product described herein. Diodes Incorporated does not assume any liability arising out of the application or use of this document or any product described herein; neither does Diodes Incorporated convey any license under its patent or trademark rights, nor the rights of others. Any Customer or user of this document or products described herein in such applications shall assume all risks of such use and will agree to hold Diodes Incorporated and all the companies whose products are represented on Diodes Incorporated website, harmless against all damages.Diodes Incorporated does not warrant or accept any liability whatsoever in respect of any products purchased through unauthorized sales channel.Should Customers purchase or use Diodes Incorporated products for any unintended or unauthorized application, Customers shall indemnify and hold Diodes Incorporated and its representatives harmless against all claims, damages, expenses, and attorney fees arising out of, directly or indirectly, any claim of personal injuryor death associated with such unintended or unauthorized application.Products described herein may be covered by one or more United States, international or foreign patents pending. Product names and markings noted herein may also be covered by one or more United States, international or foreign trademarks.This document is written in English but may be translated into multiple languages for reference. Only the English version of this document is the final and determinative format released by Diodes Incorporated.LIFE SUPPORTDiodes Incorporated products are specifically not authorized for use as critical components in life support devices or systems without the express written approval of the Chief Executive Officer of Diodes Incorporated. As used herein:A. Life support devices or systems are devices or systems which:1. are intended to implant into the body, or2. support or sustain life and whose failure to perform when properly used in accordance with instructions for use provided in the labeling can be reasonably expected to result in significant injury to the user.B. A critical component is any component in a life support device or system whose failure to perform can be reasonably expected to cause thefailure of the life support device or to affect its safety or effectiveness.Customers represent that they have all necessary expertise in the safety and regulatory ramifications of their life support devices or systems, and acknowledge andagree that they are solely responsible for all legal, regulatory and safety-related requirements concerning their products and any use of Diodes Incorporated products in such safety-critical, life support devices or systems, notwithstanding any devices- or systems-related information or support that may be provided by Diodes Incorporated. Further, Customers must fully indemnify Diodes Incorporated and its representatives against any damages arising out of the use of Diodes Incorporated products in such safety-critical, life support devices or systems.Copyright © 2020, Diodes Incorporated。

武汉吉阳光电 GY7505 UART-I2C GY7506 RS232-I2C 转换模块说明书

武汉吉阳光电 GY7505 UART-I2C GY7506 RS232-I2C 转换模块说明书

GY7505 UART-I2C ModuleGY7506 RS232-I2C Module产品使用说明书产品型号:GY7505/GY7506手册版本:V1.05目录一、产品简介 (3)1.1 性能与技术指标 (3)1.2 典型应用 (3)1.3 通信协议转换 (3)1.4 产品销售清单 (3)1.5 技术支持与服务 (3)1.6 I2C适配器产品定购信息 (4)二、外形与接口描述 (5)2.1产品外形 (5)2.2引脚描述 (5)2.3封装尺寸 (5)2.4 PIN脚定义 (5)三、电气特性 (6)四、串口波特率设置 (6)五、软件操作指令及举例 (7)5.1 Easy I2C (7)5.2 串口命令详解 (7)5.2.1 选择I2C当前通道号 (7)5.2.2获取I2C当前通道号 (8)5.2.3设置当前I2C通道的I2C速率 (8)5.2.4获取当前I2C通道的I2C速率 (8)5.2.5 Easy I2C写操作 (8)5.2.6 Easy I2C读操作 (8)5.3 常见问题现象 (9)六、利用VCI_GYI2C库函数二次开发 (10)七、应用系统示意图 (10)八、附录:AT24CXX芯片参数 (11)一、产品简介1.1 性能与技术指标1)RS232或UART串口转I2C总线接口,1路I2C接口输出。

2)标准的I2C主机接口,Master方式,兼容SMbus协议;3)GY7506 串口为RS232电平,可与PC串口相连。

GY7505串口为UART TTL电平,可与MCU直接相连。

4)电源输入:+5V5)I2C接口信号:SCL,SDA,GND6)输出信号3.3V TTL,输入5VTTL 可承受。

7)串口速率硬件设置,支持9600、119200、57600、115200bps8)I2C总线速率软件设置,支持1k-800khz。

9)支持一体化傻瓜式读写模式(Easy I2C)。

10)支持通过串口软件指令控制I2C接口的读写操作,进行二次开发。

电子罗盘模块使用手册 CMPS04-I2C.

电子罗盘模块使用手册 CMPS04-I2C.
新动力电子
CMPS04-I2C 电子罗盘模块
电子罗盘模块使用手册 CMPS04-I2C
/
概述:CMPS04-I2C 是一款高性能平面数字罗盘模块,其工作原理是通过磁阻传感器感应地球磁场的磁分 量,从而得出方位角度。该罗盘以 I2C 方式与上位进行通信。CMPS04 模块相当于一个 AT24C02 的存储器
校准的方法:
当罗盘周围磁场改变后,罗盘计算输出的角度信息将不准确,这时要对罗盘进行校准,以此对罗盘周 围磁场改变所产生的影响进行校正。方法:将罗盘水平放置发送 0x51 到命令寄存器之后均匀缓慢的旋转两 周,不可以太快,旋转一周时间应该不小于 1 分钟,一般 1 分钟旋转一周,(可以绕自身的中轴旋转,也可 以绕平面内一点作圆周运动),然后发送 0x52 到命令寄存器结束校准。
(2)电子罗盘的干扰信号 电子罗盘在稳定的磁环境下补偿适中的偏差,但是它不能补偿改变的磁干扰。比如,带直流电的电线产 生磁场,如果直流电改变,磁场大小也将改变。电源也一个变化的干扰源。 电子罗盘是消除不了变化的磁 环境干扰。
(3)电子罗盘的测量精度 国外号称是世界上精度最高的电子罗盘(C100),价格是大概 795 美元,它的航向精度能达到 0.5 度
改变目前 0xE0 设备地址( 默认出厂地址)到 0xE8,请按正确的顺序写入命令字符( 0xA0,0xAA,0xA5,0xE8 )。
这些命令必须发送正确的顺序才改变 I2C 地址,写入这个命令之间不能有其它的操作命令字符。 该命令字
符序列必须发送到命令寄存器的位置。操作完成后,你应该标签 IIC 地址,如果你忘了修改后的 IIC 地址,
你可以看发光二极管的闪烁状态。IIC 地址会在 LED 输出显示。 LED 长闪烁后就是一个 IIC 地址指示,较

SBGC32_I2C_Drv扩展模块参考手册说明书

SBGC32_I2C_Drv扩展模块参考手册说明书

SBGC32_I2C_Drv expansion module reference manualver. 0.2 – 28.03.2015 – first editionver. 0.3 – 11.04.2015 – Add “Q&A”, “Flashing MCU” sections.ver. 0.4 – 27.12.2017 – Add "API and examples" sectionver.0.5 – 05.09.2018 – The list of supported encoders was extended by new models; text was updated to conform with the latest GUI and firmware versions;OverviewThis module is intended to work as a part of the SimpleBGC32 camera stabilizer system,performing a motor driver function. Unlike regular scheme, where all motors and encoders are connected to the main board and driven by the single MCU, in the modular scheme eachmotor is driven by its own MCU, that lets to optimize cabling: encoder is integrated into the PCB for each module, and motor's cable goes to it by the shortest way. See Appendix A for an example of connection. Schematics, firmware and other resources you can find on the product's page: https:///sbgc32_i2c_drv/This expansion module is supported only in the encoder-enabled version of the SimpleBGC32 firmware: https:///encoders/Features:•Flexibility - This module can replace one or two motor+encoder pairs. Using it for all three motors is possible, but not recommended because I2C transfer on 400kHz ratewill not fit into 800us cycle time. There is an option to increase I2C speed to 800kHzfor small systems.•Low cost - Each module consists of entry-level STM32F051 series MCU, cheap magnetic or analog encoder, a FET- or IC-based motor driver and a minimal number of othercomponents.•Better cabling - a 5-wire cable is required to connect main MCU with the I2C_Drv modules and IMU sensor, all connected in parallel.•Compact size - MCU is available in the UFQFPN32 package, allowing ultra-compact design and installation into small motors.•Reliable, low power consumption - rotary encoders allow to apply advanced FOC algorithm for driving motors•Software compatibility - fully compatible with SimpleBGC32 software stack (including GUI, mobile applications, Serial API, etc.)Motor driver output circuitModule provides 6 PWM outputs to drive 3 half-bridges at ultra-sonic frequency. 300-400ns dead-time is inserted. It lets to use simple FET-based output circuit, or use integrated circuits like DRV8839, DRV8313, and any other IC that encloses 3 half-bridges and all protection circuits. Several output driver circuits are provided in the schematics, as an example.EncoderOne of the purposes of this module is to let to integrate encoder and motor driver into single PCB to minimize overall size of a system. For this purpose, a compact-sized magnetic encoder will be the best choice.List of supported encoders with its props and cons:Model Installation Interface Props ConsAS5048A on-axis SPI small size, high resolution(14bit), high update rate,perfect integration expensive compared to other magnetic ICsAS5048B on-axis I2C small size, high resolution(14bit), high update rate,perfect integration expensive; compatible with the 48- or 64-pin MCU only;AMT203on-axisin housing SPI shaft with pass-through holeis possible; easy installationon a shaftbig size; mediumupdate rate;external mountingonly; expensiveMA3 (10bit, 12bit)on-axisin housingPWM external mountingonly; slow updaterate; expensiveAnalog?analog low cost, good integration,high update rate full 360 degree rotation is not possible; friction reduces a life-cycle;AS5600on-axis I2C low cost, good integration,high update rate compatible with the 48- or 64-pin MCU only;AS5050A on-axis SPI low cost, good integration medium updaterate; low resolution AS5055A on-axis SPI low cost, good integration medium update rate RLS "Orbis"off-axisPCB w/outhousingSPI pass-through hole expensiveMA730on-axis SPI low cost; high resolution14bit; ultra-compact size;high update rate;AM4096on-axis I2C low noise, true 12bit big size of ICpackage; compatiblewith the 48- or 64-pin MCU only; Notes:1.Update rate is not crucial parameter for general application of the SimpleBGC system, so all types ofsupported encoders suit well.2.With the on-axis encoder, a special effort is required when designing a system that should support aninfinite 360-degrees rotation of a motor. When using sliprings, pay special attention to normal work of the I2C bus. It may be required to use I2C signal extenders / amplifiers.More information about using and configuring encoders in the SimpleBGC32 system you can find in this document: https:///files/SimpleBGC_32bit_Encoders.pdfNotes on schematicsWe provide a reference schematics, which contains a circuits for some types of supported encoders, several examples of output motor driver circuits and several packages of MCU (you can chose from LQFP32, UFQFPN32, LQFP48, UFQFPN48, UFBGA64 case, 32k or more FLASH). There are 2 options for flashing MCU: via SWD port and ST-Link utility, or via UART port and integrated bootloader. For the second option, additional components are required, as shown on the schematics.For the I2C encoders, 32-pin MCU case is not applicable. Use 48- or 64-pin case.Flashing MCUT o upload firmware, you can use UART port and Flash Loader Demonstrator tool from ST company, or any other flashing tool that can communicate with standard STM32 bootloader, including our GUI "Upgrade" tab in the manual mode. Second option is SWD port and ST-Link tool and utility (can be bought separately or found as a part of some "STM32Discovery" boards). Both interfaces are shown in the schematics, choose one that you like.Configuring SimpleBGC 32bit controller to work with the expansion modules1. Open SimpleBGC GUI , go to “Advanced” tab, “Motor outputs” group. Chose“SBGC32_I2C_drv#1..4” module in the drop-down list for any axis you want. Number 1..4 is configured by setting ADDR0, ADDR1 jumpers on the module: solder jumper to connect address pin to VDD for high level, or leave it floating to set low level (pin is pulled-down internally).Role ADDR0ADDR1SBGC32_I2C_drv#10 (low)0 (low)SBGC32_I2C_drv#2 1 (high)0 (low)SBGC32_I2C_drv#30 (low) 1 (high)SBGC32_I2C_drv#4 1 (high) 1 (high)2. In the “Encoders” tab, chose the same module for corresponding axis. Select a type of encoder, installed on the module, in the drop-down list below.3. It's better to increase the I2C speed by selecting the “I2C high speed” option in the “Hardware” tab, to minimize delays caused by the I2C data transfer. But it may be required to decrease overall resistance of pullups on SDA, SCL lines to 1..2k, otherwise I2C errors may come. Please pay attention to this fact when designing your own system.4. Second (frame) IMU is not required for the encoder-enabled gimbal design and may be omitted.All other settings for motor output and encoder are remain the same as in regular system. You can find further instructions in the "SBGC32 User Manual" and the "Encoders" manual, available to download from our web-site:https:///files/v3/SimpleBGC_32bit_manual_2_6x_eng.pdfhttps:///files/SimpleBGC_32bit_Encoders.pdfLicensingBinary firmware and schematics for SBGC32_I2C_Drv module are provided free of charge, limited to use only as a part of the SimpleBGC 32bit controller-based system. Source code is a property of Basecamelectronics and is not published. It is available for our partners upon a request.Q&AQ: How does it identify the motor pitch and the motor roll?A: There are 2 ADDR pins to chose I2C slave device address from four options. Set any unique address for each module, that defines them as “module 1..4”, than choose corresponding module in the GUI. More information can be found in the section "Configuring SimpleBGC32bit controller to work with the expansion modules".Q: I cannot find a circuit diagram of the main controller to be used in a modular scheme. What canI refer to in order to find it?A: The main controller is based on the regular 32bit board reference schematics. You can remove unused motor drivers and connectors to optimize its size, and add other service electronics like LiPo charger, bluetooth module, smart power switch, etc., that are not present in the original SBGC32 reference design. All functions and interfaces of the main controller are available as before, and you can still use main controller to drive any motor directly, or drive it via I2C_Drv.Q: Is it possible to apply DRV8313 instead of the original motor driver, shown in the schematics? If it is not possible, how can we get increased motor power?A: Yes, you can apply DRV8313 or any other suitable motor driver that has 3 independent full-bridges with the 3x PWM inputs and ENABLE input, compatible with the 3V-level logic.Q: I want to use I2C_Drv with the encoder that is not present in the list. Is it possible?A: You can send a request to the Basecamelectronics team for adding a support of a new model of encoder in the I2C_Drv firmware. Note that it should have I2C or SPI-compatible interface, and should be absolute. Incremental encoders ate not supported! Also consider using the "CAN Driver" module, that acts similar to the I2C_Drv module, but has more advanced motor control algorithms and provides more connection optionshttps:///can_driver/Appendix A: SBGC32_I2C_Drv connection diagramoutput driver)© Basecamelectronics® 2015Appendix B: I2C_Drv API and examplesThe API consists of the definition of I2C registers. The master controller reads and writes them to operate the module.I2C_Drv.h/*This is a part of SimpleBGC project source codeCopyright (c) 2015 Aleksei MoskalenkoSBGC32_i2c_drv - expansion board with brushless driver, encoder and I2C interface*/#ifndef I2C_DRV_H_#define I2C_DRV_H_// Device address (7bit)#define I2C_DRV_START_ADDR 0x19// Device identifier. Check it when discovering#define I2C_DRV_DEVICE_ID 0x14/************** Register map **************************//* Note that though registers are 16bit, lower byte can be read/written by 8bit transactions */// Encoder#define I2C_DRV_REG_ENC_RAW_ANGLE 40#define I2C_DRV_REG_ENC_ANGLE 41#define I2C_DRV_REG_ENC_INFO 6#define I2C_DRV_REG_ENC_ERR_CNTR 42// Motor driver#define I2C_DRV_REG_SET_POWER_ANGLE 0#define I2C_DRV_REG_SET_POWER 0#define I2C_DRV_REG_SET_ANGLE 1#define I2C_DRV_REG_SET_FORCE_POWER 2#define I2C_DRV_REG_SET_ENABLE 3// Configuration#define I2C_DRV_REG_ENC_TYPE 4#define I2C_DRV_REG_ENC_CONF 5#define I2C_DRV_REG_ENC_FLD_OFFSET 7// Device info#define I2C_DRV_REG_DEVICE_ID 39#define I2C_DRV_REG_FIRMWARE_VER 32#define I2C_DRV_REG_MCU_ID 33#define I2C_DRV_MCU_ID_SIZE 6#define I2C_DRV_REG_I2CS_ERR_CNTR 43// Misc. functions#define I2C_DRV_REG_RESET_MODE 8/********************************************************/// Types of supported encoders#define I2C_DRV_ENC_TYPE_AS5048A 1#define I2C_DRV_ENC_TYPE_AS5048B 2#define I2C_DRV_ENC_TYPE_AMT203 3#define I2C_DRV_ENC_TYPE_MA3_10BIT 4#define I2C_DRV_ENC_TYPE_MA3_12BIT 5#define I2C_DRV_ENC_TYPE_ANALOG 6#define I2C_DRV_ENC_TYPE_AS5600 7#define I2C_DRV_ENC_TYPE_AS5050A 8#define I2C_DRV_ENC_TYPE_AS5055A 9#endif/* I2C_DRV_H_ */Example of using I2C_Drvuint8_t OutputI2CDrv::init(uint8_t _out_port, uint8_t _axis){addr = (I2C_DRV_START_ADDR - 3) + _out_port;cur_power = 0;// Check if I2C board is connected (wait 2 sec)i2c::select_line(I2C_LINE_A);for(uint8_t i=0; i<100; i++) {if(i2c::read_reg_byte(addr, I2C_DRV_REG_DEVICE_ID) == I2C_DRV_DEVICE_ID) { // check device IDreturn 1;}}return 0;}void OutputI2CDrv::write_reg_byte(uint8_t reg, uint8_t val) {i2c::select_line(I2C_LINE_A);i2c::write_reg_byte(addr, reg, val);}void OutputI2CDrv::powerOn() {write_reg_byte(I2C_DRV_REG_SET_ENABLE, 1);}void OutputI2CDrv::powerOff() {write_reg_byte(I2C_DRV_REG_SET_ENABLE, 0);}void OutputI2CDrv::output16(uint16_t el_angle) {i2c::select_line(I2C_LINE_A);uint16_t buf[2] = { cur_power, el_angle };i2c::write_reg_buf(addr, I2C_DRV_REG_SET_POWER_ANGLE, (void*)buf, sizeof(buf));// TODO: We can write force power, if encoder fld.offset is calibrated// (not yet implemented in the I2C_DRV firmware)}// Search for the I2C_Drv-connected encodervoid Encoder::_init_i2c_drv(uint8_t type) {i2c.addr = (I2C_DRV_START_ADDR - ENC_TYPE_I2C_DRV1) + type;i2c::select_line(I2C_LINE_A);if(i2c::read_reg_byte(i2c.addr, I2C_DRV_REG_DEVICE_ID) == I2C_DRV_DEVICE_ID) { // Get firmware version, if required//uint16_t frw_ver;//i2c::read_reg_buf(addr, I2C_DRV_REG_FIRMWARE_VER, &frw_ver, 2);// Configure the type of internal encoderif(i2c::write_reg_byte(i2c.addr, I2C_DRV_REG_ENC_TYPE, cfg)) {// Read it back to confirm activation. Wait max. 50msfor(uint8_t i=0; i<50 && !encoder_type; i++) {Time::delay_us(1000);if(i2c::read_reg_byte(i2c.addr, I2C_DRV_REG_ENC_TYPE) == cfg) {encoder_type = type;// configure field calibration//i2c::write_reg_buf(addr, I2C_DRV_REG_ENC_FLD_OFFSET,&(params.encoder_fld_offset[axis]), 2);// Configure encoder// bits 0..3: LPF factor// bit 4: I2C fast modeuint16_t conf = 5;i2c::write_reg_buf(i2c.addr, I2C_DRV_REG_ENC_CONF, &conf, sizeof(conf));}}}}i2c::errors_count = 0;}uint16_t Encoder::_read_i2c_drv() {uint16_t angle;i2c::select_line(I2C_LINE_A);if (i2c::read_reg_buf(i2c.addr, I2C_DRV_REG_ENC_ANGLE, &angle, 2)) {read_error = 0;return angle;}return 0;}void Encoder::_request_info_i2c_drv(uint8_t info[4]) {// info[0] - encoder error counter// info[1] - I2C slave error counter// Sub-type AS5048A, AS5048B:// info[2] - magnitude// info[3] - diagnostic registeri2c::select_line(I2C_LINE_A);info[0] = i2c::read_reg_byte(i2c.addr, I2C_DRV_REG_ENC_ERR_CNTR);info[1] = i2c::read_reg_byte(i2c.addr, I2C_DRV_REG_I2CS_ERR_CNTR);// Write any data to ENC_INFO reg to queue information from encoderif(i2c::write_reg_byte(i2c.addr, I2C_DRV_REG_ENC_INFO, 0)) {Time::delay_ms(50); // wait a bit to let device to read informationi2c::read_reg_buf(i2c.addr, I2C_DRV_REG_ENC_INFO, &info[2], 2);}}© Basecamelectronics® 2018。

i2c读取流程

i2c读取流程

i2c读取流程I2C读取流程I2C(Inter-Integrated Circuit)是一种串行通信协议,用于在集成电路之间进行通信。

在本文中,我们将介绍I2C的读取流程,以及相关的步骤和注意事项。

一、I2C概述I2C是由飞利浦半导体(现在的恩智浦半导体)开发的一种串行通信协议,用于在集成电路之间进行通信。

它使用两根线(SDA和SCL)来进行数据传输,其中SDA线用于数据传输,SCL线用于时钟同步。

二、I2C读取流程I2C的读取流程主要分为以下几个步骤:1. 初始化:首先,需要初始化I2C总线,设置相关的参数和寄存器。

初始化的过程包括设置I2C的工作模式、设置时钟频率等。

2. 发送起始信号:在读取之前,需要发送一个起始信号来启动通信。

起始信号是一个低电平的SDA线上升沿,紧接着是一个低电平的SCL线上升沿。

3. 发送设备地址:在发送起始信号后,需要发送要读取的设备的地址。

设备地址是一个7位的二进制数,用于唯一标识设备。

通常情况下,设备地址的最高位是0,用于指示读取操作。

4. 等待应答:发送设备地址后,需要等待设备的应答信号。

应答信号是设备在SCL线的下降沿上发送一个低电平的信号。

5. 读取数据:一旦收到设备的应答信号,就可以开始读取数据。

读取数据的过程是从设备读取一个字节,并发送一个应答信号来确认接收到数据。

6. 终止通信:在读取完所有需要的数据后,需要发送一个终止信号来结束通信。

终止信号是一个高电平的SDA线下降沿,紧接着是一个高电平的SCL线下降沿。

三、注意事项在进行I2C读取时,需要注意以下几个事项:1. 确保设备地址正确:读取操作需要发送正确的设备地址,否则将无法与设备通信。

2. 正确处理应答信号:在发送设备地址后,需要等待设备的应答信号。

如果没有收到应答信号,可能是设备未连接或者设备地址错误。

3. 处理读取的数据:读取数据后,需要进行适当的处理和解析。

根据具体的应用场景,可能需要将数据进行转换或者计算。

iic读取光模块信息

iic读取光模块信息

iic读取光模块信息
IIC(I2C)是一种用于连接微控制器和其外围设备的总线协议。

它可以用于读取光模块的信息。

下面是一种可能的方法:
1.硬件连接:首先,确保光模块和微控制器(如单片机)之间通过I2C总线正确
连接。

光模块通常具有SDA(数据线)和SCL(时钟线)两个接口,它们需要分别连接到微控制器的I2C接口。

2.初始化I2C接口:在微控制器上,需要初始化I2C接口。

这通常涉及到设置I2C
的频率、数据格式等参数。

3.发送读取命令:通过I2C接口向光模块发送读取命令。

命令的具体格式取决于
光模块的类型和制造商的规范。

通常,这些命令是预定义的,并且可以在光模块的数据手册中找到。

4.接收光模块信息:发送命令后,微控制器需要从I2C接口接收光模块的信息。

这可能包括模块类型、波长、传输距离等模块信息,以及工作电压、模块温度、激光器偏置电流、发射光功率、接收光功率等实时信息。

5.解析和处理信息:接收到的信息需要进行解析和处理。

这可以通过编程实现,
例如使用微控制器的编程语言(如C、Python等)来处理数据。

请注意,具体的实现方式可能因光模块的类型和微控制器的型号而有所不同。

因此,建议查阅相关的技术手册和数据表,以获得更详细的信息和指导。

另外,对于BH1750光传感器,虽然它是通过I2C接口进行通信的,但其读取的数据是光强度信息,而不是光模块的信息。

因此,对于BH1750光传感器的读取,需要参考其特定的数据手册和规范来实现。

i2c vip使用手册

i2c vip使用手册I2C是Inter-Integrated Circuit的缩写,是一种串行通信协议,在电子设备中被广泛用于连接微控制器和外部器件。

I2C VIP(Verification IP)是为了验证I2C总线协议的正确性而开发的验证工具。

本手册将详细介绍I2C VIP的使用方法和操作步骤。

I2C VIP的安装与配置在使用I2C VIP之前,用户需要首先下载并安装相应的验证工具软件。

在安装完成后,通过运行该软件并按照指示进行配置,将I2C VIP 添加到工程中以便后续的使用。

I2C VIP的基本功能1. Master模式和Slave模式I2C VIP提供了Master模式和Slave模式的支持,用户可以根据需求选择适合的模式进行验证。

在Master模式下,用户可以控制整个通信过程,并发送和接收数据。

而在Slave模式下,用户可以模拟设备的行为,接收Master发来的指令并返回相应的数据。

2. 地址和数据传输I2C VIP支持地址和数据的传输,用户可以通过指定正确的地址来识别和访问相应的设备。

同时,用户可以发送各种数据类型(如控制命令和传感器数据等)。

3. 起始和停止条件在I2C协议中,起始和停止条件是控制通信开始和结束的关键。

I2C VIP能够自动产生起始和停止条件,简化了用户的操作流程。

4. 错误检测和报告I2C VIP具备错误检测功能,能够检测并报告通信中的错误信息,如传输超时、无应答等情况,便于用户快速定位和解决问题。

I2C VIP的使用步骤下面将介绍使用I2C VIP的基本步骤,以帮助用户快速上手。

1. 创建VIP环境在验证工具软件中,用户需要新建一个VIP环境,选择I2C VIP并配置相应参数,如时钟频率、地址长度等。

然后,将I2C VIP与所需验证的模块连接起来。

2. 配置Master模块在配置Master模块时,用户需要指定相关的参数,如通信速率、传输模式等。

用户还可以编写测试脚本,通过设置寄存器的值来控制具体的数据传输操作。

EEPROM I2C操作说明知识讲解

E E P R O M I2C操作说明I2C协议2条双向串行线,一条数据线SDA,一条时钟线SCL。

SDA传输数据是大端传输,每次传输8bit,即一字节。

支持多主控(multimastering),任何时间点只能有一个主控。

总线上每个设备都有自己的一个addr,共7个bit,广播地址全0.系统中可能有多个同种芯片,为此addr分为固定部分和可编程部份,细节视芯片而定,看datasheet。

1.1 I2C位传输数据传输:SCL为高电平时,SDA线若保持稳定,那么SDA上是在传输数据bit;若SDA发生跳变,则用来表示一个会话的开始或结束(后面讲)数据改变:SCL为低电平时,SDA线才能改变传输的bit1.2 I2C开始和结束信号开始信号:SCL为高电平时,SDA由高电平向低电平跳变,开始传送数据。

结束信号:SCL为高电平时,SDA由低电平向高电平跳变,结束传送数据。

1.3 I2C应答信号Master每发送完8bit数据后等待Slave的ACK。

即在第9个clock,若从IC发ACK,SDA会被拉低。

若没有ACK,SDA会被置高,这会引起Master发生RESTART或STOP流程,如下所示:1.4 I2C写流程写寄存器的标准流程为:1. Master发起START2. Master发送I2C addr(7bit)和w操作0(1bit),等待ACK3. Slave发送ACK4. Master发送reg addr(8bit),等待ACK5. Slave发送ACK6. Master发送data(8bit),即要写入寄存器中的数据,等待ACK7. Slave发送ACK8. 第6步和第7步可以重复多次,即顺序写多个寄存器9. Master发起STOP写一个寄存器写多个寄存器1.5 I2C读流程读寄存器的标准流程为:1. Master发送I2C addr(7bit)和w操作1(1bit),等待ACK2. Slave发送ACK3. Master发送reg addr(8bit),等待ACK4. Slave发送ACK5. Master发起START6. Master发送I2C addr(7bit)和r操作1(1bit),等待ACK7. Slave发送ACK8. Slave发送data(8bit),即寄存器里的值9. Master发送ACK10. 第8步和第9步可以重复多次,即顺序读多个寄存器读一个寄存器读多个寄存器1.前言对于大多数工程师而言,I2C永远是一个头疼的问题。

硬件i2c调用

硬件i2c调用
I2C(Inter-Integrated Circuit)是一种串行通信协议,通常用于连接微控制器和各种外围设备,如传感器、EEPROM、显示器等。

在硬件I2C调用中,我们直接使用硬件的I2C 模块,而不是通过软件模拟I2C通信。

这样可以提高通信速度,降低CPU的负担,并确保数据的可靠传输。

硬件I2C调用的步骤通常如下:
初始化硬件I2C模块:首先,我们需要配置I2C模块的参数,如通信速率、数据位宽度、奇偶校验等。

这些参数根据所连接的外围设备和需求进行设置。

发送设备地址:在开始通信时,主设备会发送一个设备地址给从设备,表示它想与之通信。

从设备会响应这个地址,确认它在接收数据。

发送数据:一旦建立通信,主设备就可以发送数据给从设备。

数据在I2C总线上以字节的形式传输,每个字节后跟一个应答信号。

接收数据:从设备可以发送数据回主设备。

同样,数据以字节的形式传输,每个字节后跟一个应答信号。

结束通信:当所有数据都已发送或接收完毕时,主设备会发送一个停止信号,结束通信。

硬件I2C调用通常需要特定的硬件支持,包括I2C控制器和相关硬件引脚。

不同的微控制器制造商可能会有不同的硬件I2C调用方法和库函数。

例如,在Arduino平台上,硬件I2C调用可以使用Wire库函数实现,而在基于STM32的系统中,可以使用HAL库提供的函数。

需要注意的是,硬件I2C调用需要仔细配置和正确使用,否则可能会导致通信错误或设备损坏。

因此,在进行硬件I2C调用时,建议仔细阅读相关硬件和软件文档,并遵循制造商的推荐做法。

gd32硬件i2c 读写流程

gd32硬件i2c 读写流程下载温馨提示:该文档是我店铺精心编制而成,希望大家下载以后,能够帮助大家解决实际的问题。

文档下载后可定制随意修改,请根据实际需要进行相应的调整和使用,谢谢!并且,本店铺为大家提供各种各样类型的实用资料,如教育随笔、日记赏析、句子摘抄、古诗大全、经典美文、话题作文、工作总结、词语解析、文案摘录、其他资料等等,如想了解不同资料格式和写法,敬请关注!Download tips: This document is carefully compiled by theeditor. I hope that after you download them,they can help yousolve practical problems. The document can be customized andmodified after downloading,please adjust and use it according toactual needs, thank you!In addition, our shop provides you with various types ofpractical materials,such as educational essays, diaryappreciation,sentence excerpts,ancient poems,classic articles,topic composition,work summary,word parsing,copy excerpts,other materials and so on,want to know different data formats andwriting methods,please pay attention!1. 初始化 I2C 模块配置 I2C 引脚:选择用于 I2C 通信的引脚,并将其设置为相应的功能。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
相关文档
最新文档