PDA

View Full Version : accessing fram memory



servo260
- 8th March 2005, 05:39
Hi, I have a FM24C04A (fram memory from ramtron), and I want to access it usin a 16f627. Here is the code I wrote to do some tests (it's part of a bigger code).
What I want to do is to write a 5 (decimal) in some adress and then read it and write it to a variable, then send the variable to a display.
I was experimenting with shiftout and shiftin, but I don't really know what I am doing.
The memory uses the same pin to read and write, I tried to use also only one pin on the pic, Is it possible?




@ DEVICE INTRC_OSC_NOCLKOUT, WDT_OFF, PWRT_OFF, MCLR_OFF, BOD_OFF, LVP_OFF, CPD_OFF, PROTECT_OFF
include "modedefs.bas"
define osc 4

TRISA = %00000000
TRISB = %01000110

intcon = 0


clear

num var byte
x var word
cuenta var byte
velocidad var word
circunferencia var byte
demora var byte

t1 var portb.4
t2 var portb.5
t3 var portb.3
sda var porta.7
scl var porta.6

timer con 9

OPTION_REG = %10000111
INTCON = %11100000
CMCON = 7

shiftout sda, scl, 5, [%10100000, %00000000, 5]
shiftout sda, scl, 5, [%10100000, %00000000, %10100001]
TRISA.7 = 1
shiftin sda, scl, 7, [circunferencia]
TRISA.7 = 0

x = circunferencia

display:
num = x dig 0 ; unidad de X y lo manda a num
porta = num
high t1
pause 3
low t1
num = x dig 1 ; decena de X y lo manda a num
porta = num
high t2
pause 3
low t2
num = x dig 2 ; centena de X y lo manda a num
porta = num
high t3
pause 3
low t3
goto display

mister_e
- 8th March 2005, 06:02
As i know those 24c04 are I2C device... you must use I2CREAD and I2CWRITE

servo260
- 8th March 2005, 06:14
Can you give me a code example? I never use memories before.
What I don't understand is the "control" in the i2cwrite command.

mister_e
- 8th March 2005, 06:22
Have a look to the PBP manual.

Have a look to this code from Melabs website (http://www.melabs.com/resources/samples/pbp/i2c.bas)

and much on this forum.. search for I2CREAD and I2CWRITE

servo260
- 8th March 2005, 06:29
this is what I have done, I changed this

shiftout sda, scl, 5, [%10100000, %00000000, 5]
shiftout sda, scl, 5, [%10100000, %00000000, %10100001]
TRISA.7 = 1
shiftin sda, scl, 7, [circunferencia]
TRISA.7 = 0

to this

i2cwrite sda, scl, %10100000, %0000000000, [%00000101]
i2cread sda, scl, %10100001, %000000000, [circunferencia]

But the display shows 128 and not 005

mister_e
- 8th March 2005, 06:33
your adress must be 8 bits long.. not much. And you don't need to change you control word... PBP will do it for you.

also refer to your datasheet about the Twrite delay. some will need few milliseconds before the write cycle is finish.

so try


i2cwrite sda, scl, %10100000, 0, [5]
pause 10 ' safe delay
i2cread sda, scl, %10100000, 0, [circunferencia]

servo260
- 8th March 2005, 07:30
I read at the ramtron page that this memory uses a SPI protocol. Is It the same as I2C?

mister_e
- 8th March 2005, 07:41
i'm actually read the datasheet (http://www.ramtron.com/lib/literature/FM24C04Ads_r2.1.pdf)

it's really I2C or some will call that 2-wire

SPI or Microwire is for 93c serie, some Xicor (the old X2444, S-29220 and many others). Those you need 4 i/o
CS
CLK
SDI
SDO

and those are use with SHIFTIN/SHIFTOUT.

Those Ramtron FRAM are great... they say that you don't need any delay between the write and the read... they run at the same speed than the bus. Great!

servo260
- 8th March 2005, 12:29
Hi, thanks a lot fot the info. I put the wrong values for the resistors. Everithing is working fine now.