I don't mean to be rude but the ". . ." means that I omitted code from the post or did you want three pages of the same thing over and over?
I also have no idea what colons have to do with anything.
I don't mean to be rude but the ". . ." means that I omitted code from the post or did you want three pages of the same thing over and over?
I also have no idea what colons have to do with anything.
Last edited by coyotegd; - 8th May 2008 at 08:19.
Instead of using addr.highbyte,addr.lowbyte in your I2CREAD / I2CWRITE lines, try using
just addr. PBP already knows addr is a word and will handle both high & low bytes of the
address for you.
I wrote a very simple program but with the same output result:
5, 57
5, 255
I tried using portc.0 as SDA and portc.1 at SCL with the same result. I used a different 16F877. It just doesn't make any sense to me anymore. I've checked the datasheets and my circuit many, many times.Code:DEFINE LOADER_USED 1 DEFINE OSC 20 edata var BYTE pause 100 i2cwrite portc.4,portc.3,160,5,[57] pause 10 serout2 portc.6,32,[dec 5,44,32,dec 57,10,13] i2cread portc.4,portc.3,160,5,[edata] serout2 portc.6,32,[dec 5,44,32,dec edata,10,13] end
Last edited by coyotegd; - 8th May 2008 at 17:56.
Have you tried scoping the SCL and SDA lines to see if it is really communicating? I2C is a no-brainer - if you get it working the first time.
The address should be declared in a WORD sized variable for the 24LC256. You then use this variable to hold the addresses for access.
Code:Address var Word ' this will hold the 16 bit word address EData var Byte ' Eprom data byte for read/write Address = 5 ' address to access Edata = $55 ' data to write I2Cwrite SCL,SDA,$A0, Address, [EData] ' write it Edata = 0 ' destroy the value before read I2Cread SCL,SDA,$A0, Address , [EData] ' read it back if Edata = $55 then Success ' if it compares, You Succeeded
It's the fact that this should be a "no brainer" that is so baffling. I've breadboarded much more complicated circuits, yet this simple EEPROM circuit won't work. I thought perhaps someone else had encountered this type of problem before and knew of a solution or could identify a source for troubleshooting.
A digital probe pulses away on both SCL and SDA during read/write ops.
BTW, I scoped portc.4 and c.3 outputs and SDA and SCL appear to be working. See Scope.jpg with data on top and clock on bottom. Both high prior to write/read operation and data high, clock low after write/read op. However, after a couple minutes, the clock goes high. I have no idea why.
The write-data signal doesn't change thoughout the write process and it's the same for the read-data signal, but the read signal is not the same as the write signal. See Scope2.jpg.
Last edited by coyotegd; - 11th May 2008 at 21:50.
Those waveforms look pretty bad.
For sure you need a lower pull-up resistance. 2KΩ is recommended for 400khz operation.
<br>
DT
Must have something to do with the multiplexed peripherals on RC3/4. I couldn't identify what could be the cause, but you could try to load the TRISC register yourself and define I2C_INTERNAL in case you want to use the internal I2C engine. There is something about the SSPSTAT reg too. Maybe you should look at those. I cannot comment since I havent used the 877 yet.
Bookmarks