I put a test circuit together on my LAB-X4 using the PIC16F688 to talk to a 128kB FRAM.
I could feel your pain when trying to make your test program work so decided to start from almost scratch.
The TRIS statements were missing some bit assignments which are not a good thing, from what I read somewhere here by Henrik Olssen, so I put them in.
The order of CONFIG's and other setups were rearranged as well. Not really sure which fixed it but, 
The end results were that it works at 4MHz and here's the program to compare with.
Code:
'
' This setup uses a PIC16F688 and a FM24V01, 128kB Nonvolatile RAM to test
' the I2CREAD/WRITE functions at 4MHz.
'
' First: The FRAM memory is loaded with values 1~5 starting from
' location 0 using Word size address. The values written are sequentially
' loaded into the next memory location, so only the starting address is
' needed for this test.
' Read address = $A0
' Write address = $A1
'
' Second: The FRAM memory locations 0 thru 4 are READ in a loop then stops
' and waits the Test button on the LAB-4X to be pushed and repeats.
'
' The data was monitored with the Saleae Logic scope.
' Max clock speed measured at 4Mhz was 29kHz
'
' The DEBUG function was not used during this test
'****************************************************************
#CONFIG
ifdef PM_USED
device pic16F688, intrc_osc_noclkout, wdt_on, mclr_on, protect_off
else
__config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOD_OFF & _IESO_OFF & _FCMEN_OFF
endif
#ENDCONFIG
'-----------------------------------------------------
PORTA=0
PORTC=0
TRISA = %00001000 ' All 8 bits assigned one way or the other
TRISC = %00000000 ' All 8 bits assigned one way or the other
CMCON0 = 7
ANSEL = 0
OPTION_REG = 128 ' PORTA pullups disabled
INTCON=128
OSCCON = %01100001 ' Oscillator set to 4MHz
DEFINE DEBUG_REG PORTC
DEFINE DEBUG_BIT 3
DEFINE DEBUG_BAUD 2400
DEFINE DEBUG_MODE 1
DEFINE OSC 4
Include "modedefs.bas"
'-----------------------------------------------------------
Value VAR BYTE
WR_Addr VAR BYTE
RD_Addr VAR BYTE
LOC VAR WORD ' FRAM address must be sent as Word size
x VAR BYTE
'------------------------------------------------------------
SCL VAR PORTA.4 ' RA4, pin #3
SDA VAR PORTA.5 ' RA5, pin #2
Change VAR PORTA.3 ' Push button on LAB-X4
LED VAR PORTA.0 ' Test LED. LOW = ON
'------------------------------------------------------------
LOC = 0 ' Start at 0
LED = 1 ' Turn LED OFF
PAUSE 1000 ' Give me a chance to start the monitor
GOSUB Load_Mem ' Load FRAM memory locations 0~4 with values 1~5
Main:
FOR LOC = 0 TO 4
LED = 0 ' Turn ON LED, scope monitored
I2CWRITE SDA,SCL,$A0,[LOC],Fail1
PAUSEUS 25 ' Paused to see on display
I2CREAD SDA,SCL,$A1,[VALUE],Fail2
PAUSEUS 500 ' Paused to seperate packets, viewing purpose only
LED =1 ' Turn OFF LED
NEXT LOC
WHILE CHange: WEND ' Wait until button pushed
PAUSE 500 ' Cheap debounce
GOTO Main
'----------------------- Fail routines -------------------------------
Fail1: ' Try Write again
FOR x=0 to 50
LOW LED : PAUSE 50 : HIGH LED : PAUSE 50
Next x
GOTO Main
Fail2: ' Try read again
For x=0 to 5
LOW LED : PAUSE 250 : HIGH LED : PAUSE 250
Next x
GOTO Main
'---------------------- Load FRAM --------------------------------------
Load_Mem:
LED = 0 ' Turn ON LED, scope monitored
I2CWRITE SDA,SCL,$A0,[LOC,1,2,3,4,5],Fail1
LED = 1 ' Turn OFF LED
RETURN
END
This first screenshot is from:
Code:
Load_Mem:
LED = 0 ' Turn ON LED, scope monitored
I2CWRITE SDA,SCL,$A0,[LOC,1,2,3,4,5],Fail1
LED = 1 ' Turn OFF LED
RETURN
The 2nd and 3rd from the first and last loop Reads showing the values 1 and 5 after the $A1 READ address.
Bookmarks