Private Const FRAM_ID as Byte = bx1010_0000 'top 4 bits are the 256Kb identIfier 'place other Device ID codes here Public Const FRAM_Addr0 as Byte = bx0000_0000 'low 4 bits are the FRAM device selector Public Const FRAM_Addr1 as Byte = bx0000_0001 Public Const FRAM_Addr2 as Byte = bx0000_0010 Private FRAM_Channel as Byte '_____________________________________________________________________________________ Public Sub FRAM_Set_Channel(ByVal Channel as Byte) FRAM_Channel = Channel End Sub '_____________________________________________________________________________________ Public Sub FRAM_Write_Data ( ByVal FRAM_Device as Byte, _ ByVal RAM_Addr as Integer, _ byref Data() as Byte, _ byval Num_Bytes as Byte, _ byref Success as Integer) 'ram address base is 0 'no bounds checking is done. If you try to write (or read) past the 32767 upper limit, 'it will wrap back to zero and overwrite the low data. You may be a useful feature 'or a problem which would require the user to perform bounds checking. 'only up to 255 Bytes are written because the built-in I2C functions can only handle 'up to 255 Bytes eventhough the technique used in this module could be modIfied 'to accept up to 32767 Bytes (Integer rather then Byte) Given the limited RAM of the ZX, 'this limit is probably not an issue Dim FRAM_address as Byte Dim Index as Integer 'NO checking of the device number. Only 0-2 currently defined FRAM_Address = FRAM_ID + (FRAM_Device * 2) Success = 0 'have to do this Transfer manually I2CStart(FRAM_Channel) 'start the transfer 'Select the Fram device If Not I2cPutByte(FRAM_Channel, FRAM_Address) then Success = -1000 Exit Sub End If 'select the starting address If NOT I2cPutByte(FRAM_Channel, HiByte(RAM_Addr)) then 'set the hi address For the data Success = -1001 Exit Sub End If If NOT I2cPutByte(FRAM_Channel, LoByte(RAM_Addr)) then 'set the lo address For the data Success = -1002 Exit Sub End If For index = 1 to CInt(num_Bytes) If NOT I2CPutByte(FRAM_Channel,data(index)) then 'sEnd the data Success = Success - 1 End If Next 'index If (Success = 0) then Success = CInt(num_Bytes) End If I2CStop(FRAM_Channel) 'End the transfer End Sub '______________________________________________________________________________ Public Sub FRAM_Read_Data( ByVal FRAM_Device as Byte, _ ByVal RAM_Addr as Integer, _ byref Data() as Byte, _ byval Num_Bytes as Byte, _ byref Success as Integer) Dim FRAM_Info (1 to 2) as Byte Dim Fram_Address as Byte 'NO checking of the device number. Only 0-2 currently defined FRAM_Address = FRAM_ID + (FRAM_Device * 2) FRAM_Info(1) = HiByte(Ram_Addr) FRAM_Info(2) = LoByte(RAM_Addr) 'NO checking of RAM bounds 'For this we can use the built-in function ' I2CCmd(channel, slave_id,write_count, write_data, read_count, read_data) Success = I2CCmd(FRAM_Channel, FRAM_Address, 2, Fram_Info(1), Num_Bytes, Data(1)) End Sub