View previous topic :: View next topic |
Author |
Message |
marceleza
Joined: 24 May 2006 Posts: 6 Location: S㯠Paulo - Brazil
|
i2c library - help!! |
Posted: Wed May 24, 2006 6:45 pm |
|
|
Hi!
I am with one pic 16F877 and a memory 24C04.
I am using the CCS and the library i2c to ready/write the memory.
I change it and I tried to make some changes, I am using the AN10216_1 of the Philips, that deals with i2c - http://www.semiconductors.philips.com/acrobat_download/applicationnotes/AN10216_1.pdf
I tried to make a reading of the memory using the described sequencia in this AN (inside of the document one exists slide number 35), but dont work correct.
I only obtain to make the reading using the code of the CCS. The code of ccs is:
////////////////////////////////////////////
byte read_ext_DEVICE(long int address)
{
byte data;
i2c_start();
i2c_write(ENDERECO); // 0xA0
i2c_write(address);
i2c_start();
i2c_write(ENDERECO+1);
data=i2c_read(0);
i2c_stop();
return(data);
/////////////////////////////////////
And my code is:
///////////////////////////////////////
byte read_ext_DEVICE(long int address)
{
byte data;
i2c_start();
i2c_write(ENDERECO+1);
i2c_write(address);
data=i2c_read(0);
i2c_stop();
return(data);
///////////////////////////////////////////
In the library of ccs I have that to call the address memory (0xA0) + 0, that would be for writing (write) and in sequence a read command.
Somebody can explain pq to me this?
[ ]'s
Marcelo |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed May 24, 2006 7:42 pm |
|
|
Don't use the Philips appnote. Use the actual data sheet for the 24C04.
Here is a link to the data sheet for the Microchip 24LC04B:
http://ww1.microchip.com/downloads/en/DeviceDoc/21708E.pdf
Look at the diagram for "Random Read" on page 10. It matches
the CCS driver code. |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Thu May 25, 2006 7:12 am |
|
|
The CCS driver works. Why are you changing it? Did you try it? Remember that you need to have pullups on the clock and data lines. |
|
|
marceleza
Joined: 24 May 2006 Posts: 6 Location: S㯠Paulo - Brazil
|
|
Posted: Mon May 29, 2006 5:35 am |
|
|
Hi!
Thanks for the aid!
Yes, the code of ccs works fine, I were only curious why in a AN of philips, the way of reading it is deferential of that it is in the example of ccs.
But I saw that the routine that I modified he only serves to read the position of following memory, or either, if I will be in position 00, the reading I will be of position 01.
[]´s
Marcelo |
|
|
|