Pin A2 needed to be tied to VCC not VSS in order for the chip to be enabled. This however has not fixed my problem I am still getting nothing written to it.
Pin A2 needed to be tied to VCC not VSS in order for the chip to be enabled. This however has not fixed my problem I am still getting nothing written to it.
I believe I have the SDA and SCL pins going to the wrong pins on the 16F88. I have them right now going to PORTA.0 for SDA and PORTA.1 for SCL. I believe they need to be set as PORTB.1 for SDA and PORTB.4 for SCL with the 16F88. I will try this tonight and post my findings.
Well I have new results but still not looking like I am writing to the chip. Now when I read I get 255 for an output and not 0. I don't know if the 24FC1025 is default all 1's or 0's. Here is the new Code:
Hyperterm is giving me this:Code:SO con 0 ' Define serial output pin T2400 con 0 ' Define serial mode cont CON %10100000 ' Define Control byte addr CON %0000000000000111 ' 2 Byte Address of 7 B1 VAR BYTE ' Var for data being read B1 = 0 ' Set B1 to 0 to rule out 255 coming from that I2CWRITE PORTB.1,PORTB.4,cont,addr,[20] ' Send the byte 1 to address 7 PAUSE 10 ' Wait 10ms for write to complete I2CREAD PORTB.1,PORTB.4,cont,addr,[B1] ' Read address 7 into B1 Serout SO,T2400,["Addr",#addr,":",#B1,13,10] ' Print B1's Value in DEC
Any help would be appreciatedCode:Addr7:255 Addr7:255 Addr7:255 Addr7:255![]()
Table 2-1 of the data sheet Says this about pin A2
If you are still using the schematic from MeLabs then...Non-Configurable Chip Select.
This pin must be hard wired to
logical 1 state (VCC). Device
will not operate with this pin
left floating or held to logical 0
(VSS)
The other thing I see in the data sheet is the last bit of the control byte sets Read or Write.
0 = READ
1 = WRITE
And you may have to add this but try the above stuff firstCode:contR CON %10100000 contW CON %10100001 I2CWRITE PORTB.1,PORTB.4,contW,addr,[20] PAUSE 10 'Is that long enough? I2CREAD PORTB.1,PORTB.4,contR,addr,[B1]
DEFINE I2C_SLOW 1
But all the above might be a bunch of hooey. I have not used this chip...
Dave
Always wear safety glasses while programming.
Nope I found that mistake of mine earlier and fixed itIf you are still using the schematic from MeLabs then...
Yeah this one amazes me with PBP having an I2CREAD and a I2CWRITE command but yet you still have to tell it to READ or WRITE?!?!?!The other thing I see in the data sheet is the last bit of the control byte sets Read or Write.
0 = READ
1 = WRITE
Just to clarify I found this under section 5.0 saying that a READ operation should be a 1 and WRITE should be a 0
The last bit of the control byte defines the operation to
be performed. When set to a one, a read operation is
selected, and when set to a zero, a write operation is
selected.Yes I believe so because the 24FC1025 only has a 5ms delay neededPAUSE 10 'Is that long enough?
I tried it and got the same results, nothing but 255's.And you may have to add this but try the above stuff first
DEFINE I2C_SLOW 1
Do you know if the 24FC1025 is flashed with all 0's or all 1's from the factory? Before I was getting %00000000 from var B1 and now I am getting %11111111 but I want to know if its actually reading that or if its a blip in the coding.
Here is the updated code:
I added a 2nd byte to check an address I have not written to and also get a 255 from that but early on in the code I set B1 and B0 to 0 and its getting changed somehow. So either I am reading all 1's from the addresses or the code is screwy.Code:DEFINE I2C_SLOW 1 SO con 0 ' Define serial output pin T2400 con 0 ' Define serial mode contR CON %10100001 ' Define Control byte contW CON %10100000 ' Define Control byte addr CON %0000000000000111 ' 2 Byte Address of 7 D1 CON %00000111 B0 VAR BYTE ' Var for data being read B1 VAR BYTE ' Var for 2nd byte 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,B0] ' Read address 7 into B1 ' and address 8 into B0 Serout SO,T2400,["Addr",#addr,":",#B1," and then ",#B0,13,10] ' Print
PS sorry about the novel here, but its late and I tend to ramble when I'm tired.
Other notes:
I am using a 4MHz external clock to run the show if that matters. I will be switching to a 20MHz once I have everything working.
I picked up a couple of these 24FC1025 and I am not having any luck either.
A0 and A1 and WP are connected to VSS.
A2 connected to VDD.
10K pull up on SDA and SCL.
Tried "start/stop" sequence before and after I2C commands...
Out put to terminal is 0 no matter what.
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 DEFINE I2C_SLOW 1 DEFINE I2C_SCLOUT 1 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 VAR WORD DATI VAR BYTE DATO VAR BYTE ADDR = %0000000000000000 DATO = %11110000 START: SEROUT2 PORTB.2, 16572,["TEST",$d,$a] PAUSE 1000 HIGH CPIN:HIGH DPIN:LOW DPIN I2CWRITE DPIN,CPIN,CONTW,ADDR,[DATO] HIGH CPIN:LOW DPIN:HIGH DPIN Pause 10 HIGH CPIN:HIGH DPIN:LOW DPIN I2CREAD DPIN,CPIN,CONTR,ADDR[DATI] HIGH CPIN:LOW DPIN:HIGH DPIN Serout2 PORTB.2, 16572,["DATA IN ",BIN DATI] SEROUT2 PORTB.2, 16572,[$d,$a] GOTO START
Dave
Always wear safety glasses while programming.
I give up...
Dave
Always wear safety glasses while programming.
Bookmarks