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.

Urgent!!! I2C communication between two 89s52

Status
Not open for further replies.

balaece07

Newbie level 2
Joined
Oct 4, 2008
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,365
Urgent!!!

HI EVERYONE,
BALA Here.I am trying to communicate TWO 89s52 Microcontroller Using I2C..I tried So many Times....But Didnt get the output..

Here I am Including My code..Pls find the mistake and Help me..

Tahnks in Advance

code:

#include<AT898252.h>
#include<intrins.h>
unsigned char readI2c(bit ACK_Bit);
void writei2c(unsigned char W_Byte) ;
void writemc(unsigned char addr, unsigned char data1);
void readmc(unsigned char addr);
sbit SDA = P0^1; // connect to SDA pin (Data)
sbit SCL = P0^0; // connect to SCL pin (Clock)
delay();
void main()
{
writemc(0x24,0x55);
readmc(0x24);
}
//-------------------------------
// start I2C
//-------------------------------
void Start(void)
{
SDA = 1;
SCL = 1;
_nop_();_nop_();
SDA = 0;
_nop_();_nop_();
SCL = 0;
_nop_();_nop_();
}

//-------------------------------
// stop I2C
//-------------------------------
void Stop(void)
{
SDA = 0;
_nop_();_nop_();
SCL = 1;
_nop_();_nop_();
SDA = 1;
}
//-------------------------------
// Write I2C
//-------------------------------
void writei2c(unsigned char Data)
{
unsigned char i;
for (i=0;i<8;i++)
{
SDA = (Data & 0x80) ? 1:0;
SCL=1;

SCL=0;
Data<<=1;
delay();
}

SCL = 1;
_nop_();_nop_();
SCL = 0;

}

//-------------------------------
// Read I2C
//-------------------------------
unsigned char readI2c(bit ACK_Bit)
{

unsigned char Data=0;
unsigned char i;
SDA = 1;
for (i=0;i<8;i++)
{
SCL = 1;
Data<<= 1;
Data = (Data | SDA);

SCL = 0;
_nop_();
delay();


}

if (ACK_Bit == 1)
SDA = 0; // Send ACK
else
SDA = 1; // Send NO ACK

_nop_();_nop_();
SCL = 1;
_nop_();_nop_();
SCL = 0;

return Data;
}

void writemc(unsigned char addr, unsigned char data1)
{
Start();
writei2c(0xC0);
writei2c(addr);
writei2c(data1);
Stop();
}
void readmc(unsigned char addr1)

{
unsigned char rdata;

Start();
writei2c(0xC0);
writei2c(addr1);
Start();
writei2c(0xC1);
rdata=readI2c();
Stop();
P2=rdata;

}
delay() /*One Second Delay*/
{

T2MOD=0x03;
TL2=0xFC;
TH2=0xFE;
TR2=1;
while(TF2!=1);
TR2=0;
TF2=0;

}
 

Re: Urgent!!!

HI

As far as I remember the 8952 doesn't have hardware IC slave interface.

There for it will be most difficult or close to imposable to write a software slave I2C interface due to complicated trimming requirement for the slave

Only fast controller (like the STM32 or PIC24 or PIC32 or AVR ) can emulate software I2C slave

All the best

Bobi

The microcontroller specialist
 

well, it could be done with interrupts... using both of them...
so should choose wich one will be the master, and whic one will be the slave...

having both of the as master/slave could be very difficult (the arbitration stuff and so...)
 

Hi,

If you have SPI protocol inbuilt in your microcontroller than it will work as a Master & Slave.
Just check for that.

Regards
Chanchal
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top