PDA

View Full Version : 24LC256 and PIC16F877



Tomas
- 1st March 2004, 01:18
Hi,

I have used I2CREAD and I2CWRITE in order to write to and read from the 24LC256 EEPROM. As example code i'm using I2CX.bas with the byte address changed to WORD.
I have connected the two wires in I2C protocol as follows:

SCL var PORTC.3 ' Clock pin
SDA var PORTC.4 ' Data pin

These two pins according to the 24LC256 data sheet are not supposed to be HIGH as the same time. However after lodding the .HEX file the pins were constantly HIGH. The conde looks like this:

For B0 = 0 To 15 ' Loop 16 times
B1 = B0 + 100 ' B1 is data for SEEPROM
I2CWRITE SDA,SCL,$A0,B0,[B1] ' Write each location
Pause 10 ' Delay 10ms after each write
Next B0

Loop: For B0 = 0 To 15 Step 2 ' Loop 8 times
I2CREAD SDA,SCL,$A0,B0,[B1,B2] ' Read 2 locations in a row
Lcdout $fe,1,#B0,": ",#B1," ",#B2," " ' Display 2 locations
Pause 1000
Next B0

Goto loop

Finally when running all i can see is the address incrementing by 2 and the two data variables B1 and B2 were just 0.
Can anyone see what the problem is? Please help. Thanks for you time in advance.
Tom

NavMicroSystems
- 1st March 2004, 12:48
Hi Tom,

assuming the variables used are declared as:

B0 VAR WORD
B1 VAR BYTE
B2 VAR BYTE

the code is ok.


If you are using a fast crystal (20MHz), add these two DEFINEs:

DEFINE I2C_SLOW 1
DEFINE I2C_SCLOUT 1

Add pullups (4k7) to the data and clock line and it should work.
(it might work with a pullup on the data line only)

rgds

Tomas
- 1st March 2004, 14:01
Hi,
It works now, i had 10K to pull up the data and clock lines. May be that coursed the problem. Thank you very much.
I have 8 of 25LC256 devices and in each device i will store A/D results until they are full and once full start storing again.
I'm thinking to do it as follows:
I'll store the result of the A/D from say channel 0 in EEPROM-device 1 with device-address $A0.
And the result to the A/D from channel 1 will be stored in EEPROM device 2 with device address $A2.
And the the last EEPROM-device will have address of $AE and A/D result from channel 7 will be stored in it.
I'm thinking to use FOR ... NEXT and there is 32 768 bytes in each device. However i'm worried if this approach will take a lot of time and i'm not sure how to write to the 64 byte page of an 24LC256 device.
Once this is done, i like to send the results from each EEPROM to a PC using RS232 protocol.
I'm new to PicBasic Pro and i know that the way i'm thinking to do is so "BAD". Can you please give some tips how to approach the problem with good performance?
Best Regards,
Tom.