Share on facebook
Share on twitter
Share on linkedin
Share on whatsapp

Interfacing external EEPROM with PIC Microcontroller

Here I come with new project that is “ Interfacing external EEPROM with PIC Microcontroller ”. We will see in this project that how we can easily interface EEPROM via I2C Protocol. Now a days need of external EEPROM as a permanent storage of data in any project, is enhanced. So now question is how to interface external EEPROM with PIC Microcontroller?

Project description:

So come to the project description of my 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 we have to connect 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:

We know in I2C communication data is being send serially. So it definite has some steps or protocol to write data in slave. In bellow you will find those steps or protocol 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:    

  Lets do some thing interesting  making my project more flexible and interesting, I used UART port to getting data to be store in EEPROM. That means through UART port we can attach Keyboard and store the data as we want. For that you should have proper knowledge on How to interface UART port with PIC Micrcotroller? So I come with solution see my previous post Interfacing Proteus with Matlab and get the knowledge.

Here I shown the circuit diagram of my complete project Interfacing external EEPROM with PIC Microcontroller in bellow. 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.

Interfacing external EEPROM with PIC Microcontroller

 

See bellow the complete C code for my project.

“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 

Not Enough, Need More

E-Mail Subscription





E-Mail Subscription





Table of Contents
Subham Dutta

Subham Dutta

Hi myself Subham Dutta, having 15+ years experience in filed of Engineering. I love to teach and try to build foundation of students. Try to make them imagine what they learn.

Need more this type of content in your E-Mail?



NBCAFE