mackrackit, Why are you using 10 k's for the pullup's? I believe the spec. says 4.7K or lower.. Might be the problem....
Dave Purola,
N8NTA
mackrackit, Why are you using 10 k's for the pullup's? I believe the spec. says 4.7K or lower.. Might be the problem....
Dave Purola,
N8NTA
The data sheet for this part call for 10k at 100 kHz and 2k for 400 kHz and 1 MHz.
It did not work at the higher speeds so I was trying it at the slow.
Dave
Always wear safety glasses while programming.
I have tried several different resistor sizes and still nothing.
I think I am actually communicating with it as it "ACK" backs at me...
Here is my current mess...
Code:' 18F6680 24FC1025 DEFINE OSC 20 @ __CONFIG _CONFIG1H, _OSC_HS_1H @ __CONFIG _CONFIG2H, _WDT_OFF_2H & _WDTPS_128_2H @ __CONFIG _CONFIG4L, _LVP_OFF_4L TRISF = 0 PORTF = 0 DPIN VAR PORTF.6 'I2C DATA PIN CPIN VAR PORTF.7 'I2C CLOCK PIN CONTR CON %10100001 'READ CONTROL CONTW CON %10100000 'WRITE CONTROL ADDR_HB VAR BYTE ADDR_LB VAR BYTE DATI VAR BYTE DATO VAR BYTE ACK VAR BIT ADDR_HB = %00000000 ADDR_LB = %00000000 DATO = %11100000 CNT VAR BYTE CNT = 0 START:CNT = CNT + 1 GOSUB WRITE_DATA PAUSE 100 GOSUB READ_DATA SEROUT2 PORTB.2, 16572,["TEST ",DEC CNT,$d,$a] Serout2 PORTB.2, 16572,["DATA IN ",BIN DATI] SEROUT2 PORTB.2, 16572,[$d,$a] PAUSE 500 GOTO START WRITE_DATA: ACK=1 :Serout2 PORTB.2, 16572,["ACK ",BIN ACK,$d,$a] GOSUB START_ROM SHIFTOUT DPIN,CPIN,1,[CONTW] SHIFTIN DPIN,CPIN,0,[ACK\1] Serout2 PORTB.2, 16572,["ACK ",BIN ACK,$d,$a] SHIFTOUT DPIN,CPIN,1,[ADDR_HB] SHIFTIN DPIN,CPIN,0,[ACK\1] SHIFTOUT DPIN,CPIN,1,[ADDR_LB] SHIFTIN DPIN,CPIN,0,[ACK\1] SHIFTOUT DPIN,CPIN,1,[DATO] SHIFTIN DPIN,CPIN,0,[ACK\1] GOSUB STOP_ROM PAUSE 10 RETURN READ_DATA: GOSUB START_ROM SHIFTOUT DPIN,CPIN,1,[CONTR] SHIFTIN DPIN,CPIN,0,[ACK\1] SHIFTOUT DPIN,CPIN,1,[ADDR_HB] SHIFTIN DPIN,CPIN,0,[ACK\1] SHIFTOUT DPIN,CPIN,1,[ADDR_LB] SHIFTIN DPIN,CPIN,0,[ACK\1] GOSUB START_ROM SHIFTOUT DPIN,CPIN,1,[CONTR] SHIFTIN DPIN,CPIN,0,[ACK\1] SHIFTIN DPIN,CPIN,0,[DATI\8] GOSUB STOP_ROM PAUSE 10 RETURN START_ROM: HIGH CPIN:HIGH DPIN:LOW DPIN:RETURN STOP_ROM: HIGH CPIN:LOW DPIN:HIGH DPIN:RETURN
Dave
Always wear safety glasses while programming.
I changed the Control Byte for the read and the write from this:
to this:Code:contR CON %10100001 contW CON %10100000
Thinking that because A2 is held high for it to operate then the control bit for A2 should also be a 1... here is the new code:Code:contR CON %10100011 contW CON %10100010
this is the output from hyperterm:Code:DEFINE I2C_SLOW 1 SO con 0 ' Define serial output pin T2400 con 0 ' Define serial mode contR CON %10100011 ' Define Control byte contW CON %10100010 ' Define Control byte addr CON %0000000000000111 ' 2 Byte Address of 7 addr2 CON %0000000000001000 ' 2 Byte Address of 8 D1 CON %00000111 B0 VAR BYTE ' Var for data being read B1 VAR BYTE ' Var for data being read B0 = 0 B1 = 0 I2CWRITE PORTB.1,PORTB.4,contW,addr,[D1] ' Send the byte 1 to address 7 PAUSE 10 ' Wait 10ms for write to complete I2CREAD PORTB.1,PORTB.4,contR,addr,[B1] ' Read address 7 into B1 I2CREAD PORTB.1,PORTB.4,contR,addr2,[B0] ' Read address 8 into B0 Serout SO,T2400,["Addr",#addr,":",#B1," and then Addr",#addr2,":",#B0,13,10] ' Print B1's Value in DEC
Like I said I don't know what it means but it sure is different then what I was getting.Code:Addr7:2 and then 2
Any thoughts as to why it now is reading a "2" and not 255 or 0??? Its almost like it read the last 2 bits of the write control byte as if the write command wrote the last 2 bits of the control byte to the EEPROM.
UPDATE:
I just switched the control byte to be:
and got this as an output (Note the "6" in Address 8 to begin and then it get over written to "255" the next go around):Code:contR CON %10100001 contW CON %10100010
also I know I'm writing to it because in the example output above I read address 6 with it too (not shown in the code but I added it after posting) and I was reading "255" every time. So this tells me that I am writing a "6" to address 8 but then on the second loop it gets over written/erased to "255" but the "2" in address 7 remains constant and in memory. Now keep in mind that no where in my code do I try to write to address 8 it just happens, more than likely from an over flow from the write to address 7. So basically the byte I am trying to write to 7 gets split into a "2" in address 7 and a "6" in address 8 then address 8 gets overwritten on the 2nd loop to a "255".Code:Addr7:2 and then Addr8:6 Addr7:2 and then Addr8:255 Addr7:2 and then Addr8:255 Addr7:2 and then Addr8:255 Addr7:2 and then Addr8:255
and when I do the control byte like this:
I get this (the same as having both A2 bits set to 1):Code:contR CON %10100011 contW CON %10100000
Code:Addr7:2 and then Addr8:2 Addr7:2 and then Addr8:2 Addr7:2 and then Addr8:2
Last edited by wolwil; - 17th April 2010 at 05:37.
Sorry, read the data sheet wrong. Nevermind
Last edited by ScaleRobotics; - 17th April 2010 at 06:50.
Whoops it dawned on me what I am doing by changing that Bit. I guess that my novice understanding of this made me stumble upon the fact that I am now writing and reading from a different Chip Select, but seeing how I only have the one chip I dont understand how its reading/writing chip 01 when it should be chip 00.![]()
So I guess where I was calling it the A2 bit its actually the A0 bit that I was changing.
How do you have pins A0 and A1 connected?
I have not had a chance to work on this today yet so I do not have any new news.
Dave
Always wear safety glasses while programming.
Bookmarks