【正文】
軟件驅(qū)動程序也不是非常復雜。狀態(tài)轉(zhuǎn)換之所以重要是因為CS線在微控制器和串行EEPROM之間被用作主要的握手線。}以上我展示了sermem_StopWrite()函數(shù)的執(zhí)行。 0x01)。 // 用來選擇EEPROM進行讀狀態(tài)操作 Spi_select ()。串行EEPROM在它往陣列里保存數(shù)據(jù)時需要一個爆發(fā)時間。,是使用該規(guī)則的一個測試程序。Void sermem_WriteBlock (into address, unsigned char *puffin cub)。Void sermem_ReadBlock (into address, unsigned char *puffin cuff)。其中一些具有不同的頁容量和數(shù)據(jù)//容量Void sermem_Initialize ()。當你完成時,sermem_StopRead()會被調(diào)用。它也定義了讀和寫操作。如果你在跨越頁邊界后繼續(xù)寫,那么后面的寫操作將在當前頁循環(huán)并覆蓋以前寫過的數(shù)據(jù),那不是你要做的!我已經(jīng)在Image craft ‘C’下寫過一套規(guī)則,用來處理處理串行EEPROM的問題。微芯片25C640使用32字節(jié)的頁。在一個WRITE操作中,升高CS線引起EEPROM存儲數(shù)據(jù)。你的軟件在寫的時候需要將此考慮進去。這是相當好的。當你選擇了一個器件后需要將此考慮進去。寫入狀態(tài)寄存器需要8bit的格式,等等。命令表你可以發(fā)給串行EEPROM一些為數(shù)不多的命令。連上一個串行EEPROM太簡單了,它能添加到幾乎所有的CPU,只要該CPU支持SPI總線。最近我在板子的背面為串行EEPROM添加了一塊地方。對于我們尤其有趣的是EEPROM陣列(它實際上是EEPROM存儲單元),狀態(tài)寄存器(保存結構和狀態(tài)信息),當然還有頁鎖存(它是暫時保存當前寫入數(shù)據(jù)的區(qū)域)。8VCC電源線。如果你需要中斷操作來訪問其他SPI總線上的器件,那么該引腳是有用的。CPU輸出的數(shù)據(jù)在此線上隨時鐘輸出。這適合于當你想對軟件錯誤有額外的保護,或者你打算僅僅從器件讀出。用SPI的術語,就是Slave Out,它應該連接到SPI端口的MISO引腳。這是器件的一個標準引腳。它們(EEPROM)也有幾種封裝型號,包括一個8引腳雙列直插封裝以及SOIC。這些較小的差別很容易在軟件中解決。與此對應,Atmen也有一個128K字節(jié)的器件。這對于許多應用來說是很合適的。當然,存在一些折中。另一方面,一個有8引腳封裝的串行電擦除可編程存儲器能夠買到。與此比較,一個較為標準的存儲器將需要地址總線和數(shù)據(jù)總線!操作串行電擦除可編程存儲器所需要的組合邏輯數(shù)量是相當?shù)偷?。本文的焦點就是基于SPI(串行外圍接口)的器件。當然,你可以給它們中的大多數(shù)掛上外部存儲器,但是,那要做許多工作,而且通常要消耗其他有價值的資源,僅僅是那些輸入/出引腳使芯片變得有用。}Above I show my implementation of the sermem_StopWrite () function. This functions job is to cause the serial EEPROM to mit a previously transferred page to EEPROM. The function razes the CS line, and then issues a RDSR instruction and loops waiting for the WIP bit to go to zero. Note that the spi_deselect () and spi_select () instructions needed to be there. The state transition is important because the CS line is used as the primary handshake between the micro controller that the serial EEPROM. It signals the start and stop of operations. // The Write in Progress (WIP) flag is bit 1. Wait for it to go low } While (spiting (SERMEM_INST_RDSR) amp。Void sermem_Fill (into address, unsigned char bitewing count)。Void sermem_StartWrite (into address)。Void sermem_StartRead (into address)。 mode, which means you can send up to 1 PAGE of data at a time. The number of bytes in a PAGE depends on the specific part. For example, the Atmen 25128 uses a 64 byte PAGE. The Microchip 25C640 uses a 32 byte PAGE. The idea is that each time the address spans a PAGE boundary, you need to raise the CS line so that the chip can write is page into memory. The key thing to watch for is when the address crosses that page boundary. You can write between one and the PAGE size bytes, which means if you only want to write a single byte that is fine. If you continue to write after crossing the page boundary, then the subsequent writes will wrap around on the current page and overwrite previously written data, which isn39。t use them in my software, but you are certainly wele to use them. On my board, you merely cut the trace on the jumper, and wire up the appropriate pins to a port for control.Table of mandsThere are a small number of mands that you can issue to the serial EEPROM. The following table is a quick summary.Instruction Instruction CodeDescriptionREAD0000 0011Read data from memory array beginning at selected addressWRITE0000 0010Write data to memory array beginning at selected addressWREN0000 0110Set the write enable latch (enable writing)WRDI0000 0100Clear the write enable latch (disable writing)RDSR0000 0101Read status registerWRSR0000 0001Write status registerEach instruction code has its own argument requirements. Read/Write, for example, is followed by an address. Writing the status register requires an 8bit argument, and so on. A plete set of instructions and their formats are available in the data sheet for your particular part. Most of these SPI parts have extremely similar manuals!. This is useful if you have interrupt driven routines that need to access ot