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.

i2c interfacing code in microC

Status
Not open for further replies.

sudheepsrc

Junior Member level 3
Joined
Aug 8, 2010
Messages
28
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,283
Location
kerala
Activity points
1,474
plz help me,,,,,,,,,,


void main(){
PORTB = 0;
TRISB = 0;

I2C_Init(100000);
I2C_Start(); // Issue I2C start signal
I2C_Wr(0xA2); // Send byte via I2C (command to 24cO2)
I2C_Wr(2); // Send byte (address of EEPROM location)
I2C_Wr(0xF0); // Send data (data to be written)
I2C_Stop();

Delay_ms(100);

I2C_Start(); // Issue I2C start signal
I2C_Wr(0xA2); // Send byte via I2C (device address + W)
I2C_Wr(2); // Send byte (data address)
I2C_Repeated_Start(); // Issue I2C signal repeated start
I2C_Wr(0xA3); // Send byte (device address + R)
PORTB = I2C_Rd(0u); // Read the data (NO acknowledge)
I2C_Stop();
}

plz explain this code and address+W and address+R
 

basically this code is the example in mikroc; if you see your controller is connecterd to 24c02 eeprom.
now; i2c_int(100000) Initializes I²C with desired clock that is 100khz in this case.
I2C_Start(); Determines if I²C bus is free and issues START signal.
I2C_Wr(0xA2); Sends data byte (parameter data) via I²C bus. now you have to set parameter, as in this code data is written at address 2 and A(1010) is the control code (please refer to eeprom datasheet) so 'address+W' is gives A2; as writing data.
"I2C_Wr(0xF0) it cant be F"
the below code portion is same except I2C_Wr(0xA3) now you are reading data,
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top