CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Using Flash to store data

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
rhaguiuda



Joined: 05 Sep 2007
Posts: 46
Location: Londrina - Brazil

View user's profile Send private message

Using Flash to store data
PostPosted: Wed May 27, 2009 6:57 am     Reply with quote

Hi

I tried to search for this in the forums but didn't succeed.

How can I use PIC Flash to store data? (PIC18F2420). Using #ORG? Using #ROM?

Thanks!
_________________
Give a man a fish and you'll feed him for a day. Teach a man to fish, and you'll feed him for a lifetime.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed May 27, 2009 3:32 pm     Reply with quote

What type of data do you want to store ? How much ?

You can use 'const' to put an array into Flash memory. The limit is 256
elements for the 16F PICs, but the 18F have a much higher limit. I'm not
sure what it is, but probably thousands of elements.
rhaguiuda



Joined: 05 Sep 2007
Posts: 46
Location: Londrina - Brazil

View user's profile Send private message

PostPosted: Thu May 28, 2009 5:11 am     Reply with quote

Hi PCM.

I'm trying to store some large packages of data (400 bytes per package).
PIC will receive this data through serial port (USART), so I have to write to PIC's flash while the code is running. I can't use contants for this reason.

And besides writting the Flash, I need to read and clear, when desired. Just like an extension to PIC's RAM memory.

If i'm not mistaken, the Flash memory can only be erased in large blocks, not byte by byte, is this correct?

Thanks
_________________
Give a man a fish and you'll feed him for a day. Teach a man to fish, and you'll feed him for a lifetime.
Ttelmah
Guest







PostPosted: Thu May 28, 2009 5:27 am     Reply with quote

You really need to think in terms of another solution. I'd suggest you add an external FRAM chip instead.

There are a series of problems:
1) The 'write' life of the internal flash memory, is limited.

2) When writing to it's own Flash, the processor, _has_ to stop executing code. Unless the serial comms isstopped for the entire duration of the write, data will be lost. This is unavoidable.

3) Writing to flash, is _slow_. With an SPI based external FRAM, you could store the data in under a mSec. Depending on the block size of your chip, writing the same data to flash, would take perhaps 50mSec. While writing to the FRAM, serial interrupts, and other code could still run.

Flash, is the 'wrong' solution for what you describe.

Best Wishes
rhaguiuda



Joined: 05 Sep 2007
Posts: 46
Location: Londrina - Brazil

View user's profile Send private message

PostPosted: Thu May 28, 2009 5:29 am     Reply with quote

So I guess I'll have to take that data in much small sizes, and store in RAM.

Thanks for all help.
_________________
Give a man a fish and you'll feed him for a day. Teach a man to fish, and you'll feed him for a lifetime.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu May 28, 2009 4:15 pm     Reply with quote

rhaguiuda wrote:
So I guess I'll have to take that data in much small sizes, and store in RAM.
I'm not sure what you mean by storing in RAM. The PIC18 with the largest RAM capacity has only 3968 bytes, so you'll run out of memory fast.

As Ttelmah has pointed out the internal FLASH memory can't be used because the processor can't execute code during the write. So unless you can implement some kind of flow control in the data stream this is not an option.

Serial FRAM devices are available in capacities up to 2Mbit = 256kbyte. These are easy to use, can be written with single bytes, save data quicker than a PIC can send the data and don't wear out like flash memory does.
Manufacturers of FRAM are Ramtron and Fujitsu.

For even larger storage capacities you could consider using an MMC card.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group