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

Program to write and read a byte between P89V51RD2 and ST M24C64

Hello All,

I am finding it really hard to perform write and read operations on the EEPROM connected to the MCU by two wires using the I2C Protocol.

I've read the data sheets, written the code exactly matching the datasheet info, but it was of no avail.

Please help me out.

My code looks something like this

void Write_Start(void)
        {
                E2P_SDA = 1;
                E2P_SCL = 1;
                delay_i2c();
                E2P_SDA = 0;
                delay_i2c();
                E2P_SCL = 0;
                delay_i2c();
        }

void Write_to_E2P(void)
        {
                unsigned char DEV_SEL_CODE = 0x0A0;
                unsigned char ADDR_MSB = 0x50;
                unsigned char ADDR_LSB = 0x05;
                unsigned char i;

                Write_Start();

                for(i=7;i>=0;i--)
                        {
                                E2P_SDA = DEV_SEL_CODE^i;
                                E2P_SCL = 0;
                                delay_i2c();
                                E2P_SCL = 1;
                                delay_i2c();
                        }

                E2P_SDA = 1;
                E2P_SCL = 0;
                delay_i2c();
                E2P_SCL = 1;
                delay_i2c();
                delay_i2c();
                E2P_SCL = 0;
                delay_i2c();

                if(E2P_SDA == 0)
                        LED1=1;

                for(i=7;i>=0;i--)
                        {
                                E2P_SDA = ADDR_MSB^i;
                                E2P_SCL = 0;
                                delay_i2c();
                                E2P_SCL = 1;
                                delay_i2c();
                        }

                E2P_SDA = 1;
                E2P_SCL = 0;
                delay_i2c();
                E2P_SCL = 1;
                delay_i2c();
                delay_i2c();
                E2P_SCL = 0;
                delay_i2c();

                if(E2P_SDA == 0)
                        LED2=1;

                for(i=7;i>=0;i--)
                        {
                                E2P_SDA = ADDR_LSB^i;
                                E2P_SCL = 0;
                                delay_i2c();
                                E2P_SCL = 1;
                                delay_i2c();
                        }

                E2P_SDA = 1;
                E2P_SCL = 0;
                delay_i2c();
                E2P_SCL = 1;
                delay_i2c();
                delay_i2c();
                E2P_SCL = 0;
                delay_i2c();

                if(E2P_SDA == 0)
                        LED3=1;

                for(i=7;i>=0;i--)
                        {
                                E2P_SDA = current_channel^i;
                                E2P_SCL = 0;
                                delay_i2c();
                                E2P_SCL = 1;
                                delay_i2c();
                        }

                E2P_SDA = 1;
                E2P_SCL = 0;
                delay_i2c();
                E2P_SCL = 1;
                delay_i2c();
                delay_i2c();
                E2P_SCL = 0;
                delay_i2c();

                if(E2P_SDA == 0)
                        LED4=1;


        }

Parents Reply Children
  • why on earth use that chip.

    I do wish forums could filter the I wouldn't start from there style answers.

  • But many "I wouldn't start from there" do bring forward good information.

    In this case: It is normally better to use a controller with I2C than to implement it in software. And today, there is no correlation between controller price and the availability of a I2C controller.

    Another interesting thing is the answer we got:
    "i am using a DIP Package. My board is designed for that."

    Quite a number of 8051 chips are available in a DIP package. Quite a number of development boards with 40-pin DIP sockets are intended for use with quite a number of different 8051 chips, as long as care is taken with supply voltages, crystal frequency and similar.

    A much better reason for not considering alternatives would have been: "The controller is soledred on my development board, and I don't have the equipment to replace it with another, and can't afford buying another development board."

    Another good reason for staying with bit-banging would have been: "My assignment is to implement a software-only solution, to prove that I understand the protocol."

  • P89C66x is available in DIP

    Erik

  • I do wish forums could filter the I wouldn't start from there style answers.

    if someone post I am trying to shoot an elephan with a BB gun, what would your answer be?

    eRIK

  • if someone post I am trying to shoot an elephan with a BB gun, what would your answer be?

    It certainly wouldn't be "You're an idiot! Why did you choose to go to Africa? You should have chosen Belgium instead".

  • Your post was the first containing the word "idiot". Return back to the previous posts, and read them again.

    Then return back with a list of the amount of bad advice you found.

  • Your post was the first containing the word "idiot". Return back to the previous posts, and read them again.

    I was fully aware of that!

    I'm directly expressing the tone of what was originally implied.

  • I do wish forums could filter the I wouldn't start from there style answers

    But why do you think this is a less worthy contribution? What not to do is sometimes a good guideline (try this: "don't shoot elephants"). Overly touchy, Jenit?

  • But why do you think this is a less worthy contribution? What not to do is sometimes a good guideline (try this: "don't shoot elephants"). Overly touchy, Jenit?

    You're somehow continuing to miss the point, which is not a comment on the merit of the contribution but the pig-ignorant tone with which it was presented. Jenit probably hasn't been reading this forum for long enough to realise that a number of the regular contributors suffer from varying degrees of ignorance and/or delusion.