In this project “Interfacing external EEPROM with PIC Microcontroller”, we will see how we can easily interface EEPROM via I2C Protocol. The need of external EEPROM as a permanent storage of data in any project is enhanced. So now question how to interface external EEPROM with PIC Microcontroller?

Project description:

In this project “Interfacing external EEPROM with PIC Microcontroller”, I used FM24C64Interfacing external EEPROM with PIC Microcontroller (EEPROM) and UART Port to receive data which have to be store. For interfacing EEPROM with PIC , see in figure that we have to connect SDA (Serial Data) pin of EEPROM with SDA pin of PIC Microcontroller and as well as SCL(Serial Clock) pin of EEPROM with SCL pin of PIC Microcontroller. Data from microcontroller is being send serially and store accordingly with given address. So for storing data to EEPROM we should send the address first to store the data. The communication is done between microcontroller and EEPROM through I2C communication protocol.

I2C Protocol:

i2c

To Know “Interfacing external EEPROM with PIC Microcontroller”, we have to know at least the basic of I2C Protocol. In I2C Protocol all devices  are connected parallaly as a slave with I2C bus see the bellow figure.

I2C Device addressing:

I2C Device addressing:

Every device connected as a slave have specified 7 bit or 10 bit address. For this project I use FM24C64 and it also has specified address. The spacified address for FM24C84 is

 1 0 1 0 a0 a1 a2 R/W = 10100000 (A0H for Write as per above circuit connection).

                                    = 10100001 (A1H for Read as per above circuit connection).

 I2C Protocol to write data at slave:

As we know in I2C communication data is being send serially. So it definite has some steps/protocol to write data in slave. In bellow you will find those steps for communicate with FM24C64 in Mikroc pro for PIC.

I2C1_Init(100000);                       // initialize I2C communication

I2C1_Start();                                 // issue I2C start signal

I2C1_Wr(0xA0);                          // send byte via I2C  (device address + W)

I2C1_Wr(Address1);                // send byte (address of EEPROM location)

I2C1_Wr(Address2);                // send byte (address of EEPROM location)

I2C1_Wr(Data);                         // send data (data to be written)

I2C1_Stop();                               // issue I2C stop signal

 See the bellow block diagram of that. 

I2C Protocol to write data at slave:

  I2C Protocol to read data at slave:

As like write protocol in i2c has specified protocol for read data from slave also. In bellow you will find those steps for communicate with FM24C64 in Mikroc pro for PIC.

   I2C1_Start();                                 // issue I2C start signal

  I2C1_Wr(0xA0);                          // send byte via I2C  (device address + W)

  I2C1_Wr(address0);                // send byte (data address0)

  I2C1_Wr(address1);                // send byte (data address1)

  I2C1_Repeated_Start();       // issue I2C signal repeated start

  I2C1_Wr(0xA1);                     // send byte (device address + R)

  Take = I2C1_Rd(0);             // Read the data (NO acknowledge)

  I2C1_Stop();                          // issue I2C stop signal


 See the bellow block diagram of that.

 I2C Protocol to read data at slave:    

  Now for my project  making more flexible and interesting I used UART port to getting data to 

Interfacing external EEPROM with PIC Microcontroller

be store in EEPROM that means through UART port you can attach Keyboard and store the data as you want. For getting knowledge on How to interface UART port with PIC Micrcotroller? See my previous post

Interfacing Proteus with Matlab

See the circuit diagram of my complete project Interfacing external EEPROM with PIC Microcontroller where I take input from UART port then store it to EEPROM and read the data from EEPROM and finally display it through LED attached with port B.

 

See bellow the complete C code in Mikroc for PIC of project Interfacing external EEPROM with PIC Microcontroller.

Embedded C Code
// Name : Interfacing external EEPROM with PIC Microcontroller
// Author : Subham Dutta
// Date : 21-02-14
// Website : www.nbcafe.in

unsigned int uart_rd;

void main() {
ansel=0;
anselh=0;

PORTB = 0;
TRISB = 0; // Configure PORTB as output
UART1_Init(9600); // Initialize UART module at 9600 bps
Delay_ms(100);
while(1)
{
if (UART1_Data_Ready()) { // If data is received,
uart_rd = UART1_Read();
UART1_Write(uart_rd); // read the received data,
}
I2C1_Init(100000); // initialize I2C communication
I2C1_Start(); // issue I2C start signal
I2C1_Wr(0xA0); // send byte via I2C (device address + W)
I2C1_Wr(0); // send byte (address of EEPROM location)
I2C1_Wr(1); // send byte (address of EEPROM location)
I2C1_Wr(uart_rd); // send data (data to be written)
I2C1_Stop(); // issue I2C stop signal

Delay_100ms();

I2C1_Start(); // issue I2C start signal
I2C1_Wr(0xA0); // send byte via I2C (device address + W)
I2C1_Wr(0); // send byte (data address)
I2C1_Wr(1); // send byte (address of EEPROM location)
I2C1_Repeated_Start(); // issue I2C signal repeated start
I2C1_Wr(0xA1); // send byte (device address + R)
PORTB = I2C1_Rd(0); // Read the data (NO acknowledge)
I2C1_Stop(); // issue I2C stop signal
}
}

See the simulation video how it simulate in Proteus