How to Interface I2C-EEPROM with 8051 Microcontroller The term I2C or IIC abbreviation is an inter integrated circuit and it is called as I squared C. I2C is a serial computer bus, which is invented by NXP semiconductors previously it is named as Philips semiconductors. The I2C bus is used to attach low speed peripheral integrated circuits to microcontrollers and processors. In the year 2006, to implement the I2C protocol no licensing fee is necessary. But fee is necessary to get I2C slave address assigned by NXP semiconductors. Some competitors like Texas Instruments, Siemens AG, NEC, Motorola, Intersil and STMicroelectronics have announced well-suited I²C products to the market in the mid 1990s. In the year 1995, SMBus is defined by Intel, that is a subgroup of I²C that states the protocols are more strict. The main purpose of SMBus is to support interoperability and robustness. Therefore, current I²C systems include rules and policies from SMBus, sometimes it supports both I2C and SMBus with minimal reconfiguration. I2C Bus Interface I2C Bus-EEPROM with 8051 Microcontroller What is I2C Bus I2c bus uses two bidirectional open-drain lines such as SDA (serial data line) and SCl (serial clock line) and these are pulled up with resistors. I2C bus permits a master device to start communication with a slave device. Data is interchanged between these two devices. Typical voltages used are +3.3V or +5V although systems with extra voltages are allowed. I2C Interface EEPROM Electrically Erasable Programmable ROM (EEPROM) is a user modifiable ROM which can be removed and reprogrammed frequently through the application of higher than the normal electrical voltage. An EEPROM is a kind of non-volatile memory used in electronic devices like computers to store small quantities of data that should be saved when power is detached. 8051 Slicker Board The 8051 Slicker board is specially designed to help technical students in the area of embedded systems. This kit is designed in such way that all the features of 8051 microcontroller will be possibly used by the students. This striker board supports ISP (In System Programming) that is done via the serial port. This kit and 8051 from NXP is proposed to smooth the progress of debugging of many designs surrounding of speed 8- bit microcontrollers. Interfacing I2C – EEPROM The following figure shows interfacing I2C-EEPROM with 8051 microcontroller. Here, I2C is a master- slave protocol, that includes the data along with clock pulse. Typically, the master device switched the clock line, SCL. This line orders the data timing which transfers on the I2C bus.Unless the clock is operated, no data will be transferred. All slaves are controlled by the same clock, SCL. Interfacing I2C – EEPROM I2C bus supports the various devices where each device is identified by a unique address whether it is an LCD driver, memory card, microcontroller or interfacing of keyboard which can operate as Tx or Rx depends on the functioning of the device. The controller is designed to control the EEPROM device via I2C protocol. Here, he I2C protocol works as a master device and regulates EEPROM and it works as a slave. The R/W operations are proficient by transferring a set of control signals comprising the address AND/ OR data bus. These signals should be attended with suitable clock signals Interface I2C Bus-EEPROM with 8051 Microcontroller If you want to read, Write and Erase EEPROM by using I2C bus in 8051 striker board. Interfacing of I2 Bus-EEPROM with 8051 microcontroller is very simple. The operation of this interfacing is to send a signal like WRITE, followed by data and address bus. In this operation, the EEPROM is used to store the data. In 8051 kit, two numbers of EEPROM lines are regulated by I2C supported drivers. The SCL and SDA are connected to the I2C based serial EEPROM IC. Interface I2C Bus-EEPROM with 8051 Microcontroller By using SDA and SCL I2C lines, the read and write operations of EEPROM are done in 8051 Slicker Kit The interfacing of I2C is so simple and in every single data Read/Write in EEPROM. The delay depends on compiler how it enhances the loops as soon as you make changes in the choices the delay varies. Source Code for I2C Interfacing #include<reg51.h> #include<stdio.h> #include<intrins.h> #define ACK 1 #define NO_ACK 0 unsigned char i; unsigned char EData[5]; unsigned char Data; void InitSerial(void); void DelayMs(unsigned int); void WriteI2C(unsigned char); void Start(void); void Stop(void); void ReadBYTE(unsigned int); void WriteBYTE(unsigned int); unsigned char ReadI2C(bit); sbit SCL = P2^0; // connect to SCL pin (Clock) sbit SDA = P2^1; // connect to SDA pin (Data) //————————————— // Main program //————————————— void main(void) { InitSerial(); // Initialize serial port putchar(0x0C); // clear hyper terminal DelayMs(5); WriteBYTE(0x0000); WriteI2C(‘A’); //Write Data’s Here WriteI2C(‘B’); WriteI2C(‘C’); WriteI2C(‘D’); WriteI2C(‘E’); WriteI2C(‘F’); Stop(); DelayMs(10); ReadBYTE(0x0000); EData[0] = ReadI2C(NO_ACK); EData[1] = ReadI2C(NO_ACK); EData[2] = ReadI2C(NO_ACK); EData[3] = ReadI2C(NO_ACK); EData[4] = ReadI2C(NO_ACK); EData[5] = ReadI2C(NO_ACK); for(i=0;i<6;i++) { printf(“value = %c\n”,EData[i]); // display data */ DelayMs(100); } while(1); } //————————————— // Initialize serial port //————————————— void InitSerial(void) { SCON = 0x52; // setup serial port control TMOD = 0x20; // hardware (9600 BAUD @11.0592MHZ) TH1 = 0xFD; // TH1 TR1 = 1; // Timer 1 on } //——————————- // start I2C //——————————- void Start(void) { SDA = 1; SCL = 1; _nop_();_nop_(); SDA = 0; _nop_();_nop_(); SCL = 0; _nop_();_nop_(); } //——————————- // stop I2C //——————————- void Stop(void) { SDA = 0; _nop_();_nop_(); SCL = 1; _nop_();_nop_(); SDA = 1; } //——————————- // Write I2C //——————————- void WriteI2C(unsigned char Data) { for (i=0;i<8;i++) { SDA = (Data & 0x80) ? 1:0; SCL=1;SCL=0; Data<<=1; } SCL = 1; _nop_();_nop_(); SCL = 0; } //——————————- // Read I2C //——————————- unsigned char ReadI2C(bit ACK_Bit) { Start(); WriteI2C(0xA1); SDA = 1; for (i=0;i<8;i++) { SCL = 1; Data<<= 1; Data = (Data | SDA); SCL = 0; _nop_(); } if (ACK_Bit == 1) SDA = 0; // Send ACK else SDA = 1; // Send NO ACK _nop_();_nop_(); SCL = 1; _nop_();_nop_(); SCL = 0; Stop(); return Data; } //——————————- // Read 1 byte form I2C //——————————- void ReadBYTE(unsigned int Addr) { Start(); WriteI2C(0xA0); WriteI2C((unsigned char)(Addr>>8)&0xFF); WriteI2C((unsigned char)Addr&0xFF); } //——————————- // Write 1 byte to I2C //——————————- void WriteBYTE(unsigned int Addr) { Start(); WriteI2C(0xA0); WriteI2C((unsigned char)(Addr>>8)&0xFF); // send address high WriteI2C((unsigned char)Addr&0xFF); // send address low } //————————————— // Delay mS function //————————————— void DelayMs(unsigned int count) { // mSec Delay 11.0592 Mhz unsigned int i; // Keil v7.5a while(count) { i = 115; while(i>0) i–; count–; } } Thus, this is all about the implementation of I2C interface. We hope that you have got a better understanding of this concept. Furthermore, any queries regarding this concept or interfacing devices please give your valuable suggestions by commenting in the comment section below. Share This Post: Facebook Twitter Google+ LinkedIn Pinterest Post navigation ‹ Previous Steps to Fix a Cyclic Redundancy Check ErrorNext › White Paper on Single Phase Induction Motor Related Content Kogge Stone Adder : Circuit, Working, Advantages, Disadvantages & Its Applications Brent Kung Adder : Circuit, Working, Advantages, Disadvantages & Its Applications Inverting Summing Amplifier : Circuit, Working, Derivation, Transfer Function & Its Applications Active Band Pass Filter : Circuit, Types, Frequency Response, Q Factor, Advantages & Its Applications Comments are closed.