Split from: How to use FRAM..?

Go To Last Post
34 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Dear all,

I am new to use FRAM, 

Could you please tell me what is lower address and upper address ? 

I am going to write and read 8 different value. So I need to store them in one matrix or in different and specific address. (am I right ?)

This topic has a solution.
Last Edited: Thu. Sep 28, 2017 - 12:12 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well for a start you might want to say what part number. But if we assume the FM25L256 already mentioned in this thread then a Google for "FM25L256 datasheet" gets you to here:

 

http://datasheet.octopart.com/FM...

 

In one place that tells us:

 

 

Later it says this about SPI operation:

 

So you will send WREN as one 8bit command, then WRITE as the next 8 bit command. Then an address between 0x0000 and 0x7FFF to select the location within 32K where you want to start writing. Then the bytes of data to be written. You stop the write by raising _CS after you write the last byte.

 

So to answer your question, for a 32K byte device the 32K bytes have a lower address of 0x0000 and an upper address of 0x7FFF.

 

No doubt the datasheet for the device you actually plan to use tells you how many bytes it holds. The bottom will be 0x0000 and the top will be <device_size_bytes>-1

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hossein128 wrote:
I am new to use FRAM

You do realise that you are waking a thread that has been dead for ten years ?!

 

Could you please tell me what is lower address and upper address ? 

In what context, exactly?

 

This doesn't sound like anything specifically to do with FRAM - in any memory, you will have "low" (ie, numerically "small") and "high" (ie, numerically "large")  addresses.

 

Or perhaps it's referring to the least/less significant and most/more significant parts of an address word - again, nothing specifically to do with FRAM.

 

I am going to write and read 8 different value. So I need to store them in one matrix

You can store them in whatever arrangement makes most sense for the purposes of your application.

Of course, we know absolutely nothing about your application - so nobody can help you with what may or may not be appropriate.

 

This may also be unrelated to FRAM per se.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:
This doesn't sound like anything specifically to do with FRAM - in any memory, you will have "low" (ie, numerically "small") and "high" (ie, numerically "large") addresses.
I think he's mistakenly thinking this is just going to appear in "AVR memory space" (presumably the RAM one?) and because there's already stuff there this FRAM will appear at some offset so will have lower/upper address bounds.

 

I think he may have failed to grasp the difference between serial and parallel addressed memory devices. Clearly for serially (SPI) addressed memory then all the addresses AND data all go down the same, single wire, one after another.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You may well be right.

 

But it certainly doesn't seem to have anything to do with the original topic - so should be split?

 

EDIT

 

Has now been split.

 

Original thread was: http://www.avrfreaks.net/forum/how-use-fram

 

Last Edited: Tue. Sep 26, 2017 - 04:55 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

One virtual beer on Hossein not returning and answering...

"He used to carry his guitar in a gunny sack, or sit beneath the tree by the railroad track. Oh the engineers would see him sitting in the shade, Strumming with the rhythm that the drivers made. People passing by, they would stop and say, "Oh, my, what that little country boy could play!" [Chuck Berry]

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Dear clawson,

Thanks for your reply.

you make it clear now for me. 

I'm gonna use MB85RS16N.

the datasheet is available in 

http://edevice.fujitsu.com/fj/DA...

 

Again Thanks and sorry for my delay to reply.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Dear awneil

Thanks for your reply.

yes you are right I forgot to tell about my application. 

My project is to read 7 different sensors (Hall sensors) and count the number of sense and store them in F-RAM.

and in some specific case micro controller need to read the numbers and continue ...

I hope I could make it clear for you.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

awneil wrote:
This doesn't sound like anything specifically to do with FRAM - in any memory, you will have "low" (ie, numerically "small") and "high" (ie, numerically "large") addresses.
I think he's mistakenly thinking this is just going to appear in "AVR memory space" (presumably the RAM one?) and because there's already stuff there this FRAM will appear at some offset so will have lower/upper address bounds.

 

I think he may have failed to grasp the difference between serial and parallel addressed memory devices. Clearly for serially (SPI) addressed memory then all the addresses AND data all go down the same, single wire, one after another.

yes right :) 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

JohanEkdahl wrote:

One virtual beer on Hossein not returning and answering...

laugh laugh laugh 

Im here , SOrry for delay

Cheers 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hossein128 wrote:
I'm gonna use MB85RS16N.

 

So does have an SPI connection to the microcontroller:

Fujitsu, in the MB85RS16N datasheet, wrote:

DESCRIPTION

MB85RS16N is a FRAM (Ferroelectric Random Access Memory) chip in a configuration of 2,048 words × 8 bits, using the ferroelectric process and silicon gate CMOS process technologies for forming the nonvolatile memory cells. MB85RS16N adopts the Serial Peripheral Interface (SPI). 

 

https://edevice.fujitsu.com/fj/DATASHEET/e-ds/MB85RS16N-DS501-00030-3v0-E.pdf

 

 

hossein128 wrote:
you make it clear now for me

So is your question now answered?

 

If so, please mark the appropriate post using the  'Mark Solution' button.

 

You could also edit the thread title so that it actually reflects the question that you were asking.

 

EDIT

 

See: http://www.avrfreaks.net/comment...

 

Last Edited: Wed. Sep 27, 2017 - 07:59 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:

 

So is your question now answered?

 

If so, please mark the appropriate post using the  'Mark Solution' button.

 

You could also edit the thread title so that it actually reflects the question that you were asking.

Kinda,,,, 

to save my data as there is 8 different values /Variables do I need to set specific lower and upper address to write and read each variable ??

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hossein128 wrote:
8 different values /Variables
Here are 8 randomly selected variables:

int number;
long long_num;
char c;
short half_int;
uint16_t data[14];
struct {
    int n;
    long l;
} combined;
union {
    uint32 num;
    uint16_t word[2];
    uint8_t bytes[4];
} joined;
int32_t signed_var;

What do your 8 look like?

 

Anyway, given that there's no limit (speed or number) on writes to FRAM personally I'd be tempted to put all my 8 variables together in a struct then do a complete struct_write() when you want to save changes made to the RAM based copy.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hossein128 wrote:
to save my data as there is 8 different values /Variables do I need to set specific lower and upper address to write and read each variable ??

Again, this has nothing specifically to do with FRAM.

 

Of course, you need to know where something is stored in memory in order to be able to access it!

 

Because, as Cliff pointed out, an SPI-connected memory does not appear in the microcontroller's address space, this is not something that can be managed by the compiler (as for "normal" program variables) - so you are going to have to define how stuff gets stored in your SPI memory.

 

A common way is to put all your data into a structure, and copy the entire structure to/from the SPI device.

 

EDIT

 

Cliff beat me to it.

Last Edited: Wed. Sep 27, 2017 - 08:08 AM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

hossein128 wrote:

8 different values /Variables

 

Here are 8 randomly selected variables:

int number;
long long_num;
char c;
short half_int;
uint16_t data[14];
struct {
    int n;
    long l;
} combined;
union {
    uint32 num;
    uint16_t word[2];
    uint8_t bytes[4];
} joined;
int32_t signed_var;

What do your 8 look like?

 

Anyway, given that there's no limit (speed or number) on writes to FRAM personally I'd be tempted to put all my 8 variables together in a struct then do a complete struct_write() when you want to save changes made to the RAM based copy.

Thanks for your reply and I appreciate it .

My variables are float numbers. 

Using structure is a good Idea. 

Thanks

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:

hossein128 wrote:
to save my data as there is 8 different values /Variables do I need to set specific lower and upper address to write and read each variable ??

Again, this has nothing specifically to do with FRAM.

 

Of course, you need to know where something is stored in memory in order to be able to access it!

 

Because, as Cliff pointed out, an SPI-connected memory does not appear in the microcontroller's address space, this is not something that can be managed by the compiler (as for "normal" program variables) - so you are going to have to define how stuff gets stored in your SPI memory.

 

A common way is to put all your data into a structure, and copy the entire structure to/from the SPI device.

 

EDIT

 

Cliff beat me to it.

 

I got it. 

Thanks to make it clear for me. 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

When quoting, don't quote the entire post - it clogs up the thread!

 

Just pick out enough to give context to your reply.

 

See, for example, #13 and #14

 

EDIT

 

Or, for a general reply, just use the 'Reply' button on the post in question - then the forum will identify which post you're replying to:

 

 

 

#Quoting

Last Edited: Wed. Sep 27, 2017 - 08:50 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sure, my bad 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I appreciate it if you guide me how to write and read the structure to/from the memory 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How can we guide you when you’ve told us very little?
There’s examples using arduino. This should get you started.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thanks for your reply 

I am using ATmega 644, and Code Vision (C language) 

I already got that I need to make structure for my data, so I need to know how I can write and read created struct to/from external FRAM

please let me know if you need more details.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How many times does this have to be repeated?

 

The fact that it's FRAM is irrelevant - the approach would be exactly the same for any other type of SPI-connected memory. And, in fact, any other SPI-connected peripheral at all.

 

There are plenty of examples of using serial memories - especially EEPROM.

 

You will have to check the chip datasheet for the specific command/response format.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:

How many times does this have to be repeated?

 

3 to 4 timesdevil

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:
There’s examples using arduino. This should get you started

eg, https://github.com/hackscribble/hackscribble-ferro-library/blob/master/Hackscribble_Ferro.cpp

 

found by simply putting "MB85RS16N c code" into google.

 

other search engines are available.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:
in fact, any other SPI-connected peripheral at all

So, if you've never used SPI at all before, you might want to start with some basic SPI exercises.

 

Microchip has a nice little board with 7 common SPI peripherals on it:

 

http://www.microchip.com/DevelopmentTools/ProductDetails.aspx?PartNO=pkserial-spi1

 

There's 

  • SPI temperature sensor
  • SPI Analogue-to-Digital converter (ADC)
  • SPI digital potentiometer
  • SPI Programmable-Gain Amplifier (PGA)
  • SPI IO expander

and, of course, an SPI serial EEPROM (ie, memory).

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Have you got functions to read/write bytes/blocks of data to the fram? You’ll need these first.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for your suggestion 

I will consider it  smileyyes

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thanks for your reply;

well I write the following code (but I need to improve it and I am not sure its correct or not):

 

void WriteFRAM(char AddrL, char AddrU, float data )
 {

      
        PORTB.0 = 0; 
        F_Transmit(WREN); // opcode
        PORTB.0 =1;
        delay_us(10);
        PORTB.0 =1;
        F_Transmit(WRITE); // opcode
        F_Transmit(AddrU); // upper adress bits
        F_Transmit(AddrL); // lower adress bits
        F_Transmit(data); // Data byte
        

        PORTB.0 =1;

}

 

void SaveDataST(float P0,float P1, float P2,float P3,float P4,float P5,float P6,float P7 )  
      
   {
   int sizeST;
   int Address;
   char *p;
   typedef unsigned char BT;   
    
    struct Position
   {
    float M0;
    float M1;
    float M2;
    float M3;
    float M4;
    float M5;
    float M6;
    float M7;
   }Position_M; 

   

p = (BT*)&Position_M;
                             
      for ( Address = 0; Address < sizeof(Position_M); Address++ )
       {
        WriteFRAM(0x10, Address, *p);
        p++;
       }
 }

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You can only write one byte at a time to SPI memory. A "float" in CodeVision occupies 4 bytes so it will take 4 writes to store the float.
.
But really a struct (or more obviously an array?) holding eight float variables is really just a block of 32 bytes (8 * 4) so create a routine to write any block of N bytes to the memory then call it to write 32 bytes giving it the start address of the struct or array.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:
Have you got functions to read/write bytes/blocks of data 

Hopefully this is sinking in by now:

 

For any SPI peripheral, you will need to start with functions to send/receive bytes of data. Then you take those functions, and use them to send/receive blocks of data, etc ...

 

The thing to note with SPI is that it is always full-duplex - meaning that it is always receiving at the same time it is sending.

It is the sending (from the master) which causes the clock to be generated - so you cannot receive anything without sending something.

 

So, with SPI, you will not have separate send byte & receive byte functions - but an "exchange" function which sends & retrieves the byte received while sending.

 

You can see this on page 9 of the datasheet.

 

Again, if you've never done SPI before, it may be easier to get your head around this by starting with a simpler slave device ...

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How to properly post source code: http://www.avrfreaks.net/comment...

 

clawson wrote:
You can only write one byte at a time to SPI memory

The MB85RS16N does support "automatic address increment" for writing multiple bytes in a single "transaction"

 

See datasheet, page 9

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hossein128 wrote:

 PORTB.0 = 0; 

Why no comment on this, nor any of the other PORTB.0 lines?

 

What do you think these lines do?

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
#define FRAM_SELECT PORTB.0


void WriteFRAM(uint16_t Addr,  uint8_t data )
 {
      
        FRAM_SELECT = 0; 
        F_Transmit(WREN); // opcode
        FRAM_SELECT =1;
        delay_us(10);
        FRAM_SELECT = 0;
        F_Transmit(WRITE); // opcode
        F_Transmit(Addr>>8); // upper adress bits
        F_Transmit(Addr & 0xff); // lower adress bits
        F_Transmit(data); // Data byte
        FRAM_SELECT =1;
}

void WriteBlockFRAM(uint16_t Addr,  uint8_t *data , uint16_t length)
 {
      
        FRAM_SELECT = 0; 
        F_Transmit(WREN); // opcode
        FRAM_SELECT =1;
        delay_us(10);
        FRAM_SELECT =0;
        F_Transmit(WRITE); // opcode
        F_Transmit(Addr>>8); // upper adress bits
        F_Transmit(Addr & 0xff); // lower adress bits
        uint16_t a = 0
        while ( a < length)
            {
            F_Transmit(*data++); // Data byte
            a++;
            }
        
        FRAM_SELECT =1;
}

I've not read the datasheet on your device, so the above code is just a guess. I expect it will work better than yours - you had some glaring defects.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for your reply, 

it was very helpful and now its clear for me .