Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Two-Wire Peripheral Expansion for the AT89C2051 Microcontrol

Status
Not open for further replies.

Help

Advanced Member level 2
Advanced Member level 2
Joined
Feb 15, 2005
Messages
617
Helped
7
Reputation
14
Reaction score
3
Trophy points
1,298
Activity points
7,065
at89c2051 sample

Hi,

Anyone can help/guide me how to use Two-Wire Protocol (I2C). I already had understood the basic I2C working. So how am i to start from basic. I hope to control ADC, IOExpanded, RTC, EEPROM, RAM module.

Please help me from basic because i also in beginner state!!!

Thank You
 

Re: Two-Wire Peripheral Expansion for the AT89C2051 Microcon

The easiest way of learnig is to work with examples ..
Here you will find detailed description, including 8050-code, on how to interface 24CXX memory with 8051-derivative:

**broken link removed**

This article covers the specific hardware description and software routines required to interface the MAX7651 and MAX7652 12-bit data acquisition system to the 24C02 2-wire serial EEPROM. Detailed software code is provided.
Since the MAX7651/52 is based on a standard 8051 processor core the information presented here is useful to any standard 8051-based design.

The AT89C2051 doesn't have "proper" I2C interface so you can use any 2 general purpose I/O pins ..
Connecting other divices via the I2C bus will be just as simple as it is described in the above example, but you will need to use devices' specific addresses to read/write data to and from them ..

Regards,
IanP
 

    Help

    Points: 2
    Helpful Answer Positive Rating
Re: Two-Wire Peripheral Expansion for the AT89C2051 Microcon

Hi,

It is there provide any C code for us!! I am not familiar with assambly code! Without using the MAX7651 ic I can learn it easly!! I already design some of the function that i posted. So, what can i do???

Thank you
 

Re: Two-Wire Peripheral Expansion for the AT89C2051 Microcon

From your point of view you may treat MAXXX51 as 8051 .. After all you are not interested in its features but in its 8051-core ..
Anyhow, check out examples in:
"I2C for Raisonance 8051 C compiler"
at:
http://www.oceanwaveconsulting.com/TaylorRiver/I2C/

Basic use of these routines
There are 4 basic functions in my I2C implenentation
bit I2C_Start(void)
bit I2C_Send_Byte(unsigned char)
unsigned char I2C_Get_Byte(bit)
bit I2C_Stop(void)

Regards,
IanP
 

    Help

    Points: 2
    Helpful Answer Positive Rating
Re: Two-Wire Peripheral Expansion for the AT89C2051 Microcon

Hi,

So, temporary i dont have this MAXXX51 ic. Can i use 8051 interface to my 24c02 eeprom? I think you already give me the sample on that. I will try and make it work, further more i will coming back....

Thank you very much...
 

Re: Two-Wire Peripheral Expansion for the AT89C2051 Microcon

Don't worry about that MAX chip .. Use any 8051 µC ..
That was used just as an example, although the code itself could be good for both ..

Btw, in this 24CXX EEPROM you may have A0, A1 and A2 = 0 ..

Regards,
IanP
 

    Help

    Points: 2
    Helpful Answer Positive Rating
Re: Two-Wire Peripheral Expansion for the AT89C2051 Microcon

Btw, in this 24CXX EEPROM you may have A0, A1 and A2 = 0 ..

Grade thank to your remind!!! I will try to understand and change the coding. Thank you very much...

Regard,
Help

Normally what's the data we will store inside the eeprom?
 

Re: Two-Wire Peripheral Expansion for the AT89C2051 Microcon

Most likely configuration setup of a system, look-up tables which may require updates, data that was logged from external sensors etc. etc ..

Regards,
IanP
 

    Help

    Points: 2
    Helpful Answer Positive Rating
Re: Two-Wire Peripheral Expansion for the AT89C2051 Microcon

Hi,

Now i playing and try to understand the code but... why i can't compile the sample program!!! It comeout alot of error!!! Can you please check for me???

Thank
 

Re: Two-Wire Peripheral Expansion for the AT89C2051 Microcon

What's the function doing?? I2C_NOP(); ???
 

Re: Two-Wire Peripheral Expansion for the AT89C2051 Microcon

I2C_NOP(); I would say it will be doing something similar to NOP in 8051 which is do nothing for one machine cycle, in other words a short delay ..

Regards,
IanP
 

    Help

    Points: 2
    Helpful Answer Positive Rating
Re: Two-Wire Peripheral Expansion for the AT89C2051 Microcon

Code:
unsigned char I2C_Get_Byte(bit ack)
  {
  unsigned char index;  // bit position counter 0x80 -> 0x40 -> ... -> 0x01
  unsigned char X;      // value being read from HW to return to caller


  I2C_DIO = 1;   // set for a read (transmit)
  X       = 0;
  for(index = 0x80; index != 0; index >>= 1)     // MSB first
    {
    I2C_NOP();
    I2C_CLK = 1; 
    if (I2C_DIO)
      X |= index;
    I2C_CLK = 0;
    }
 
  I2C_DIO = ack;    // ACK (0) or NACK (1) bit
  I2C_NOP();
  I2C_CLK = 1;
  I2C_NOP();
  I2C_CLK = 0;
      
  return(X);     
  }

What does for loop doing? What are X doing?? It is after finish for loop the X = 11111111B and what does it mean if(I2C_DIO) since I2C_DIO already set by 1?
 

Re: Two-Wire Peripheral Expansion for the AT89C2051 Microcon

Bear in mind that in 8051 writing a "1" to a pin has two meanings: setting a "1" or setting this pin as input. Here this operation has the latter meaning ..
The for loop is bit-banging the I2C device .. As you can see the CLK is going up and down and the DIO pin reads bits from the I2C SDA (data) line ..
If you need more explanations on Bit-Banging I2C take a look at:
http://www.keil.com/i2c/examples.asp
and, if you are interested in really understanding IIC, may I suggest the IIC "class"
**broken link removed**

Regards,
IanP
 

    Help

    Points: 2
    Helpful Answer Positive Rating
Re: Two-Wire Peripheral Expansion for the AT89C2051 Microcon

Q1) Can be explain in this way???

if (I2C_DIO) //receiver sending data to transmitter receive either Hi/Lo
// if the receiver got sending data than is true...

X |= index; // then copy the receiver data to X


Q2) The last part for I2C

Code:
bit I2C_Generate_Stop(void)	
  {
    unsigned char retry;   // don't want to be here for ever, this is a retry counter

  [color=red]retry = 9;[/color]

  I2C_DIO = 1;
  while (retry--)
    if (!I2C_DIO)              // while the data line is low
      {                        // continue to pulse the clock
	  I2C_CLK = 1;			   // if DIO(SDA) = 0 then the CLK(SCL) alway running High-Low High-Low
      I2C_NOP();
      I2C_CLK = 0;
      }
    else  
      {                       // when the data line actually is high
      I2C_DIO = 0;            // we can now execute a valid STOP
      I2C_NOP();
      I2C_CLK = 1;
      I2C_NOP();
      I2C_DIO = 1;
      return(TRUE);
      }

  I2C_CLK = 1;
  return (FALSE);
  }

Since the STOP is control by Master why we still need to check I2C_DIO TRUE or FALSE, if(!I2C_DIO)??
Why retry 9 time??
 

Re: Two-Wire Peripheral Expansion for the AT89C2051 Microcon

The number retry=9 is arbitrary, and can be 2, 5 or 10 ..
As the STOP is defined as a LOW to HIGH transition on the SDA pin while the
SCL pin is held HIGH, and if this condition is fullfiled for the first time there will be no further retries ..
In many situations, especially in circuits with one master and one slave, you will not test the SDA pin at all and just issue the STOP:
Code:
{
    sda_low();
    scl_high();
    sda_high();
}

Regards,
IanP
 

    Help

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top