First you must know the size of a programming page. It is a power of two usually ranging from 512 bytes to 4096 bytes, depending on the total capacity of the device. The best approach is to buffer your data in a RAM area with the size of a FLASH page and program it at once. Furthermore, most of the current devices don't allow for erasing a single page. They only can erase a sector at a time, that is a number of consecutive pages, sometimes as large as 128 pages in length. Don't forget that erasing a sector (or page when allowed) usually takes longer than programming it and each sector/page has a maximum number of erase/write cycles during its lifetime, usually between 100,000 or 1,000,000 times but sometimes as low as 10,000 times. If you have the RAM and your data arrives fast, you may want to allocate two buffers, while you are filling one buffer from the serial port the other is being written to the FLASH. Best regards, Isaac Em 22/12/2013 04:25, Andre Abelian escreveu: > Hi All, > > I have to write to flash memory 2 pocket of data one of them is always 14= bytes and the second one may very 110-128 bytes of data. the way flash mem= ory works is > I can't rewrite like EEPROM is. in order to rewrite entire sector needs t= o be erased and after erase all cells becomes logic 1. the reason I mention= this is if verification failed I have to ignore and go next. in my case I = have 2 uart and one of them is 14 byte rx data coming in and the second one= 120 byte rx. as soon as the data comes in I have to store in to flash. al= l data are mixed 14 bytes or 120 bytes can be mixed order and different in= formation. the size of flash is 4000000 bytes. the way I see it easiest wa= y to save data is to define maximum data size lets say 130 bytes and store = data every 130 bytes regardless of 14 bytes or 120 bytes is coming in. so t= he data will be stored every 130 bytes and to read back it will be every 13= 0 bytes witch makes it easy to read. another way I was thinking is to add s= tart and end character and when it comes to read back i just look for start= and end character. total record can go up to 25000. I am not sure > if I explained clearly. on top of this since i already knew about flash = I also added 256kb eeprom to store location information where was last save= d. my question is what's the best way do you think to store data in flash a= nd read back all.=20 > > any idea? > > thanks > > Andre =20 --=20 http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .