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.

More than 1 I2C on single line

Status
Not open for further replies.

Analyzer

Full Member level 6
Joined
Nov 18, 2001
Messages
374
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,298
Activity points
3,518
proteus show vterm

Hi there,

I need more than 100 Kb memory for my application.I'm using ccs c compiler, 16F877, 24LC256 and proteus for desing.Can i use more than one I2C memory with same pins? I want to use 4 24LC256 on the same line (same pins of 877) Is it possible? If so, How can i use it? Any proteus dsn files for this? Or some brief will be fine for me :)

Thanks

Analyzer.
 

i2c_write(address &0xfe)

Usually, I2C chip has three additional pins: A2-A0. These pins represent the part of I2C devices address and being connected to 0 or 1 can be used to assign different addresses to different chips. So, that you can address these chips individually. Check 24LC256 datasheet if you need more info.

Ace-X.
 

usually every i2c device have there own address. i2c device are also have family pre-fix address bit and select address bit. example 24CXXX eerom memory will have address bit of 1010 and change able bit for chip select A2 A1 A2 , you could set this bit by connect these pin or memory ic to logic low or hi (Gnd or Vcc) and when you what to access to these chip you just ask for right address. For other device like port expander etc.. the family code will change it by the manufacture so it not mix up with the memory device. I think we may possible to use more than 10 device on one line. One thing you need to becare full of using a lot of device on one line is the pull up resister value of sda and scl . If you use a lot of device with a long distance you may need good pull up resister calculation or some circuit to help line transfer data and clock correctly. I have been build loger with 4 24lc256 and they are working fine...
 

As that device has 3 address pins you will be ok for upto 8 devices on the I2C bus.
Just as a thought, have you not considered serial flash - much larger memory sizes are available (>1Mb).

Regards
sjo
 

So,

Should i connect devices like this? :

By the way i cannot login as "Analyzer" :

I change it to jpg and added a vterm.
 

Hmm,

I'm very confused to use these addresses.I'm using CCS C Compiler 3.168 and Proteus 6 I tested this schematic with this code :

#include "c:\.....\I2C_Mem.h"
#include <24128.c>
#use rs232(baud=19200, xmit=PIN_C6, rcv=PIN_C7)

void main() {

int16 c,i,s;

init_ext_eeprom();

c = 1;i=50;

s=32000;

printf("WRITE\n\r");

while(c < 100) {WRITE_EXT_EEPROM(c+s,i);c++;i++;if (i>100) i=50;}

c = 1;i=50;

printf("READ\n\r");
while(c < 100) {printf("%c",READ_EXT_EEPROM(c+s));c++;i++;if (i>100) {i=50;printf("\n\r");}}

printf("\n\rFinished");
}

I missed something with addresses i think, and i have no idea how to talk with first and second memory.. This code works if 0<s<32676 So, i think i can not access to the second memory. I'm close to finish

Analyzer.
 

Analyzer said:
I'm very confused to use these addresses.

I guess, you miss the difference between I2C device address and address inside EEPROM memory. I2C supports up to 128 devices on the same lines, so before you will send/receive any data from device, you have to select it. So, you send its address on I2C bus to show that the next command will be addressed to very this device. We use I2C address at this point (1010000 or 1010001 in your case). After that you send the command to I2C EEPROM on reading/writing from/to specified address. Here we are talking about address inside memory.

As to your case, I think you have to take a look for changes inside file 24128.c (not sure, 'cause I never worked with CCS).

Good luck and Merry Christmas!

Ace-X.
 

470k for pull up is too low for i2c mabee 470 ohm or 4.7k but not 470 k !
 

#include <24128.c>
#ifndef EEPROM_SDA

#define EEPROM_SDA PIN_B1
#define EEPROM_SCL PIN_B0

#endif

#define hi(x) (*(&x+1))

#use i2c(master, sda=EEPROM_SDA, scl=EEPROM_SCL)

#define EEPROM_ADDRESS long int
#define EEPROM_SIZE 16384

void init_ext_eeprom()
{
int i;

output_float(EEPROM_SCL);
output_float(EEPROM_SDA);
delay_us(4);
for (i=0;i<3;i++) {
i2c_start();
i2c_write(0xa0);
i2c_write(0xff);
i2c_write(0xff);
if(i==2)
i2c_write(0x2);
else
i2c_write(0x2+i);
i2c_stop();
}
}


void write_ext_eeprom(long int address, BYTE data)
{
i2c_start();
i2c_write(((0xa0)|(hi(address)>>5))&0xfe);
i2c_write(hi(address)&0x3f);
i2c_write(address);
i2c_write(data);
i2c_stop();
delay_ms(10);
}


BYTE read_ext_eeprom(long int address) {
BYTE data;

i2c_start();
i2c_write(((0xa0)|(hi(address)>>5))&0xfe);
i2c_write(hi(address)&0x3f);
i2c_write(address);
i2c_start();
i2c_write((0xa1)|(hi(address)>>5));
data=i2c_read(0);
i2c_stop();
return(data);
}

This is the header driver file i am using.Here is i2cwrite prototype :

i2c_start(); // Start condition
i2c_write(0xa0);// Device address
i2c_write(cmd);// Low byte of command
i2c_write(cmd>> 8 );// High byte of command
i2c_stop(); // Stop condition

I need to change first i2write to choose rigth address.Am i right? :

void write_ext_eeprom(long int address, BYTE data)
{
i2c_start();
i2c_write(((0xa0)|(hi(address)>>5))&0xfe); //This line to be changed
i2c_write(hi(address)&0x3f);
i2c_write(address);
i2c_write(data);
i2c_stop();
delay_ms(10);
}

I need to rewrite write_ext_eeprom(...) and read_ext_eeprom(...). How should i change my header file?

Analyzer
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top