This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Interfacing I2C EEPROMs

I want to write some bytes of data on EEPROMs, and later retrieve the data using at89s51/52.
How I2C communication can be established to do this task?
I need the C help for generating timing signals, writing to eeprom and reading from eeprom for interfacing 24C02 with at89s52.

Parents
  • I mistakenly re-posted because I'm discussing for first in this site.
    WELL I WAS NOT SHOUTING!
    and here is my code, I found similar type of code in a site and edited in my way and tried to save the data from a port and send the saved the data to other port. But not working...# simulated in ISIS proteus 7.1...

    #include <reg52.h>
    #include<intrins.h>         //to use no operation
    #define data P2
    sbit scl=P1^3;
    sbit sda=P1^4;
    bit ack;
    void delay(unsigned char n)  // delay function approx. for about 1ms
            {
            unsigned char i;
            TMOD=0x01;
            for(i=0; i<=n; i++)
                            {
                            TH0 = 0xFC;
                            TL0 = 0x18;
                            TR0 = 1;
                            while(TF0==0);
                            TR0 = 0;
                            TF0 = 0;
                            }
            }
    void aknowledge()         //acknowledge condition
    {
            scl=1;
            _nop_();
            _nop_();
            scl=0;
    }
    void start()            //start condition
    {
            sda=1;
            scl=1;
            _nop_();         //No operation  provides a very small delay
            _nop_();
            sda=0;
            scl=0;
    }
    void stop()                     //stop condition
    {
            sda=0;
            scl=1;
            _nop_();
            _nop_();
            sda=1;
            scl=1;
    }
    void send_byte(unsigned char value)     //send byte serially
    {
            unsigned int i;
            unsigned char send;
            send=value;
            for(i=0;i<8;i++)
            {
                    sda=send/128;                   //extracting MSB
                    send=send<<1;                     //shiftng left
                    scl=1;
                    _nop_();
                    _nop_();
                    scl=0;
            }
       ack=sda;                                     //reading acknowledge
       sda=0;
    }
    unsigned char read_byte()                       //reading from EEPROM serially
    {
            unsigned int i,reead=0;
            sda=1;
            for(i=0;i<8;i++)
            {
                    reead=reead<<1;
                    scl=1;
                    _nop_();
                    _nop_();
                    if(sda==1)
                            reead++;
                    scl=0;
            }
            sda=0;
            return reead;                           //Returns 8 bit data here
    }
    void save(unsigned char num)                                    //save in EEPROM
    {
            start();
            send_byte(0xA0);                                                //device address
            aknowledge();
            send_byte(0x00);                                                //word address
            aknowledge();
            send_byte(num);                                                 //send data
            aknowledge();
            stop();
    }
    unsigned char read(void)
    {
            unsigned char i;
            start();
            send_byte(0xA0);
            aknowledge();
            send_byte(0x00);
            aknowledge();
            start();
            i=read_byte();
            aknowledge();
            stop();
            aknowledge();
            return i;
    }
    void main()
    {
    while (1)
            {
             save(data);       // save the value at Port 2
             delay(10);
             P3=read();                // Send the saved value at Port 3
             delay(10);
            }
    }
    

Reply
  • I mistakenly re-posted because I'm discussing for first in this site.
    WELL I WAS NOT SHOUTING!
    and here is my code, I found similar type of code in a site and edited in my way and tried to save the data from a port and send the saved the data to other port. But not working...# simulated in ISIS proteus 7.1...

    #include <reg52.h>
    #include<intrins.h>         //to use no operation
    #define data P2
    sbit scl=P1^3;
    sbit sda=P1^4;
    bit ack;
    void delay(unsigned char n)  // delay function approx. for about 1ms
            {
            unsigned char i;
            TMOD=0x01;
            for(i=0; i<=n; i++)
                            {
                            TH0 = 0xFC;
                            TL0 = 0x18;
                            TR0 = 1;
                            while(TF0==0);
                            TR0 = 0;
                            TF0 = 0;
                            }
            }
    void aknowledge()         //acknowledge condition
    {
            scl=1;
            _nop_();
            _nop_();
            scl=0;
    }
    void start()            //start condition
    {
            sda=1;
            scl=1;
            _nop_();         //No operation  provides a very small delay
            _nop_();
            sda=0;
            scl=0;
    }
    void stop()                     //stop condition
    {
            sda=0;
            scl=1;
            _nop_();
            _nop_();
            sda=1;
            scl=1;
    }
    void send_byte(unsigned char value)     //send byte serially
    {
            unsigned int i;
            unsigned char send;
            send=value;
            for(i=0;i<8;i++)
            {
                    sda=send/128;                   //extracting MSB
                    send=send<<1;                     //shiftng left
                    scl=1;
                    _nop_();
                    _nop_();
                    scl=0;
            }
       ack=sda;                                     //reading acknowledge
       sda=0;
    }
    unsigned char read_byte()                       //reading from EEPROM serially
    {
            unsigned int i,reead=0;
            sda=1;
            for(i=0;i<8;i++)
            {
                    reead=reead<<1;
                    scl=1;
                    _nop_();
                    _nop_();
                    if(sda==1)
                            reead++;
                    scl=0;
            }
            sda=0;
            return reead;                           //Returns 8 bit data here
    }
    void save(unsigned char num)                                    //save in EEPROM
    {
            start();
            send_byte(0xA0);                                                //device address
            aknowledge();
            send_byte(0x00);                                                //word address
            aknowledge();
            send_byte(num);                                                 //send data
            aknowledge();
            stop();
    }
    unsigned char read(void)
    {
            unsigned char i;
            start();
            send_byte(0xA0);
            aknowledge();
            send_byte(0x00);
            aknowledge();
            start();
            i=read_byte();
            aknowledge();
            stop();
            aknowledge();
            return i;
    }
    void main()
    {
    while (1)
            {
             save(data);       // save the value at Port 2
             delay(10);
             P3=read();                // Send the saved value at Port 3
             delay(10);
            }
    }
    

Children