A kind of method of EEPROM data write-in
Technical field
The present invention relates to a kind of methods that the technical field of extensive aggression more particularly to EEPROM data are written.
Background technology
EEPROM (band electrically erasable programmable read-only memory) is the modifiable read-only memory of user, can pass through height
It wipes and reprograms in the effect of common voltage, therefore EEPROM is widely used.
There are one feature, write-in data will appear a page flop phenomenon by EEPROM.A such as AT24C02BN EEPROM core
Piece memory space is 2kbit, that is, 256byte, and AT24 points are page 32, and every page of length is 8byte, if from address 0x5
Start that [8]={ 0,1,2,3,4,5,6,7 } data is written, first page content is after completion:0x0~0x7:3、4、5、6、7、0、
1、2.EEPROM often transfers a byte after calling I2C write-in interfaces, and current page address can transfer current page from adding 1
Current page beginning of the page is returned in address after the last one byte.No matter how many a bytes are transmitted, as long as reaching current page when write-in
The last one byte, address can all automatically return to current page beginning of the page, and other addresses then add 1 automatically.Here it is EEPROM automated pages
Write automatic turning.Page based on EEPROM writes flop phenomenon, if be written by I2C bulk transfers data to EEPROM, by nothing
Method is written page by page.In addition, after EEPROM receives the data that I2C is transmitted, hardware needs the regular hour to be written.So such as
If fruit calls I2C only to transmit a byte every time, on the one hand repeat to call that I2C occupancies and time can be increased, on the other hand
Delay regular hour after a byte of being often totally lost allows EEPROM write-in hardware to greatly reduce execution efficiency again.
Invention content
The technical issues of present invention need to solve is to overcome the shortcomings of above-mentioned, provides a kind of efficient EEPROM data write-in
Method, which is characterized in that including:
Step 1, the initial address of write-in be EEPROM effective address, and total length of data to be written be no more than from
The initial address to the highest address of EEPROM effective length when, execute step 2;
Step 2, it is transmitted to EEPROM in batches after data prediction to be written;
Step 3, successively EEPROM is written in the data to be written received by EEPROM.
Further, the step of data prediction to be written specifically includes:
Step A, if total length of data to be written is less than or equal to the initial address to EEPROM current page highests address
Length is then written into data and is disposably transmitted to EEPROM, no to then follow the steps B;
Step B, if total length of data to be written be more than the initial address to EEPROM current page highests address length,
The initial address then is transmitted to the data of the length of EEPROM current page highests address to EEPROM, updates the initial address
With the total length of data to be written, step A is executed.
Further, the data to be written are transmitted to EEPROM transmission using I2C.
Further, the initial address is the beginning of the page address of EEPROM.
Further, the EEPROM is AT24C02BN.
After the method for the present invention, EEPROM is transmitted to after data prediction to be written in batches, the EEPROM successively will
The data to be written write-in EEPROM received, avoids the automatic page turning phenomenon when write-in of EEPROM data, more due to that will wait for
Write-in data transmit in batches, have often transmitted a batch, and EEPROM write-in a batch improves efficiency, avoid and every have transmitted one
The problem that the delay regular hour makes EEPROM write-in hardware efficiencies low after byte.
Description of the drawings
Fig. 1 is the method flow diagram of EEPROM data write-in provided by the invention;
Fig. 2 is the flow chart of data prediction to be written provided by the invention.
Specific implementation mode
In order to make relevant technical staff in the field more fully understand technical scheme of the present invention, below in conjunction with of the invention real
The technical solution in embodiment of the present invention is clearly and completely described in the attached drawing for applying mode, it is clear that described reality
The mode of applying is only some embodiments of the invention, rather than whole embodiments.
The invention will be further described with embodiment below in conjunction with the accompanying drawings.
Refering to fig. 1, it is a kind of method of the EEPROM data write-in of embodiment provided by the invention, this method includes:
Step S100, the effective address for being EEPROM in the initial address of write-in, and total length of data to be written does not surpass
Cross from initial address to the highest address of EEPROM effective length when, execute step S200;
In the present embodiment, initial address is beginning of the page address.
One AT24C02BN eeprom chip memory space is 2kbit, that is, 256byte, and AT24 points are page 32,
0x00~0xff is the effective address of EEPROM, and when the initial address of write-in is 0x00, writable data to be written are total
Length is up to 256byte.
Step 200, it is transmitted to EEPROM in batches after data prediction to be written;
The data prediction to be written for being written into EEPROM transmits in batches, has often transmitted a batch and has waited for EEPROM write-ins.
Successively EEPROM is written in the data to be written received by step S300, EEPROM.
EEPROM often receives a batch data to be written, and a batch is just written.
In a preferred embodiment, the data prediction to be written includes:
Step S201, judge total length of data to be written whether be less than or equal to the initial address to EEPROM current pages most
The length of high address;
Step S202, if total length of data to be written is less than or equal to the initial address to EEPROM current page highests address
Length, then be written into data and be disposably transmitted to EEPROM, it is no to then follow the steps S203;
Step S203, to EEPROM transmit the initial address to the length of EEPROM current page highests address data,
The initial address and the total length of data to be written are updated, step S201 is executed.
By step S201~S203, the initial address and the total length of data to be written are constantly updated, until
It is just written into data write-in on EEPROM one pages, is then transferred to EEPROM, EEPROM is written.
In the present embodiment, initial address is beginning of the page address, so the data length transmitted every time to EEPROM is exactly the page
Length.
In above-mentioned steps, it is written into data and passes a batch, write-in a batch.This incoming batch data can just be from write-in
Initial address avoids the phenomenon that generating page overturning when writing batch of data, also avoids to the length of the last one address of current page
It passes a byte and writes a low problem of byte efficiency.
Only several embodiments of the present invention are expressed above, the description thereof is more specific and detailed, but can not therefore and
It is interpreted as the limitation to the scope of the claims of the present invention.It should be pointed out that for those of ordinary skill in the art, not taking off
Under the premise of present inventive concept, various modifications and improvements can be made, these are all within the scope of protection of the present invention.Cause
This, the protection domain of patent of the present invention should be determined by the appended claims.