CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

I2C for 18C452

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
IGNACIO BRAVO
Guest







I2C for 18C452
PostPosted: Fri Oct 19, 2001 7:37 am     Reply with quote

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
Tomasz Bochenek
Guest







Re: I2C for 18C452
PostPosted: Sun Oct 21, 2001 11:39 pm     Reply with quote

:=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
IGNACIO BRAVO
Guest







Re: I2C for 18C452
PostPosted: Mon Oct 22, 2001 11:08 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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