I2C_24C64驱动程序
19264显示驱动程序
19264控制器KS0108#include <at89x52.h>#include <intrins.h>#include "zimo.h"#define RS P2_6 /*"H" is send or read the data;"L" is the instruction*/ #define RW P3_6#define E P2_5 /*Operation enable*/#define CS1 P2_4#define CS2 P2_3#define CS3 P2_2#define DATA P0#define uchar unsigned char#define uint unsigned int/* -------------------------------------------------Delay some time----------- */void delay10ms(unsigned char x){unsigned char i,j,k;for(i=0;i<x;i++)for(j=0;j<10;j++)for(k=0;k<120;k++);}/* -------------------------------------------------Send the instruction to the First KS0108 window--*/void OutFI(uchar i){unsigned char data_sta;do{E=0;RW=1;RS=0;CS1=0;_nop_();E=1;_nop_();data_sta=DATA;E=0;RW=0;CS1=1;E=1;}while(data_sta&0x80);E=0;RW=0;RS=0;CS1=0;_nop_();E=1;_nop_();DATA=i;_nop_();E=0;RW=1;CS1=1;E=1;}/* ------------------------------------------------- Send the instruction to the Second KS0108 window.--*/void OutSI(uchar i){unsigned char data_sta;do{E=0;RW=1;RS=0;CS2=0;_nop_();E=1;_nop_();data_sta=DATA;E=0;RW=0;CS2=1;E=1;}while(data_sta&0x80);E=0;RW=0;RS=0;CS2=0;_nop_();E=1;_nop_();DATA=i;_nop_();E=0;RW=1;CS2=1;E=1;}/* ------------------------------------------------- Send the instruction to the Third KS0108 window--*/void OutTI(uchar i){unsigned char data_sta;do{E=0;RW=1;RS=0;CS3=0;_nop_();E=1;_nop_();data_sta=DATA;E=0;RW=0;CS3=1;E=1;}while(data_sta&0x80);E=0;RW=0;RS=0;CS3=0;_nop_();E=1;_nop_();DATA=i;_nop_();E=0;RW=1;CS3=1;E=1;}/* -------------------------------------------------Send the data to the First ks0108 Window--*/void OutFD(uchar i){unsigned char data_sta;do{E=0;RW=1;RS=0;CS1=0;_nop_();E=1;_nop_();data_sta=DATA;E=0;RW=0;CS1=1;E=1;}while(data_sta&0x80);E=0;RW=0;RS=1;CS1=0;_nop_();E=1;_nop_();DATA=i;_nop_();E=0;RW=1;CS1=1;E=1;}/* ------------------------------------------------- Send the data to the Second ks0108 Window--*/void OutSD(uchar i){unsigned char data_sta;do{E=0;RW=1;RS=0;CS2=0;_nop_();E=1;_nop_();data_sta=DATA;E=0;RW=0;CS2=1;E=1;}while(data_sta&0x80);E=0;RW=0;RS=1;CS2=0;_nop_();E=1;_nop_();DATA=i;_nop_();E=0;RW=1;CS2=1;E=1;}/* ------------------------------------------------- Send the data to the Third ks0108 Window--*/void OutTD(uchar i){unsigned char data_sta;do{E=0;RW=1;RS=0;CS3=0;_nop_();data_sta=DATA;E=0;RW=0;CS3=1;E=1;}while(data_sta&0x80);E=0;RW=0;RS=1;CS3=0;_nop_();E=1;_nop_();DATA=i;_nop_();E=0;RW=1;CS3=1;E=1;}/* ------------------------------------------------- Read the data to the First ks0108 Window--*//*unsigned char RD_data_F(){unsigned char data_sta;do{E=0;RW=1;RS=0;CS1=0;_nop_();E=1;_nop_();data_sta=DATA;E=0;RW=0;CS1=1;E=1;}while(data_sta&0x80);E=0;RW=1;RS=1;CS1=0;_nop_();E=1;_nop_();_nop_();_nop_();data_sta=DATA;_nop_();E=0;RW=0;CS1=1;E=1;return (data_sta);}/* ------------------------------------------------- Read the data to the Second ks0108 Window--*//*unsigned char RD_data_S(){unsigned char data_sta;do{E=0;RW=1;RS=0;CS2=0;_nop_();E=1;_nop_();_nop_();_nop_();data_sta=DATA;E=0;RW=0;CS2=1;E=1;}while(data_sta&0x80);E=0;RW=1;RS=1;CS2=0;_nop_();data_sta=DATA;_nop_();E=0;CS2=1;E=1;return (data_sta);}/* ------------------------------------------------- Read the data to the Third ks0108 Window--*//*unsigned char RD_data_T(){unsigned char data_sta;do{E=0;RW=1;RS=0;CS3=0;_nop_();E=1;_nop_();_nop_();_nop_();data_sta=DATA;E=0;RW=0;CS3=1;E=1;}while(data_sta&0x80);E=0;RW=1;RS=1;CS3=0;_nop_();E=1;_nop_();data_sta=DATA;_nop_();E=0;CS3=1;E=1;return(data_sta);}/* ------------------------------------------------- Initialize the LCD,The system reset,invoke First time-*/void InitLCD(){OutFI(0x40); /*Set the Y address 0 */OutSI(0x40);OutTI(0x40);OutFI(0xb8); /*Set the Page 0 */OutSI(0xb8);OutTI(0xb8);OutFI(0xc0); /*Set the display start line 0 */OutSI(0xc0);OutTI(0xc0);OutFI(0x3f); /*Display ON */OutSI(0x3f);OutTI(0x3f);}/* -------------------------------------------------Clear the three ks0108's display ram.Clrscr screen-*/void Clrscreen(){unsigned char i,j;for(i=0;i<8;i++){OutFI(0xb8|i);for(j=0;j<64;j++){OutFI(j|0x40);OutFD(0);}}for(i=0;i<8;i++)(OutSI(0xb8|i);for(j=0;j<64;j++)(OutSI(j|0x40);OutSD(0);}}for(i=0;i<8;i++)(OutTI(0xb8|i);for(j=0;j<64;j++)(OutTI(j|0x40);OutTD(0);}}}/* -------------------------------------------------Display Chinese ideograph;x_add is the x address;It has 4 layers,0,1,2,3; Width is the Chinese ideograph width;bmp is the table's name-*/void DrawBmp(uchar x_add,uchar layer,uchar width,uchar *bmp)(unsigned char x;unsigned int i=0;for(x=x_add;x<x_add+width;x++)(if (x>127) /*The Third KS0108*/(OutTI((x-128)|0x40); /*Set the x address*/OutTI(layer|0xb8); /*Set the y address*/OutTD(bmp[i]); /*Send thd data to LCD ram*/OutTI((x-128)|0x40); /*Display the down screen*/ OutTI((layer|0xb8)+1); i++; /*Display zimo table address add 1*/ OutTD(bmp[i]);}else if (x>63) /*The Second ks0108*/{OutSI((x-64)|0x40);OutSI(layer|0xb8);OutSD(bmp[i]);OutSI((x-64)|0x40);OutSI((layer|0xb8)+1);i++;OutSD(bmp[i]);}else /*The First ks0108*/{OutFI(x|0x40);OutFI(layer|0xb8);OutFD(bmp[i]);OutFI(x|0x40);OutFI((layer|0xb8)+1);i++;OutFD(bmp[i]);}i++;}}/* -------------------------------------------------Display Chinese ideograph;x_add is the x address;It has 4 layers,0,1,2,3; Width is the Chinese ideograph width;bmp is the table's name.-*/void DrawBmp_f(uchar x_add,uchar layer,uchar width,uchar *bmp) {unsigned char x;unsigned int i=0;for(x=x_add;x<x_add+width;x++) (if (x>127)(OutTI((x-128)|0x40);OutTI(layer|0xb8);OutTD(~bmp[i]);OutTI((x-128)|0x40);OutTI((layer|0xb8)+1);i++;OutTD(~bmp[i]);}else if (x>63)(OutSI((x-64)|0x40);OutSI(layer|0xb8);OutSD(~bmp[i]);OutSI((x-64)|0x40);OutSI((layer|0xb8)+1);i++;OutSD(~bmp[i]);}else(OutFI(x|0x40);OutFI(layer|0xb8);OutFD(~bmp[i]);OutFI(x|0x40);OutFI((layer|0xb8)+1);i++;OutFD(~bmp[i]);}i++;}}/*Display indention; x_add is the x address;It has 4 layers,0,1,2,3; Width is the Chinese ideograph width-*/void _DrawBmp_(uchar x_add,uchar layer,uchar width){unsigned char x;for(x=x_add;x<x_add+width;x++){if (x>127){OutTI((x-128)|0x40);OutTI(layer|0xb8);OutTD(0);OutTI((x-128)|0x40);OutTI((layer|0xb8)+1);OutTD(0);}else if (x>63){OutSI((x-64)|0x40);OutSI(layer|0xb8);OutSD(0);OutSI((x-64)|0x40);OutSI((layer|0xb8)+1);OutSD(0);}else{OutFI(x|0x40);OutFI(layer|0xb8);OutFD(0);OutFI(x|0x40);OutFI((layer|0xb8)+1);OutFD(0);/* --------------------------------------------------Display indention; x_add is the x address;It has 4 layers,0,1,2,3; Width is the Chinese ideograph width-*/void _DrawBmp_black(uchar x_add,uchar layer,uchar width){unsigned char x;for(x=x_add;x<x_add+width;x++){if (x>127){OutTI((x-128)|0x40);OutTI(layer|0xb8);OutTD(0xff);OutTI((x-128)|0x40);OutTI((layer|0xb8)+1);OutTD(0xff);}else if (x>63){OutSI((x-64)|0x40);OutSI(layer|0xb8);OutSD(0xff);OutSI((x-64)|0x40);OutSI((layer|0xb8)+1);OutSD(0xff);}else{OutFI(x|0x40);OutFI(layer|0xb8);OutFD(0xff);}}OutFI(x|0x40);OutFI((layer|0xb8)+1);OutFD(0xff);}}}/* --------------------------------------------------Display the line display_data_graph is the display graph data-*/void _DrawBmp_line(uchar x_add,uchar layer,uchar width,uchar display_data_graph) {unsigned char x;unsigned int i=0;for(x=x_add;x<x_add+width;x++){if (x>127){OutTI((x-128)|0x40);OutTI(layer|0xb8);OutTD(display_data_graph);}else if (x>63){OutSI((x-64)|0x40);OutSI(layer|0xb8);OutSD(display_data_graph);}else{OutFI(x|0x40);OutFI(layer|0xb8);OutFD(display_data_graph);}i++;/*Display the column display_data_graph is the display graph data-*/void _DrawBmp_column(uchar x,uchar width) {unsigned int i=0;if (x>127){for(i=0;i<width;i++){OutTI((x-128)|0x40);OutTI(i|0xb8);OutTD(0xff);}}else if (x>63){for(i=0;i<width;i++){OutSI((x-64)|0x40);OutSI(i|0xb8);OutSD(0xff);}}else{for(i=0;i<width;i++){OutFI(x|0x40);OutFI(i|0xb8);OutFD(0xff);}}}}}。
I2C控制器软件使用指南
目录1. 软件获取 (3)2. 软件安装 (3)3. 软件使用 (7)4. 软件高级使用 (9)5. 后记 (12)I2C控制器软件使用指南1.软件获取I2C控制器软件可以在这里下载,目前最新版本为V1.2.0版本。
2.软件安装1)双击安装包程序I2C_Ctrl_SetupV1.2.0.exe。
2)选择语言,我们选择中文,点击“下一步”。
3)点击“下一步”4)选择接受许可协议,点击“下一步”。
5)输入相关信息,点击“下一步”。
6)选择安装类型,我们选择全部安装,程序将安装到默认路径,选择定制可以改变程序安装路径,点击“下一步”。
7)点击“安装”,程序将安装到用户计算机中。
8)正在安装程序9)点击“完成”,程序将完成安装,到这来程序就已经安装好了。
3.软件使用1)双击桌面图标,打开软件。
2)如图为软件界面3)确保I2C控制器已经和计算机连接,如果没有连接或驱动没有正常安装则在选择设备栏将出现如下提示。
4)根据I2C设备设置I2C控制器,我们使用AT24C64存储器芯片为测试芯片,根据芯片手册和硬件连接我们作如下设置:设置说明:1.控制方式一般选择硬件控制,除非I2C设备对总线控制时序有非常严格的要求。
2.设备类型选择主机。
3.速率模式根据I2C设备进行设置,我们所测试的芯片支持最大400K的速度,因此我们选择快速模式,目前该控制器最大支持400K速率。
速度的选择应根据实际I2C设备实际支持速率选择。
4.AT24C64的设备地址宽度为7BIT。
5.AT24C64有子地址,且子地址为2字节宽度。
6.数据包长指每次读写数据每包数据的字节数,若发生大量数据则程序会根据最大包长分割数据,注意,最大包长度不能超过55字节。
这里考虑到AT24C64每次写数据最多为16字节,我们在这里设置为8字节。
7.数据传输速率是指I2C控制器向I2C设备读写数据速率,这里我们设置为400K。
8.设备地址设置为0xA0,这是AT24C64的设备地址,数据从0地址开始写。
CAT24C64 D64 64Kb I2C CMOS 序列 EEPROM 数据手册说明书
64 Kb I2C CMOS Serial EEPROMCAT24C64DescriptionThe CAT24C64 is a 64 Kb CMOS Serial EEPROM device, internally organized as 8192 words of 8 bits each.It features a 32−byte page write buffer and supports the Standard (100 kHz), Fast (400 kHz) and Fast−Plus (1 MHz) I2C protocol. External address pins make it possible to address up to eight CAT24C64 devices on the same bus.Features•Supports Standard, Fast and Fast−Plus I2C Protocol•1.7 V to 5.5 V Supply V oltage Range•32−Byte Page Write Buffer•Hardware Write Protection for Entire Memory•Schmitt Triggers and Noise Suppression Filters on I2C Bus Inputs (SCL and SDA)•Low Power CMOS Technology•1,000,000 Program/Erase Cycles•100 Year Data Retention•Industrial and Extended Temperature Range•SOIC, TSSOP, UDFN 8−pad and Ultra−thin WLCSP 4−bump Packages•This Device is Pb−Free, Halogen Free/BFR Free, and RoHS CompliantFigure 1. Functional Symbol SDASCL WPV CC SSA2, A1, APIN CONFIGURATIONS (Top Views)See detailed ordering and shipping information in the package dimensions section on page 8 of this data sheet.ORDERING INFORMATIONSOIC−8W SUFFIXCASE 751BDSOIC (W), TSSOP (Y),UDFN (HU4)Y SUFFIXCASE 948ALDevice AddressA0, A1, A2Serial DataSDASerial ClockSCLWrite ProtectWPPower SupplyV CCGroundV SSFunctionPin NamePIN FUNCTIONFor the location of Pin 1, please consult thecorresponding package drawing.UDFN−8HU4 SUFFIXCASE 517AZWLCSP−4C4C SUFFIXCASE 567JYSDAWPV CCV SSA2A1A01SCLWLCSPA1A2B1B2SDAV SSSCLV CC1X= Specific Device Code(see ordering information)Y= Production Year (Last Digit)M= Production Month (1−9, O, N, D)W= Production Week CodeMARKINGDIAGRAMS(WLCSP−4)WLCSP−4C4U SUFFIXCASE 567PBXYM(C4C)For serial EEPROM in a US8 package, pleaseTable 1. ABSOLUTE MAXIMUM RATINGSParameters Ratings Units Storage Temperature–65 to +150°C Voltage on Any Pin with Respect to Ground (Note 1)–0.5 to +6.5V Stresses exceeding those listed in the Maximum Ratings table may damage the device. If any of these limits are exceeded, device functionality should not be assumed, damage may occur and reliability may be affected.1.The DC input voltage on any pin should not be lower than −0.5 V or higher than V CC + 0.5 V. During transitions, the voltage on any pin mayundershoot to no less than −1.5 V or overshoot to no more than V CC + 1.5 V, for periods of less than 20 ns.Table 2. RELIABILITY CHARACTERISTICS (Note 2)Symbol Parameter Min UnitsN END (Note 3)Endurance1,000,000Program/Erase Cycles T DR Data Retention100Years2.These parameters are tested initially and after a design or process change that affects the parameter according to appropriate AEC−Q100and JEDEC test methods.3.Page Mode, V CC = 5 V, 25°C.Table 3. D.C. OPERATING CHARACTERISTICS(V CC = 1.8 V to 5.5 V, T A = −40°C to +125°C and V CC = 1.7 V to 5.5 V, T A = −40°C to +85°C, unless otherwise specified.)Symbol Parameter Test Conditions Min Max UnitsI CCR Read Current Read, f SCL = 400 kHz1mAI CCW Write Current Write, f SCL = 400 kHz2mAI SB Standby Current All I/O Pins at GND or V CC T A = −40°C to +85°CV CC≤ 3.3 V1m AT A = −40°C to +85°CV CC > 3.3 V3T A = −40°C to +125°C5I L I/O Pin Leakage Pin at GND or V CC2m AV IL Input Low Voltage−0.5V CC x 0.3V V IH Input High Voltage V CC x 0.7V CC + 0.5V V OL1Output Low Voltage V CC≥ 2.5 V, I OL = 3.0 mA0.4V V OL2Output Low Voltage V CC < 2.5 V, I OL = 1.0 mA0.2V Table 4. PIN IMPEDANCE CHARACTERISTICS(V CC = 1.8 V to 5.5 V, T A = −40°C to +125°C and V CC = 1.7 V to 5.5 V, T A = −40°C to +85°C, unless otherwise specified.) Symbol Parameter Conditions Max UnitsC IN (Note 4)SDA I/O Pin Capacitance V IN = 0 V8pFC IN (Note 4)Input Capacitance (other pins)V IN = 0 V6pFI WP (Note 5)WP Input Current V IN < V IH, V CC = 5.5 V130m AV IN < V IH, V CC = 3.3 V120V IN < V IH, V CC = 1.8 V80V IN> V IH2I A (Note 5)Address Input Current(A0, A1, A2)Product Rev F V IN < V IH, V CC = 5.5 V50m A V IN < V IH, V CC = 3.3 V35V IN < V IH, V CC = 1.8 V25V IN> V IH24.These parameters are tested initially and after a design or process change that affects the parameter according to appropriate AEC−Q100and JEDEC test methods.5.When not driven, the WP, A0, A1 and A2 pins are pulled down to GND internally. For improved noise immunity, the internal pull−down is relativelystrong; therefore the external driver must be able to supply the pull−down current when attempting to drive the input HIGH. T o conserve power, as the input level exceeds the trip point of the CMOS input buffer (~ 0.5 x V CC), the strong pull−down reverts to a weak current source.Table 5. A.C. CHARACTERISTICS(V CC = 1.8 V to 5.5 V, T A = −40°C to +125°C and V CC = 1.7 V to 5.5 V, T A = −40°C to +85°C.) (Note 6)Symbol ParameterStandardV CC = 1.7 V − 5.5 VFastV CC = 1.7 V − 5.5 VFast−PlusV CC = 1.7 V − 5.5 VT A = −405C to +855CUnits Min Max Min Max Min MaxF SCL Clock Frequency1004001,000kHzt HD:STA START Condition Hold Time40.60.25m s t LOW Low Period of SCL Clock 4.7 1.30.45m s t HIGH High Period of SCL Clock40.60.40m s t SU:STA START Condition Setup Time 4.70.60.25m s t HD:DAT Data In Hold Time000m s t SU:DAT Data In Setup Time25010050ns t R (Note 7)SDA and SCL Rise Time1,000300100ns t F (Note 7)SDA and SCL Fall Time300300100ns t SU:STO STOP Condition Setup Time40.60.25m s t BUF Bus Free Time BetweenSTOP and START4.7 1.30.5m st AA SCL Low to Data Out Valid 3.50.90.40m s t DH Data Out Hold Time10010050ns T i (Note 7)Noise Pulse Filtered at SCLand SDA Inputs100100100ns t SU:WP WP Setup Time000m s t HD:WP WP Hold Time 2.5 2.51m s t WR Write Cycle Time555mst PU (Notes 7, 8)Power−up to Ready Mode110.11ms Product parametric performance is indicated in the Electrical Characteristics for the listed test conditions, unless otherwise noted. Product performance may not be indicated by the Electrical Characteristics if operated under different conditions.6.Test conditions according to “A.C. Test Conditions” table.7.Tested initially and after a design or process change that affects this parameter.8.t PU is the delay between the time V CC is stable and the device is ready to accept commands.Table 6. A.C. TEST CONDITIONSInput Levels0.2 x V CC to 0.8 x V CCInput Rise and Fall Times≤ 50 nsInput Reference Levels0.3 x V CC, 0.7 x V CCOutput Reference Levels0.5 x V CCOutput Load Current Source: I OL = 3 mA (V CC≥ 2.5 V); I OL = 1 mA (V CC< 2.5 V); C L = 100 pFPower −On Reset (POR)Each CAT24C64 incorporates Power −On Reset (POR)circuitry which protects the internal logic against powering up in the wrong state. The device will power up into Standby mode after V CC exceeds the POR trigger level and will power down into Reset mode when V CC drops below the POR trigger level. This bi −directional POR behavior protects the device against ‘brown −out’ failure following a temporary loss of power.Pin DescriptionSCL: The Serial Clock input pin accepts the clock signal generated by the Master.SDA: The Serial Data I/O pin accepts input data and delivers output data. In transmit mode, this pin is open drain. Data is acquired on the positive edge, and is delivered on the negative edge of SCL.A 0, A 1 and A 2: The Address inputs set the device address that must be matched by the corresponding Slave address bits. The Address inputs are hard −wired HIGH or LOW allowing for up to eight devices to be used (cascaded) on the same bus. When left floating, these pins are pulled LOW internally. The Address inputs are not available for use with WLCSP 4−bumps.WP: When pulled HIGH, the Write Protect input pin inhibits all write operations. When left floating, this pin is pulled LOW internally. The WP input is not available for the WLCSP 4−bumps, therefore all write operations are allowed for the device in this package.Functional DescriptionThe CAT24C64 supports the Inter −Integrated Circuit (I 2C) Bus protocol. The protocol relies on the use of a Master device, which provides the clock and directs bus traffic, and Slave devices which execute requests. The CAT24C64operates as a Slave device. Both Master and Slave cantransmit or receive, but only the Master can assign those roles.I 2C Bus ProtocolThe 2−wire I 2C bus consists of two lines, SCL and SDA,connected to the V CC supply via pull −up resistors. The Master provides the clock to the SCL line, and either the Master or the Slaves drive the SDA line. A ‘0’ is transmitted by pulling a line LOW and a ‘1’ by letting it stay HIGH. Data transfer may be initiated only when the bus is not busy (see A.C. Characteristics). During data transfer, SDA must remain stable while SCL is HIGH.START/STOP Condition An SDA transition while SCL is HIGH creates a START or STOP condition (Figure 2). The START consists of a HIGH to LOW SDA transition, while SCL is HIGH. Absent the START, a Slave will not respond to the Master. The STOP completes all commands, and consists of a LOW to HIGH SDA transition, while SCL is HIGH.Device AddressingThe Master addresses a Slave by creating a START condition and then broadcasting an 8−bit Slave address. For the CA T24C64, the first four bits of the Slave address are set to 1010 (Ah); the next three bits, A 2, A 1 and A 0, must match the logic state of the similarly named input pins. The devices in WLCSP 4−bumps respond only to the Slave Address with A2 A1 A0 = 000 (CA T24C64C4xTR). The R/W bit tells the Slave whether the Master intends to read (1) or write (0) data (Figure 3).AcknowledgeDuring the 9th clock cycle following every byte sent to the bus, the transmitter releases the SDA line, allowing the receiver to respond. The receiver then either acknowledges (ACK) by pulling SDA LOW, or does not acknowledge (NoACK) by letting SDA stay HIGH (Figure 4). Bus timing is illustrated in Figure 5.START CONDITIONSTOP CONDITIONSDASCLFigure 2. Start/Stop TimingFigure 3. Slave Address BitsDEVICE ADDRESS** The devices in WLCSP 4−bumps respond only to the Slave Address with: A2 A1 A0 = 000, CAT24C64C4xTRFigure 4. Acknowledge TimingSCL FROM MASTERDATA OUTPUTFROM TRANSMITTERDATA OUTPUT FROM RECEIVER≥ t SU:DAT )Figure 5. Bus TimingSCLSDA INSDA OUTWRITE OPERATIONSByte WriteTo write data to memory, the Master creates a START condition on the bus and then broadcasts a Slave address with the R/W bit set to ‘0’. The Master then sends two address bytes and a data byte and concludes the session by creating a STOP condition on the bus. The Slave responds with ACK after every byte sent by the Master (Figure 6). The STOP starts the internal Write cycle, and while this operation is in progress (t WR ), the SDA output is tri −stated and the Slave does not acknowledge the Master (Figure 7).Page WriteThe Byte Write operation can be expanded to Page Write,by sending more than one data byte to the Slave before issuing the STOP condition (Figure 8). Up to 32 distinct data bytes can be loaded into the internal Page Write Buffer starting at the address provided by the Master. The page address is latched, and as long as the Master keeps sending data, the internal byte address is incremented up to the end of page, where it then wraps around (within the page). New data can therefore replace data loaded earlier. Following the STOP, data loaded during the Page Write session will be written to memory in a single internal Write cycle (t WR ).Acknowledge PollingAs soon (and as long) as internal Write is in progress, the Slave will not acknowledge the Master. This feature enables the Master to immediately follow −up with a new Read or Write request, rather than wait for the maximum specified Write time (t WR ) to elapse. Upon receiving a NoACK response from the Slave, the Master simply repeats the request until the Slave responds with ACK.Hardware Write ProtectionWith the WP pin held HIGH, the entire memory is protected against Write operations. If the WP pin is left floating or is grounded, it has no impact on the Write operation. The state of the WP pin is strobed on the last falling edge of SCL immediately preceding the 1st data byte (Figure 9). If the WP pin is HIGH during the strobe interval,the Slave will not acknowledge the data byte and the Write request will be rejected.Delivery StateThe CAT24C64 is shipped erased, i.e., all bytes are FFh.SLAVE ADDRESSSA ***C KA C KA C KS T O P PST ARTA CKBUS ACTIVITY:MASTER SLAVEADDRESS BYTE ADDRESS BYTE DAT A BYTE Figure 6. Byte Write Sequence*a 15 − a 13 are don’t care bits.a 15 − a 8a 7 − a 0d 7 − d 0Figure 7. Write Cycle TimingSTOPCONDITIONSTARTCONDITIONADDRESSSCLSDASLAVE ADDRESSSA C K A C K C K ST ARTC K S T O C KC K C K BUSACTIVITY:MASTER SLAVEADDRESS BYTE ADDRESS BYTEDATA BYTE DATA BYTE DATA BYTE Figure 8. Page Write SequenceFigure 9. WP TimingADDRESS BYTE DATA BYTESCLSDA WPREAD OPERATIONSImmediate ReadTo read data from memory, the Master creates a START condition on the bus and then broadcasts a Slave address with the R/W bit set to ‘1’. The Slave responds with ACK and starts shifting out data residing at the current address.After receiving the data, the Master responds with NoACK and terminates the session by creating a STOP condition on the bus (Figure 10). The Slave then returns to Standby mode.Selective ReadTo read data residing at a speci fic address, the selected address must first be loaded into the internal address register.This is done by starting a Byte Write sequence, whereby the Master creates a START condition, then broadcasts a Slave address with the R/W bit set to ‘0’ and then sends two address bytes to the Slave. Rather than completing the ByteWrite sequence by sending data, the Master then creates a START condition and broadcasts a Slave address with the R/W bit set to ‘1’. The Slave responds with ACK after every byte sent by the Master and then sends out data residing at the selected address. After receiving the data, the Master responds with NoACK and then terminates the session by creating a STOP condition on the bus (Figure 11).Sequential ReadIf, after receiving data sent by the Slave, the Master responds with ACK, then the Slave will continue transmitting until the Master responds with NoACK followed by STOP (Figure 12). During Sequential Read the internal byte address is automatically incremented up to the end of memory, where it then wraps around to the beginning of memory.Figure 10. Immediate Read Sequence and TimingSCL SDA 8th Bit STOPNO ACKDATA OUT89SLAVE ADDRESSSA C KDATA BYTEN OA C K S T O P PST ARTBUS ACTIVITY:MASTER SLAVEFigure 11. Selective Read SequenceSLAVE ADDRESS SA C KA C KA C K ST ARTSLAVE SA C KS T A R T PS T O P ADDRESS BYTE ADDRESS BYTE ADDRESSN O A C KDATA BYTEBUS ACTIVITY:MASTER SLAVEFigure 12. Sequential Read SequenceS T O SLAVE C KA C A C N O A C A C BYTE n BYTE n+1BYTE n+2BYTE n+xBUS ACTIVITY:MASTERSLAVEORDERING INFORMATIONDevice Order Number SpecificDeviceMarking Package Type Temperature Range Lead Finish ShippingCAT24C64WI−GT324C64F SOIC−8, JEDEC I = Industrial(−40°C to +85°C)NiPdAu Tape & Reel,3,000 Units / ReelCAT24C64YI−GT3C64F TSSOP−8I = Industrial(−40°C to +85°C)NiPdAu Tape & Reel,3,000 Units / ReelCAT24C64HU4I−GT3C6U UDFN−8I = Industrial(−40°C to +85°C)NiPdAu Tape & Reel,3,000 Units / ReelCAT24C64C4CTR A WLCSP−4with Die CoatIndustrial(−40°C to +85°C)N/A Tape & Reel,5,000 Units / ReelCAT24C64C4UTR A WLCSP−4with Die CoatIndustrial(−40°C to +85°C)N/A Tape & Reel,5,000 Units / Reel9.All packages are RoHS−compliant (Lead−free, Halogen−free).10.The standard lead finish is NiPdAu.11.For information on tape and reel specifications, including part orientation and tape sizes, please refer to our Tape and Reel PackagingSpecifications Brochure, BRD8011/D.12.Caution: The EEPROM devices delivered in WLCSP must never be exposed to ultra violet light. When exposed to ultra violet lightthe EEPROM cells lose their stored data.UDFN8, 2x3 EXTENDED PADCASE 517AZ ISSUE ADATE 23 MAR 2015SCALE 2:1NOTES:1.DIMENSIONING AND TOLERANCING PER ASME Y14.5M, 1994.2.CONTROLLING DIMENSION: MILLIMETERS.3.DIMENSION b APPLIES TO PLATEDTERMINAL AND IS MEASURED BETWEEN 0.15 AND 0.25MM FROM THE TERMINAL TIP .4.COPLANARITY APPLIES TO THE EXPOSEDPAD AS WELL AS THE TERMINALS.DIM MIN MAX MILLIMETERS A 0.450.55A10.000.05b 0.200.30D 2.00 BSC D2 1.35 1.45E 3.00 BSC E2 1.25 1.35e 0.50 BSC L 0.250.35*For additional information on our Pb −Free strategy and soldering details, please download the ON Semiconductor Soldering and Mounting Techniques Reference Manual, SOLDERRM/D.SOLDERING FOOTPRINT*DIMENSIONS: MILLIMETERSDETAIL AA30.13 REF L1DETAIL ALALTERNATE CONSTRUCTIONSLL1−−−0.15RECOMMENDEDGENERICMARKING DIAGRAM*XXXXX = Specific Device Code A = Assembly Location WL = Wafer Lot Y = YearW = Work WeekG= Pb −Free Package*This information is generic. Please refer to device data sheet for actual part marking.Pb −Free indicator, “G” or microdot “ G ”,may or may not be present.XXXXX AWLYW G18XDETAIL BALTERNATE CONSTRUCTIONSWLCSP4, 0.77x0.77CASE 567JY ISSUE CDATE 07 MAR 2017PIN A1REFERENCESCALE 4:1TOP VIEWBOTTOM VIEWDIMENSIONS: MILLIMETERS*For additional information on our Pb −Free strategy and soldering details, please download the ON Semiconductor Soldering and Mounting Techniques Reference Manual, SOLDERRM/D.SOLDERING FOOTPRINT*RECOMMENDEDNOTES:1.DIMENSIONING AND TOLERANCING PER ASME Y14.5M, 1994.2.CONTROLLING DIMENSION: MILLIMETERS.3.DATUM C, THE SEATING PLANE, IS DEFINED BY THE SPHERICAL CROWNS OF THE SOLDER BALLS.4.COPLANARITY APPLIES TO SPHERICAL CROWNS OF THE SOLDER BALLS.5.DIMENSION b IS MEASURED AT THE MAXIMUMCONTACT BALL DIAMETER PARALLEL TO DATUM C.6.BACKSIDE COATING IS OPTIONAL.DIM A MIN NOM −−−MILLIMETERS A1D E b 0.150.155e0.40 BSC−−−0.040.06A20.23 REF A30.025 REF 0.750.770.750.77MAX 0.160.350.080.790.79DETAIL ANOTE 6X = Specific Device Code Y = YearW= Work Week*This information is generic. Please refer to device data sheet for actual part marking.Pb −Free indicator, “G” or microdot “ G ”,may or may not be present.GENERICMARKING DIAGRAM*X YWWLCSP4, 0.77x0.77CASE 567PBISSUE ADATE 09 NOV 2016PIN A1REFERENCESCALE 4:1TOP VIEWBOTTOM VIEWDIMENSIONS: MILLIMETERS*For additional information on our Pb−Free strategy and solderingdetails, please download the ON Semiconductor Soldering andMounting Techniques Reference Manual, SOLDERRM/D.SOLDERING FOOTPRINT*RECOMMENDEDNOTES:1.DIMENSIONING AND TOLERANCING PER ASMEY14.5M, 1994.2.CONTROLLING DIMENSION: MILLIMETERS.3.DATUM C, THE SEATING PLANE, IS DEFINED BY THESPHERICAL CROWNS OF THE SOLDER BALLS.4.COPLANARITY APPLIES TO SPHERICAL CROWNS OFTHE SOLDER BALLS.5.DIMENSION b IS MEASURED AT THE MAXIMUMCONTACT BALL DIAMETER PARALLEL TO DATUM C.6.BACKSIDE COATING IS OPTIONAL.DIMAMIN NOM−−−MILLIMETERSA1DEb0.150.155e0.40 BSC−−−0.040.055A20.19 REFA30.025 REF0.750.770.750.77MAX0.160.300.070.790.79DETAIL ANOTE 6X= Specific Device CodeY= YearW= Work Week*This information is generic. Please refer todevice data sheet for actual part marking.Pb−Free indicator, “G” or microdot “ G”,may or may not be present.GENERICMARKING DIAGRAM*XYWSOIC −8, 150 mils CASE 751BD ISSUE ODATE 19 DEC 2008IDENTIFICATIONTOP VIEWSIDE VIEWEND VIEWNotes:(1) All dimensions are in millimeters. Angles in degrees.(2) Complies with JEDEC MS-012.SYMBOLMIN NOM MAX θA A1b cD E E1e h 0º8º0.100.330.190.254.805.803.801.27 BSC1.750.250.510.250.505.006.204.00L0.401.271.35TSSOP8, 4.4x3.0, 0.65PCASE 948AL ISSUE ADATE 20 MAY 2022qXXX = Specific Device Code Y = YearWW = Work WeekA = Assembly Location G= Pb −Free Package*This information is generic. Please refer to device data sheet for actual part marking.Pb −Free indicator, “G” or microdot “G ”, may or may not be present. Some products may not follow the Generic Marking.GENERICMARKING DIAGRAM*XXX YWW A GPUBLICATION ORDERING INFORMATIONTECHNICAL SUPPORTLITERATURE FULFILLMENT:。
24LC65 I2C EEPROM字节读写驱动程序
24LC65 I2C EEPROM字节读写驱动程序[龙啸九天] [786次] 01-3-24 下午07:54:15/*————————————————————〖说明〗24LC65 I2C EEPROM字节读写驱动程序,芯片A0-A1-A2要接VCC。
现缺页写、页读,和CRC校验程序。
以下程序经过50台验证,批量的效果有待考察。
为了安全起见,程序中很多NOP是冗余的,希望读者能进一步精简,但必须经过验证。
51晶振为11.0592MHz〖文件〗24LC65.c ﹫2001/03/23〖作者〗龙啸九天 c51@ <a href= target=_blank></a> 〖修改〗修改建议请到论坛公布 <a href= target=_blank></a> 〖版本〗V1.00A Build 0323—————————————————————*/#define SDA P0_0#define SCL P0_1/*----------------------------------------------------------------------------调用方式:write_8bit(uchar ch) ﹫2001/03/23函数说明:内函数,私有,用户不直接调用。
------------------------------------------------------------------------------*/write_8bit(uchar ch){uchar i=8;SCL=0;_nop_();_nop_();_nop_();_nop_();_nop_();while (i--){SDA=(bit)(ch&0x80);_nop_();_nop_();_nop_();_nop_();_nop_();ch<<=1;SCL=1;_nop_();_nop_();_nop_();_nop_();_nop_();SCL=0;_nop_();_nop_();_nop_();_nop_();_nop_();}_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();}/*--------------------------------------------------------------------------------调用方式:void ACK(void) ﹫2001/03/23函数说明:内函数,私有,用户不直接调用。
24Cxx I2C EEPROM字节读写驱动程序
_nop_();_nop_();_nop_();_nop_();_nop_();_nop_(); //Thd:STA
SCL=0; //START
write_8bit(0xa0 | page); //写页地址和操作方式,对于24C32-24C256,page不起作用
ACK(ห้องสมุดไป่ตู้;
if(eepromtype>IIC24C16) //如果是24C01-24C16,地址为一字节;24C32-24C256,地址为二字节
调用方式:void WriteIIC_24CXX(enum EEPROMTYPE eepromtype,unsigned int address,unsigned char ddata) ﹫2001/09/18
函数说明:对于IIC芯片24CXX,在指定地址address写入一个字节ddata
SDA=0;
_nop_();_nop_();_nop_();_nop_();_nop_();_nop_(); //Thd:STA
SCL=0; //START
write_8bit( (address<<1) | 0x01); //写页地址和操作方式
ACK();
while (i--)
{
SDA=1;
#include "reg51.h"
#include "intrins.h"
sbit SCL= P2^7;
sbit SDA= P2^6;
enum EEPROMTYPE {IIC24C01,IIC24C01A,IIC24C02,IIC24C04,IIC24C08,IIC24C16,IIC24C32,IIC24C64,IIC24C128,IIC24C256};
I2C-24CXX驱动程序(真正实用-全)
#ifndef _24cXX_H#define _24cXX_H/* Includes ----------------------------------------------------------------*/#include "stm32f10x.h"#include "value.h"//#include "stdbool.h"/* Define ------------------------------------------------------------------*//* EEPROM Addresses defines *///注:32 64 的字地址是16位2个字节如果使用32或64请简单修改驱动即可#define WC24cXX 0x00 // 器件地址写#define RC24cXX 0x01 // 器件地址读#define USE_24C08 //使用24C08#ifdef USE_24C02#define MAXSIZE24cXX 256 // 总容量Bytes //级联时请修改本参数和硬件驱动#define BLOCK_SIZE 256 // 块容量Bytes#define I2C_PAGESIZE 8 // 8个字节每页#endif#ifdef USE_24C04#define MAXSIZE24cXX 512 // 总容量Bytes //级联时请修改本参数和硬件驱动#define BLOCK_SIZE 256 // 块容量Bytes#define I2C_PAGESIZE 16 // 16个字节每页#endif#ifdef USE_24C08#define MAXSIZE24cXX 1024 // 总容量Bytes //级联时请修改本参数和硬件驱动#define BLOCK_SIZE 256 // 块容量Bytes#define I2C_PAGESIZE 16 // 16个字节每页/* user define */#define YBCV_ADDR_0 0x0000 //定义仪表控制数据结构体的EEPROM 存储地址0#define YBCV_ADDR_1 0x0200 //定义仪表控制数据结构体的EEPROM存储地址1#define EEPROM_VERIFY YB_CTRL_V ALE_SIZE //EEPROM仪表通道修正参数存储地址#endif#ifdef USE_24C16#define MAXSIZE24cXX 2048 // 总容量Bytes#define I2C_PAGESIZE 16 // 16个字节每页#endif#ifdef USE_24C32#define MAXSIZE24cXX 4096 // 总容量Bytes //级联时请修改本参数和硬件驱动#define BLOCK_SIZE 4096 // 块容量Bytes#define I2C_PAGESIZE 32 // 16个字节每页#endif#ifdef USE_24C64#define MAXSIZE24cXX 8192 // 总容量Bytes //级联时请修改本参数和硬件驱动#define BLOCK_SIZE 8192 // 块容量Bytes#define I2C_PAGESIZE 32 // 16个字节每页#endif#define I2CInit I2C_GPIO_Config#define SCL(a) if (a) \GPIO_SetBits(GPIOB, GPIO_Pin_10);\else \GPIO_ResetBits(GPIOB,GPIO_Pin_10)#define SDA(a) if (a) \GPIO_SetBits(GPIOB, GPIO_Pin_11);\else \GPIO_ResetBits(GPIOB,GPIO_Pin_11)#define SCLO GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_10)#define SDAO GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_11)/* Private ------------------------------------------------------------------*//* Public -------------------------------------------------------------------*//*uint idata ucSendBuffer[8]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};uint idata ucReceData;uint idata ucReceiveBuffer[8];//从器件中读出的多字节数据暂存区*//* Function Declaration -----------------------------------------------------*/extern bool I2C2_Init(void);//I2C初始化//extern bool I2C_ByteWrite(u8* pBuffer, u8 WriteAddr); //向24cXX中写入1个字节extern bool I2C_PageWrite(u8* pBuffer, u8 BlockCode, u16 WriteAddr, u8 n); //24cXX页写(不超过一页)extern bool I2C_BlockWrite(u8* pBlock, u8 BlockCode, u16 WriteAddr, u16 n); //24cXX数据块写(不超过BLOCK_SIZE个字节)extern bool I2C_BufferWrite(u8* pBuffer, u16 WriteAddr, u16 n); //24cXX数据写(不超过MAXSIZE24cXX个字节)extern bool I2C_BufferRead(u8* pBuffer, u16 ReadAddr, u16 n); //从24cXX中读出N字节数据(不超过MAXSIZE24cXX个字节)//extern void I2C_EE_WaitEepromStandbyState(void); //等待24CXX内部写周期结束#endif /*_24cXX_H*//******************** (C) COPYRIGHT 2015 XXXXX *********************************** 文件名:24cXX.c* 描述:本函数是xx项目的24cXX的读写函数* 平台:Keil 4 MDK \ stm32 3.5.0库* 库版本:基于野火相关资料及程序上优化修改* 作者:天涯月下红颜醉**********************************************************************************/ /* Includes ------------------------------------------------------------------*/#include "24cXX.h"#include "value.h"#include "systick.h"#include <stdlib.h>/** 函数名:I2C2_Init* 描述:I2C2初始化* 输入:无* 输出:无* 调用:内部调用*/bool I2C2_Init(void){bool s = true;GPIO_InitTypeDef GPIO_InitStructure;/* 使能与I2CGPIO 有关的时钟*/RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);/* PB10-I2C2_SCL、PB11-I2C2_SDA*/GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD; // 普通开漏输出GPIO_Init(GPIOB, &GPIO_InitStructure);SDA(1);SCL(1);Delay_nop();Delay_nop();if(!SDAO) s = false;if(!SCLO) s = false;SDA(0);Delay_nop();Delay_nop();if(SDAO) s = false;SCL(0);Delay_nop();SDA(0);SCL(0);Delay_nop();Delay_nop();if(SDAO) s = false;if(SCLO) s = false;SCL(1);Delay_nop();Delay_nop();SDA(1);return s;}/********开启24cXX的I2C总线********/static bool I2CStart(void){SDA(1);SCL(1);Delay_nop();Delay_nop();if(!SDAO)return false; //SDA线为低电平则总线忙,退出SDA(0);Delay_nop();Delay_nop();if(SDAO)return false; //SDA线为高电平则总线出错,退出SCL(0);Delay_nop();return true;}/********关闭24cXX的I2C总线*******/static void I2CStop(void){SDA(0);SCL(0);Delay_nop();Delay_nop();SCL(1);Delay_nop();Delay_nop();SDA(1);}/*********发送ACK*********/static void I2CAck(void){SDA(0);SCL(0);Delay_nop();// Delay_nop();SCL(1);Delay_nop();// Delay_nop();SCL(0);}/*********发送NO ACK*********/static void I2CNoAck(void){SDA(1);SCL(0);Delay_nop();// Delay_nop();SCL(1);Delay_nop();// Delay_nop();SCL(0);}/*********读取ACK信号*********/static bool I2CWaitAck(void) //返回为:1=有ACK,0=无ACK {SCL(0);SDA(1); //设置SDA为输入Delay_nop();// Delay_nop();SCL(1);Delay_nop();// Delay_nop();if(SDAO){SCL(0);return false;}SCL(0);return true;}/************MCU向24cXX发送一个字节数据*************/ static void I2CSendByte(u8 demand) //数据从高位到低位//{u8 i=8;while(i--){SCL(0);Delay_nop();SDA((bool)(demand&0x80));demand<<=1;Delay_nop();// Delay_nop();SCL(1);Delay_nop();// Delay_nop();}SCL(0);}/*********MCU从24cXX读入一字节数据*********/static u8 I2CReceiveByte(void) //数据从高位到低位//{u8 i=8;u8 ddata=0;SDA(1); //设置SDA为输入while(i--){ddata<<=1; //数据从高位开始读取SCL(0);Delay_nop();// Delay_nop();SCL(1);Delay_nop(); //从高位开始ddata|=SDA;ddata<<=1// Delay_nop();if(SDAO){ddata|=0x01;}}SCL(0);return ddata;}/** 函数名:I2C_EE_WaitEepromStandbyState* 描述:Wait for EEPROM Standby state* 输入:无* 输出:无* 返回:无* 调用:*/static void I2C_EE_WaitEepromStandbyState(u8 BlockCode){int i = 50;do{Delay_us(100);I2CStart();I2CSendByte(BlockCode | WC24cXX);//发送器件地址写}while(I2CWaitAck() == 0 && i-- > 0);I2CStop();}/****************向24cXX中写入1个字节****************//*static bool I2C_ByteWrite(u8* pBuffer, u8 WriteAddr){I2CStart();//启动I2CI2CSendByte(WC24cXX);//发送器件地址写if(I2CWaitAck() == 0)return false;I2CSendByte(WriteAddr);if(I2CWaitAck() == 0)return false;I2CSendByte(*pBuffer);if(I2CWaitAck() == 0)return false;I2CStop();return true;}*//** 函数名:I2C_PageWrite* 描述:在EEPROM的一个写循环中可以写多个字节,但一次写入的字节数* 不能超过EEPROM页的大小。
24LC64
P13 0x2000
INT8U LC64Read(INT16U Address, INT8U* pData, INT16U Length); INT8U LC64Write(INT16U Address;
#endif
//发送读命令 Start(); rslt &= SndByte( 0xa1 | pag); //长度超过 1 个字节? if( Length>1 ) {
for(i=0; i<Length-1; i++) {
*(pData++) = RcvByte( TRUE ); } }
//获取最后一个字节的数据 *pData = RcvByte( FALSE ); Stop();
SDA = 1; SCL = 1; Delay( PLUSEWIDTH ); SDA = 0; Delay( PLUSEWIDTH ); SCL = 0; }
/*====================================================== 功能描述: I2C 停止条件 参数: 无 返回: 无 ======================================================*/ void Stop() {
char i; INT8U tmp=0; INT8U ret=0;
//释放 SDA 线 SDA = 1; //顺序读取一个字节的数据 //按从高到低的位序拼成一个字节 for(i=0; i<=7; i++) {
SCL = 0; Delay( PLUSEWIDTH ); SCL = 1; Delay( PLUSEWIDTH ); tmp = SDA; ret <<= 1; ret |= tmp; } SCL = 0; //发送应答位? if( IsAck ) SDA = 0; else
24C64 (64千位8192 × 8位串行CMOS EEPROM的,I2C同步2线总线)
EEPROM ARRAY PAGE LATCHES
YDEC
SENSE AMP R/W CONTROL
Bad
I2C is a trademark of Philips Corporation.
*24xx64 is used in this document as a generic part number for the 24AA64/24LC64/24C64 devices.
High level input voltage Low level input voltage Hysteresis of Schmitt Trigger inputs (SDA, SCL pins) Low level output voltage Input leakage current
VIH VIL VHYS
A0, A1, A2, WP = VSS
FIGURE 1-1: BUS TIMING DATA
TF
SCL
SDA IN
TSU:STA
THD:STA TSP
TLOW
SDA OUT
THIGH THD:DAT
TAA
VHYS
TO
TBUF
WP
(protected)
TSU:WP
THD:WP
• Schmitt trigger inputs for noise suppression
• 1,000,000 erase/write cycles guaranteed
• Electrostatic discharge protection > 4000V
• Data retention > 200 years
• Self-timed ERASE/WRITE cycle
I2C设备驱动介绍
I2C设备驱动介绍I2C(Inter-Integrated Circuit)是一种串行通信协议,用于连接并使多个外部设备与主控制器进行通信。
在嵌入式系统中,I2C设备驱动起着至关重要的作用,负责将操作系统与I2C总线上的设备进行通信,促进数据的传输和交互。
1.初始化:驱动程序需要初始化I2C控制器,包括设置时钟频率、地址范围等。
2.设备注册:设备驱动需要在操作系统中注册I2C设备,以便操作系统能够识别和管理设备。
3.读写操作:驱动程序需要实现读写设备寄存器的功能,包括发送开始和停止信号、以及发送、接收数据等。
4.错误处理:驱动程序需要处理I2C通信过程中可能出现的错误,例如传输失败、设备无响应等情况。
5.中断处理:驱动程序需要支持I2C设备的中断机制,以便及时处理设备的状态变化或数据传输完成的中断信号。
6.电源管理:驱动程序需要支持设备的电源管理功能,包括设备的唤醒、睡眠等操作。
7.设备控制:驱动程序需要实现设备特定的控制功能,例如设置传感器的采样率、配置设备的工作模式等。
8. 虚拟文件系统接口:在Linux系统中,驱动程序通常通过虚拟文件系统接口(如/dev)与用户空间进行交互,提供读写设备寄存器的功能。
1.确定设备:首先,开发者应该确定需要驱动的I2C设备。
这可能包括传感器、EEPROM、显示器等。
2.确定硬件连接:确定I2C设备与主控制器之间的硬件连接和电气特性。
这包括设备的I2C地址、I2C总线上的物理接口等。
3.编写驱动程序:在操作系统中,开发者可以根据设备的文档或芯片厂商提供的驱动程序框架,编写自己的I2C设备驱动程序。
驱动程序需要实现上述提到的功能,并且根据设备的特点进行相应的适配和优化。
4.编译和测试:完成驱动程序的编写后,需要将其编译成与操作系统内核匹配的模块或静态链接库。
然后,通过加载驱动模块或重新编译内核来使驱动程序生效。
最后,进行测试,确保驱动程序在各种场景下的正常运行。
AT24c1024 LPC23XX驱动 i2c
void I2CSendByte(unsigned char ch)//写一个字节数据
{
unsigned char Byte_count=8;
SDA_out;
while(Byte_count--)
{
FIO0CLR=SD2401_SCL;
I2CWait(50);
//延时大约8uS
//sramadd_lo:每块内的EE字节地址,
//sramdata:数据
unsigned char I2CReadEEram(unsigned char page,unsigned int sramadd_lo)
{
unsigned char ddata=0;
I2CStart();
if(page==0)I2CSendByte(0xA0);
unsigned char Byte_count=8; unsigned char ddata=0; SDA_in;
第2页
AT24c1024 LPC23XX驱动
FIO0SET=SD2401_SDA;
while (Byte_count--)
{
ddata<<=1;
FIO0CLR=SD2401_SCL;
I2CWait(50);
//延时大约8uS
FIO0SET=SD2401_SCL;
I2CWait(50);
//延时大约8uS
if(FIO0PIN&SD2401_SDA)ddata=ddata|1;
}
FIO0CLR=SD2401_SCL;
return ddata;
}
//page:00:选择块0,01:选择块1,
i2c驱动程序总结
i2c驱动程序总结I2C驱动程序总结由于6410没有合适的i2c参考驱动,本总结主要基于TQ2440的AT24C02⼀、TQ2440电路⼆、I2c驱动程序分析1写⼊⼝函数at24cxx_init()在⼊⼝函数中主要有⼀个增加设备驱动的函数i2c_add_driver(),该函数会调⽤i2c_register_driver(THIS_MODULE, 驱动名字)完成注册。
2写出⼝函数at24cxx_exit()在出⼝函数⾥主要有⼀个删除设备驱动的函数i2c_del_driver(),这个函数功能有从设备驱动链表中删除驱动,卸载注册的驱动等3修饰⼊⼝函数和出⼝函数module_init(at24cxx_init); 这样,使⽤insmod命令加载驱动模块时,⼊⼝函数at24cxx_init()就会被调⽤module_exit(at24cxx_exit); 这样,使⽤rmmod命令加载驱动模块时,⼊⼝函数at24cxx_exit()就会被调⽤4写I2C驱动主要是:分配⼀个i2c_driver结构体设置填充i2c_driver结构体注册(前⾯1、2、3步)staticstruct i2c_driver at24cxx_driver={.driver = {.name = “at24cxx”,}.attach_adapter = at24cxx_attach,.detach_client = at24cxx_detach};函数at24cxx_attach()和at24cxx_detach需要⾃⼰构造5构造at24cxx_attach()函数和at24cxx_detach()函数Static int at24cxx_attach(struct i2c_adapter *adapter){return i2c_probe(adapter,&addr_data,at24cxx_detect);}I2c_probe函数主要是通过适配器adapter发送结构体addr_data的地址,这个地址就是i2c设备的地址,需要⾃⼰根据硬件原理图定义的,如果收到回应,就是说有这个i2c设备,就调⽤at24cxx_detect处理,这个函数需要⾃⼰去构造的。
芯片24C64中文资料
芯片24C64中文资料I2C总线I2C总线〔Inter Integrated Circuit外部集成电路总线〕是两线式串行总线,仅需求时钟和数据两根线就可以停止数据传输,仅需求占用微处置器的2个IO引脚,运用时十分方便。
I2C总线还可以在同一总线上挂多个器件,每个器件可以有自己的器件地址,读写操作时需求先发送器件地址,该地址的器件失掉确认后便执行相应的操作,而在同一总线上的其它器件不做照应,称之为器件寻址,这个原理就像我们打的原理相当。
I2C总线发生80年代,由PHLIPS公司开发,早期多用于音频和视频设备,如今I2C总线的器件和设备已多不胜数。
最罕见的采用I2C总线的EEPROM也已被普遍运用于各种家电、工业及通讯设备中,主要用于保管设备所需求的配置数据、采集数据及顺序等。
消费I2C总线EEPROM的厂商很多,如ATMEL、Microchip公司,它们都是以24来扫尾命名芯片型号,最常用就是24C 系列。
24C系列从24C01到24C512,C前面的数字代表该型号的芯片有多少K的存储位。
如ATMEL的24C64,存储位是64K位,也就是说可以存储8K〔8192〕字节,它支持1.8V 到5V电源,可以擦写1百万次,数据可以坚持100年,运用5V电源时时钟可以到达400KHz,并且有多种封装可供选择。
我们可以很容易的在身边的电器设备中发现它们的身影,如电视中用于保管频道信息,电脑内存条中保管内存大小等相关信息,汽车里用于保管里程信息等等。
图一就是ATMEL24C64芯片的PID封装和用于内存条SPD(Serial Presence Detect)上的24芯片。
图1图2图二是ATMEL公司24C64的引脚定义图。
A0-A2用于设置芯片的器件地址,在同一总线上有多个器件时,可以经过设置A0-A2引脚来确定器件地址。
SDA是串行数据引脚,用于在芯片读写时输入或输入数据、地址等,这个引脚是双向引脚,它是漏极开路的,运用时需求加上一个上拉电阻。
I2C EEPROM系列手册24LC64
2005 Microchip Technology Inc.
DS21930A_CN 第 3 页
24AAXX/24LCXX/24FCXX
2.0 电气特性
绝对最大额定值 (†)
VCC .............................................................................................................................................................................6.5V 相对于 Vss 的所有输入和输出 ............................................................................................................ -0.6V 到 VCC +1.0V 存储温度 ................................................................................................................................................. -65°C 到 +150°C 环境温度 (使用电源时) ........................................................................................................................ -40°C 到 +125°C 所有引脚静电保护 ....................................................................................................................................................................≥ 4 kV
(完整word版)24C02I2C驱动程序(详细全)
/*---------------------------------------24C02.h-----------------------------------*/ #ifndef _24C02_H#define _24C02_H/* Includes ----------------------------------------------------------------*/#include "STC15F2K60S2.h"#include "stdbool.h"/* Define ------------------------------------------------------------------*/#define WC24C02 0xa0//器件地址写#define RC24C02 0xa1//器件地址读#define MAXSIZE24C02 256//AT24C02最多256个字节2K bits 32页#define I2C_PAGESIZE 8//AT24C02每页有8个字节#define delayNOP() _nop_();_nop_();_nop_();_nop_() //延时sbit SDA = P2^5;//定义数据线sbit SCL = P2^6;//定义时钟线/* Private ------------------------------------------------------------------*//* Public -------------------------------------------------------------------*/uint idata ucSendBuffer[8]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};uint idata ucReceData;uint idata ucReceiveBuffer[8];//从器件中读出的多字节数据暂存区/* Function Declaration -----------------------------------------------------*/ bool I2CStart(void);//启动I2Cvoid I2CStop(void);//停止I2Cvoid I2CAck(void);//应答信号void I2CNoAck(void);//发送非应答信号bool I2CWaitAck(void);//检测应答位void I2CSendByte(u8 demand);//发送一字节数据u8 I2CReceiveByte(void);//接收一字节数据//extern bool I2C_ByteWrite(u8* pBuffer, u8 WriteAddr); //向24c02中写入1个字节extern bool I2C_PageWrite(u8* pBuffer, u8 WriteAddr, u8 n); //24c02页写(不超过一页)extern bool I2C_BufferWrite(u8* pBuffer, u8 WriteAddr, u16 n); //24c02数据块写(不超过256个字节)extern bool I2C_BufferRead(u8* pBuffer, u8 ReadAddr, u16 n); //从24C02中读出N字节数据(不超过256个字节)#endif/*----------------------------------------------end file-----------------------------------------------*//*---------------------------------------------24C02.c------------------------------------------------*//******************** (C) COPYRIGHT 2014 xxxx *********************************** 文件名:24c02.c* 描述:本函数是xxxxx的24C02的读写函数注:器件地址0xa0 数据地址:00H-FFH 2K bits 256Byte* 平台:Keil 4 A51* 库版本:使用了宏晶科技的相关资料及程序\ STM库3.50 I2C程序* 作者:xxxxxx* 时间:2014.9.3******************************************************************************* ***//* Includes ------------------------------------------------------------------*/#include "24c02.h"/********开启24c02的I2C总线********/bool I2CStart(void){SDA=1;SCL=1;delayNOP();delayNOP();if(!SDA)return false; //SDA线为低电平则总线忙,退出SDA=0;delayNOP();delayNOP();while(SDA)return false; //SDA线为高电平则总线出错,退出SCL=0;delayNOP();return true;}/********关闭24c02的I2C总线*******/ void I2CStop(void){SDA=0;SCL=0;delayNOP();delayNOP();SCL=1;delayNOP();delayNOP();SDA=1;}/*********发送ACK*********/void I2CAck(void){SDA=0;SCL=0;delayNOP();// delayNOP();SCL=1;delayNOP();// delayNOP();SCL=0;}/*********发送NO ACK*********/void I2CNoAck(void){SDA=1;SCL=0;delayNOP();// delayNOP();SCL=1;delayNOP();// delayNOP();SCL=0;}/*********读取ACK信号*********/bool I2CWaitAck(void) //返回为:1=有ACK,0=无ACK{SCL=0;SDA=1; //设置SDA为输入delayNOP();// delayNOP();SCL=1;delayNOP();// delayNOP();if(SDA){SCL=0;return false;}SCL=0;return true;}/************MCU向24c02发送一个字节数据*************/ void I2CSendByte(u8 demand) //数据从高位到低位//{u8 i=8;while(i--){SCL=0;_nop_();SDA=(bool)(demand&0x80);demand<<=1;delayNOP();// delayNOP();SCL=1;delayNOP();// delayNOP();}SCL=0;}/*********MCU从24c02读入一字节数据*********/u8 I2CReceiveByte(void) //数据从高位到低位//{u8 i=8;u8 ddata=0;SDA=1; //设置SDA为输入while(i--){ddata<<=1; //数据从高位开始读取SCL=0;delayNOP();// delayNOP();SCL=1;delayNOP(); //从高位开始ddata|=SDA;ddata<<=1// delayNOP();if(SDA){ddata|=0x01;}}SCL=0;return ddata;}/****************向24c02中写入1个字节****************//*bool I2C_ByteWrite(u8* pBuffer, u8 WriteAddr){I2CStart();//启动I2CI2CSendByte(WC24C02);//发送器件地址写if(I2CWaitAck() == 0)return false;I2CSendByte(WriteAddr);if(I2CWaitAck() == 0)return false;I2CSendByte(*pBuffer);if(I2CWaitAck() == 0)return false;I2CStop();return true;}*//** 函数名:I2C_PageWrite* 描述:在EEPROM的一个写循环中可以写多个字节,但一次写入的字节数* 不能超过EEPROM页的大小。
如何对AT24C02编写驱动程序——IIC总线协议
如何对AT24C02编写驱动程序——IIC总线协议AT24C02是一种2Kbit(256字节)的串行EEPROM芯片,采用I2C总线协议进行通信。
编写AT24C02的驱动程序需要了解I2C总线协议的工作原理以及AT24C02的读写操作。
以下是编写AT24C02驱动程序的步骤:1. 硬件配置:首先,需要在单片机上配置I2C总线的硬件连接。
I2C 总线需要两根信号线,即SDA(Serial Data Line)和SCL(Serial Clock Line)。
将SDA和SCL引脚连接到AT24C02的对应引脚,并通过上拉电阻将其拉高。
2.初始化I2C总线:在驱动程序中,需要初始化I2C总线的相关寄存器和配置参数。
这包括设置I2C总线的通信速率、使能I2C模块、使能中断等。
3.开始信号和设备地址:发送开始信号START,然后发送AT24C02的设备地址,设备地址由3位固定的值和一个读/写位组成。
读写位为0代表写操作,为1代表读操作。
4.发送数据:如果是写操作,发送要写入的数据到AT24C02的指定地址。
数据写入时,需要注意AT24C02的内存地址范围,以及页写操作的限制。
如果是读操作,发送读取的目标地址。
5.停止信号:传输完成后,发送停止信号STOP,结束通信。
6.延时和轮询:在I2C总线通信中,需要一定的延时等待数据传输完成。
在写入大量数据或读取数据时,还需要轮询等待操作完成。
7.错误处理:在驱动程序中,需要考虑到可能发生的错误和异常情况。
例如,设备地址未响应、通信超时、数据传输错误等,都需要进行相应的错误处理。
8.封装函数接口:为了方便上层应用调用,可以将上述操作封装成函数接口。
例如,提供读写函数、擦除函数和查询设备ID的函数等。
除了以上的驱动程序,还可以根据实际需求进行功能扩展。
例如,可以实现批量写入数据、随机读取数据、擦除操作等。
总之,编写AT24C02的驱动程序主要包括硬件配置、初始化I2C总线、发送开始信号和设备地址、发送数据、发送停止信号、延时和轮询、错误处理等步骤。
I2C总线式存储器24C0X系列读写程序模块
/*****************************************************************头文件名VIIC_C51.H这个头文件对应的库是VIIC_C51.LIB,库中有几个模拟I2C的函数,加入此文件即可使用I2C平台(主方式的软件平台),函数是对LPC764的I2C的I/O口实现,即其P1.3 (SDA) , P1.2(SCL),51系列机型可以通用.注意: 函数是采用软件延时的方法产生SCL脉冲,固对高晶振频率要作一定的修改....(本例是1us机器周期,即晶振频率要小于12MHZ).(函数的使用可参考给出的事例程序.)*****************************************************************/#ifdef uchar#define READYDEF 1 /*宏uchar已定义*/#else#define uchar unsigned char#endif/*******************************************************************无子地址发送字节数据函数功能: 从启动总线到发送地址,数据,结束总线的全过程,从器件地址sla.如果返回1表示操作成功,否则操作有误。
********************************************************************/ extern bit ISendByte(uchar sla,uchar c);/*******************************************************************有子地址发送多字节数据函数功能: 从启动总线到发送地址,子地址,数据,结束总线的全过程,从器件地址sla,子地址suba,发送内容是s指向的内容,发送no个字节。
I2C接口的EEPROM 24C64芯片的驱动方法
I2C接口的EEPROM24C64芯片的驱动方法与93C46类似的,24C64也是EEPROM,但不同的是24C64是I2C接口的,容量也要更大些,用来存储较大容量的数据,甚至在某些单片机中可以用作程序存储器。
24C64提供65536个位,它们是以字节方式进行组织的。
通过设置不同的地址,可以实现多达8个芯片共享两线总线。
它被广泛应用于工业、化工等需要低功耗与低电压的领域。
同时,它还提供诸如4.5V~5.5V、2.7V~5.5V、2.5V~5.5V与1.8V~5.5V各种工作电压范围的芯片,从而使其应用更加通用。
24C64的引脚定义:引脚功能详细描述:24C64的功能框图:引脚功能描述:串行时钟(SCL):在SCL的上升沿数据写入芯片中,在下降沿从芯片中读出数据。
串行数据(SDA):SDA用作双向数据传输。
这个引脚是漏极开路驱动,需要加上拉电阻。
设备地址(A2,A1,A0):A2~A0是设备地址设置引脚,可以通过接高或接低来设置不同的地址,也可以直接悬空。
设置为不同地址时最多可以在同一总线上存在多达8个芯片。
当这些引脚悬空时,默认地址为0。
写保护(WP):当此引脚接到GND上时,允许正常的写操作。
当WP接到V CC时,所有的写操作都是被禁止的。
如果悬空,则WP在内部被拉到GND。
24C64的组织方式:24C64在内部被组织为256个页,每个页32个字节。
可以按字节来进行操作,地址为13位。
24C64的操作方法:24C64是采用I2C接口来进行数据传输的,在这里不再介绍I2C接口数据传输的相关内容,具体的I2C总线协议在相关章节有详细讲解,敬请翻阅。
下面只针对于24C64的操作方法进行讲解。
1)设备寻址在开始条件使芯片使能后,需要给其写入一个8位的设备地址码,以使某一芯片被命中。
在地址码的开头有两个“10”序列,共4位,然后是3位的地址,最后是1位的读写标识位。
具体的地址码结构如下:24C64使用3个设备地址位A2、A1、A0使多达8个芯片同时存在于一条总线上。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
if(I2C_dat_t < I2C_SOP_NUM) {
I2C->DATA = *I2C_ptr ++; /* ??? */
I2C->CON.STA = 0; /* I2C */
I2C->CON.STO = 1; /* I2C */
I2C_end = 1;
}
I2C_dat_t ++;
}
}
}
else if(Device_addr == 0xa6)
{
I2C->CON.STO = 0; /* I2C */
}
else {
I2C->DATA = *I2C_ptr ++; /* ??? */
I2C->CON.STA = 0; /* I2C */
}
break;
case 0x58: /*receive a data and back a ACK bit */
*I2C_ptr = I2C->DATA ;
I2C->CON.STA = 0; /* I2C */
I2C->CON.STO = 1; /* I2C */
I2C->CON.STO = 0; /* I2C */
break;
case 0x18: /*?????????? ACK ? */
case 0x28: /*?????????? ACK ? */
I2C_f_t ++;
if(Device_addr == 0xa0)
SYS->IPRSTC2.I2C_RST = 0; /* I2C ?? ???? */
I2C->CON.ENSI = 1; /* I2C ????? */
I2C->CLK = PCLK/(4*I2C_CLK) - 1; /* I2C ??? */
I2C->CON.EI = 1; /* I2C ????? */
*I2C_ptr ++ = I2C->DATA ;
I2C->CON.AA = 0; /* ?????? */
I2C->CON.STA = 0; /* I2C */
I2C->CON.STO = 0; /* I2C */
if(I2C_SOP_NUM > 1)
I2C->CON.AA = 1; /* ?????? */
else
I2C->CON.AA = 0; /* ?????? */
I2C->CON.STA = 0; /* I2C */
NVIC->ISER[0] = (1 << ((uint32_t)(I2C0_IRQn) & 0x1F)); /* enable interrupt */
NVIC_SetPriority(I2C0_IRQn, 6) ;
I2C->TOC.DIV4 = 1; /* ?????????4 */
case 0x48: /* ???SLA+R,?????? */
I2C->CON.STA = 0; /* I2C */
I2C->CON.STO = 0; /* I2C */
break;
default:
I2C->CON.STA = 0; /* I2C */
/*******************************××*****************************************************************************/
/* led controller for M051 series */
I2C->CON.STO = 0; /* I2C */
}
else {
I2C->DATA = *I2C_ptr ++; /* ??? */
I2C->CON.STA = 0; /* I2C */
/************************************************************************************************************××*/
#include "I2C.H"
#include "M05X_header.h"
I2C->CON.STO = 1; /* I2C */
I2C_end = 1;
}
I2C_dat_t ++;
}
}
}
break;
case 0x40: /*SLA+R has been transmitted */
I2C->CON.STO = 0; /* I2C */
break;
}
}
I2C->CON.SI = 1; /* I2C */
}
void init_I2C(void) {
SYS -> P3_MFP.MFP4_T0_SDA = 0;
SYS -> P3_MFP.MFP5_T1_SCL = 0;
I2C_end = 1;
break;
case 0x20: /* ???SLA+W,?????? */
case 0x30: /* ???I2DAT????,?????? */
case 0x38: /* ?SLA +R/W?????????? */
{
if(I2C_buf_t == 2) {
I2C->DATA = I2C_address/256; /* ??? */
I2C->CON.STA = 0; /* I2C */
I2C->CON.STO = 0; /* I2C */
// I2C->TOC.ENTI = 1; /* ??????/?? */
}
void I2C_START(uint8 sum_dat) {
I2C_buf_t = 0;
I2C_dat_t = 0;
}
else {
*I2C_ptr ++ = I2C->DATA ;
I2C->CON.AA = 1; /* ?????? */
I2C->CON.STA = 0; /* I2C */
I2C->CON.STO = 0; /* I2C */
volatile uint8 read_or_send ;
volatile uint8 *I2C_ptr ;
volatile uint8 Device_addr ;
void I2C0_IRQHandler(void)
{
uint32 status;
status = I2C->STATUS;
}
break;
case 0x10: /*A repeated START has been transmitted. */
I2C->DATA = Device_addr | I2C_read ; /* ??? */
I2C->CON.STA = 0; /* I2C */
else {
if(I2C_dat_t < I2C_SOP_NUM) {
I2C->DATA = *I2C_ptr ++; /* ??? */
I2C->CON.STA = 0; /* I2C */
#define PCLK (48000000UL)
volatile uint8 I2C_buf_t;
volatile uint16 I2C_address ;
volatile uint8 I2C_dat_t ;
volatile uint8 I2C_SOP_NUM;
volatile uint8 I2C_end ;
if (I2C->TOC.TIF)
{
I2C->TOC.TIF = 1; /* Clear TIF */
I2C_end = 2;
}
else
{
switch (status)
{
case 0x08: /* START has been transmitted */
I2C_buf_t ++;
if(I2C_buf_t == 1) {
I2C->DATA = Device_addr | I2C_write; /* ??? */
I2C->CON.STA = 0; /* I2C */
I2C->CON.STO = 0; /* I2C */
I2C->CON.STO = 0; /* I2C */
break;
case 0x50: /*receive a data and a ACK bit */
I2C_dat_t ++;
if(I2C_dat_t >= I2C_SOP_NUM) { /* I2C???????? */
}
else {
if(read_or_send == 1) {
I2C->CON.STA = 1; /* I2C ????? */
I2C->CON.STO = 0; /* I2C */
}
SYS -> P3_MFP.ALT4_T0_SDA = 1;