![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
IGNACIO BRAVO Guest
|
I2C for 18C452 |
Posted: Fri Oct 19, 2001 7:37 am |
|
|
A few days ago, I sent a message with a problem with I2C for 16F877 and 18C245 for v3.0. I've solved the problem with 16F877, (thanks PCM Master)(bellow you can see de solution and works very well for 16f877) but the same code doesnīt work for 18C452. I'm transfering dates with I2C memories with 18C452 and I'm using these codes(if someone thinks that are interesting.) My serial memories are PCF8582 of Philips, with 256 bytes. I donīt understand why it works perfectly with 16F877 and doesnīt work with 182c452. Any idea?
Why doesnīt it work well?
Many thanks.
int read_memoria(int address)
{
int data;
int aux=0b10100001;
//First request a write process
i2c_start();
i2c_write(0b10100000);
i2c_write(address);
i2c_start();
//Second a read process
i2c_write(0b10100001);
data=i2c_read(0);
i2c_stop();
return(data);
}
void write_memoria(int address, int data)
{
int aux=0b10100000; //Addr slave=0
i2c_start();
i2c_write(aux);
i2c_write(address);
i2c_write(data);
delay_ms(10);
i2c_stop();
delay_ms(10);
return;
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 741 |
|
![](templates/subSilver/images/spacer.gif) |
Tomasz Bochenek Guest
|
Re: I2C for 18C452 |
Posted: Sun Oct 21, 2001 11:39 pm |
|
|
:=A few days ago, I sent a message with a problem with I2C for 16F877 and 18C245 for v3.0. I've solved the problem with 16F877, (thanks PCM Master)(bellow you can see de solution and works very well for 16f877) but the same code doesnīt work for 18C452. I'm transfering dates with I2C memories with 18C452 and I'm using these codes(if someone thinks that are interesting.) My serial memories are PCF8582 of Philips, with 256 bytes. I donīt understand why it works perfectly with 16F877 and doesnīt work with 182c452. Any idea?
:=Why doesnīt it work well?
:=
:=Many thanks.
:=
:=
:=int read_memoria(int address)
:= {
:= int data;
:= int aux=0b10100001;
:=
:=//First request a write process
:= i2c_start();
:= i2c_write(0b10100000);
:= i2c_write(address);
:=
:= i2c_start();
:=
:=//Second a read process
:= i2c_write(0b10100001);
:=
:=
:= data=i2c_read(0);
:= i2c_stop();
:=
:= return(data);
:=}
:=
:=
:=void write_memoria(int address, int data)
:={
:=
:= int aux=0b10100000; //Addr slave=0
:=
:=
:=
:=
:= i2c_start();
:= i2c_write(aux);
:= i2c_write(address);
:= i2c_write(data);
:= delay_ms(10);
:= i2c_stop();
:= delay_ms(10);
:=
:= return;
:=}
Hello,
I do not know the 18C245, but few weeks ago I had similar problem - to make my I2C communication working I had to put 10 usek delays after each read or i2s_stop() function. The solution came with one of the new versions of CCS PIC C - 3,050 or something. I suggest that you download the latest version and try again.
___________________________
This message was ported from CCS's old forum
Original Post ID: 761 |
|
![](templates/subSilver/images/spacer.gif) |
IGNACIO BRAVO Guest
|
Re: I2C for 18C452 |
Posted: Mon Oct 22, 2001 11:08 am |
|
|
Thanks everybody for your help. I've solved my problem with I2C for 18C452 with 3.0 version. It's incredible, we only changed an attribute in directive #USE (slow instead of fast). This is my code for read/write a I2C memory with address 0. I hope that this one will be useful for you.
Code: | #use I2C(master, sda=PIN_C4, scl=PIN_C3, SLOW)
int read_memoria(int address)
{
int data;
int aux=0b10100001; //101 mandatory code for this memory
i2c_start();
i2c_write(0b10100000); //Write Transfer
i2c_write(address);
delay_ms(10);
i2c_start();
i2c_write(0b10100001); //Read Transfer
data=i2c_read(0);
delay_us(10);
i2c_stop();
delay_us(10);
return(data);
}
void write_memoria(int address, int data)
{
int aux=0b10100000;
i2c_start();
i2c_write(aux);
i2c_write(address);
i2c_write(data);
delay_ms(10);
i2c_stop();
delay_ms(10);
return;
} |
___________________________
This message was ported from CCS's old forum
Original Post ID: 769 |
|
![](templates/subSilver/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|