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.

How to use I2C on AT89C51?

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
Hi,

May i know the function I2C on AT89C51 is which pin? Is it Pin16 Port3.6 and Pin17 Port3.7? Anyone can tell me.....

Thanks....
 

pullup resister of 89c51

AT89C51 does not have I2C bus, so there are no dedicated pins for SCL and SDA.
Other members of the 8051-family with I2C interface use P1.6 as SCL (clock) and P1.7 as SDA (data)..
Regards,
IanP
 

    Help

    Points: 2
    Helpful Answer Positive Rating
89c5131 i2c

Help said:
Hi,

May i know the function I2C on AT89C51 is which pin? Is it Pin16 Port3.6 and Pin17 Port3.7? Anyone can tell me.....

Thanks....

AT89C51 is not having I2C capability. Some of its 8051 clones have that.

If you are using I2C on AT89C51, you have to use bitbang mechanism (software)to use I2C.

means, general two purpose IO pins will be connected as SDA and SCLK. You can find application notes in philips/atmel/keil website.


Here is the sample code
**broken link removed**

Cheers
 

i2c 89c51

Hi idlebrain,

Please can you show me the link and sample design circuit of connection?

Thanks...
 

89c51 sda pin no

SCK BIT P3.6 ;I2C的时钟线
SDA BIT P3.7 ;I2C的数据线
;读写I2C总线器件要用到的寄存器
ERRFLAG BIT 00H
TEMP1 EQU 1AH
DELAYCOUNT EQU 1BH
ADDREHI EQU 1CH ;读写的地址
ADDRELO EQU 1DH
WRITE_DATA EQU 1EH ;单字节写入的数据
READ_DATA EQU 1FH ;单字节读出的数据
WRITE_BYTE: LCALL STARTI2C
JB ERRFLAG,WRITE_B_RE ;不是空闲返回
MOV A,#0A0H
LCALL SHOUT_DATA
JB ERRFLAG,WRITE_B_STOP ;出错停止
; MOV A,ADDREHI ;送高位地址
; LCALL SHOUT_DATA
; JB ERRFLAG,WRITE_B_STOP
MOV A,ADDRELO ;送低位地址
LCALL SHOUT_DATA
JB ERRFLAG,WRITE_B_STOP
MOV A,WRITE_DATA
LCALL SHOUT_DATA
JB ERRFLAG,WRITE_B_STOP
CLR ERRFLAG ;正常清出错位
WRITE_B_STOP: LCALL STOPI2C
MOV DELAYCOUNT,#0AH
LCALL DELAY
WRITE_B_RE: RET
READ_BYTE: LCALL STARTI2C
JB ERRFLAG,READ_RE
MOV A,#0A0H
LCALL SHOUT_DATA
JB ERRFLAG,READ_STOP
; MOV A,ADDREHI
; LCALL SHOUT_DATA
; JB ERRFLAG,READ_STOP
MOV A,ADDRELO
LCALL SHOUT_DATA
JB ERRFLAG,READ_STOP
LCALL READ_CURRENT
LJMP READ_RE
READ_STOP: LCALL STOPI2C
READ_RE: RET
READ_CURRENT: LCALL STARTI2C
JB ERRFLAG,RE_CURRENTRE
MOV A,#0A1H
LCALL SHOUT_DATA
JB ERRFLAG,RE_CURRENTST
LCALL SHIN_DATA
LCALL NAK
CLR ERRFLAG
RE_CURRENTST: LCALL STOPI2C
RE_CURRENTRE: RET



SHOUT_DATA: MOV R6,#08H
SHOUT_DATA1: RLC A
MOV SDA,C
NOP
SETB SCK
NOP
NOP
NOP
NOP
CLR SCK
DJNZ R6,SHOUT_DATA1
SETB SDA
NOP
NOP
SETB SCK
NOP
NOP
NOP
NOP
MOV C,SDA
MOV ERRFLAG,C
CLR SCK
RET


SHIN_DATA: SETB SDA
MOV R6,#08H
SHIN_DATA1: NOP
NOP
NOP
SETB SCK
NOP
NOP
MOV C,SDA
RLC A
NOP
CLR SCK
DJNZ R6,SHIN_DATA1
MOV READ_DATA,A
RET





STARTI2C: SETB SDA
SETB SCK
NOP
JNB SDA,STARTI2C_ERR
JNB SCK,STARTI2C_ERR
NOP
CLR SDA
NOP
NOP
NOP
NOP
CLR SCK
CLR ERRFLAG
LJMP STARTI2C_RE
STARTI2C_ERR: SETB ERRFLAG
STARTI2C_RE: RET




STOPI2C: CLR SDA
NOP
NOP
SETB SCK
NOP
NOP
NOP
NOP
SETB SDA
RET

ACK: CLR SDA
NOP
NOP
SETB SCK
NOP
NOP
NOP
NOP
CLR SCK
RET

NAK: SETB SDA
NOP
NOP
SETB SCK
NOP
NOP
NOP
NOP
CLR SCK
RET
END
 
i2c at89c

peace upon you

using software sent from philips but you should put pull up resistor in the two pins (10 KΩ) to the 5volt.
 

89c2051 i2c

Hi
ordinary 89C51 does not have I2C bus so you should yourself make its protocol
you can see my tries on i2c eeprom in C code.
viva Persia
Bye
 

interface i2c with 89c51

Hi,

Do you design the eeprom circuit? Is it you using this 24LC02 chip as your eeprom...

Thanks...
 

i2c 89c51 controller

ordinary 89c51 has not 12C bus
ful detailed pin descrpition chek the data sheet
u will grt the ans
regards
HaIdEr
 

can i connect i2c with 89c51

Hi help,

You simply connect any two io pins to SDA and SCL of EEPROM. You need to connect pullup resistor for SDA pin. check the following sentence in datasheet.

"SDA bus requires a pullup resistor to VCC (typical 4.7K for 100KHZ, 1K for 400KHZ)"

Connect A2/A1/A0 to VCC or GND(VSS) as per the addressing requirements. These three pins corresponds 3,2,1 bits of the address byte. Bit 0 being the read/write control

If you want control write protect connect to another micro pin, if not simply connect to ground.

Use the software with start/stop conditions and ACK mechanism.

One more point to add is you can read/write 8 bytes at a time at max.

Vedas
 

    Help

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

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top