版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、<p><b> 外文翻譯</b></p><p> Serial Memories</p><p><b> Overview</b></p><p> Many of us like to use small, single chip micro controllers. They are relat
2、ively cheap, easy to wire up to make run, and over all just mighty convenient to use. One down side to using these single chip controllers is the lack of large amounts of memory. Sure, you can hook up external memory to
3、most of them, but that requires a lot of work, and usually consumes other valuable resources, mainly the I/O pins that make the chip useful.</p><p> There is help out there! There are several forms of memor
4、y that don't require the standard address bus and data bus wiring. These memories are called serial memories, and they are just the ticket to allow you to store large amounts of information without giving up those pr
5、ecious I/O lines. There are several different styles of serial EEPROM. The focus of this article is going to be SPI based devices. There are also 1, 2, and 3 wire serial EEPROM devices that function in a similar way, but
6、 have d</p><p> This article is going to introduce the basics of serial memories, and present the driver software needed to make it operate.</p><p> Missing the Bus</p><p> The b
7、ig advantage to using a Serial EEPROM is that the wiring only requires 4 signal lines from the CPU to operate it. Compare this with a more standard memory, which requires an address bus and a data bus! The amount of glue
8、 logic required to make a Serial EEPROM operate is extremely low. </p><p> For example, check out the following two packages. A traditional memory, such as a 27256, requires a 28-pin part to be wired into y
9、our circuit. There are 15 address lines, 8 output lines, plus assorted control lines. On the other hand, a serial EEPROM can be purchased using in a 8-pin package. There is 1 input line, 1 output line, 1 control line, an
10、d 1 clock line required. There are a couple of other control lines available, but are not actually required if you wish to avoid them. As you can ima</p><p> Of course, there are tradeoffs. Since the memory
11、 of the serial EEPROM is accessed one bit at a time, there is a speed penalty to be paid. However, these are still extremely fast parts. They can output their data at over 2 million bits per second, which is quite reason
12、able for many applications. So, for a small amount of software overhead and only 4 I/O pins, you can have yourself some substantial data storage!</p><p> Would you like to super Size that?</p><p&
13、gt; Serial EPROM’s are available in a variety of different sizes. They seem to range from 128 bytes all the way up to 32k bytes. Atmen also has a 128k byte device that fits the same form factor. All of these parts are e
14、lectrically compatible. However, some require minor software changes. For example, some allow writes of 32 bytes at a time, where others allow 64 bytes at a time. These minor differences are easily dealt with in software
15、. </p><p> It turns out that serial EPROM’s are available from several different manufacturers. At least two, Microchip and Atmen, have compatible chips. I haven't looked into the other manufacturers, b
16、ut I would expect theirs may be as well. </p><p> They are also available in several package sizes, including an 8pin DIP as well as SOIC surface mount. </p><p> The Basics</p><p>
17、; There are 8 pins on one of these parts. Here is a list and their functions</p><p> (* denotes active LOW)</p><p> The Block Diagram</p><p> As always, engineers love to see th
18、e block diagram! Here is the block diagram you will find in the documentation for the Microchip 25C640:</p><p> As you can see, there are a few different parts called out in the block diagram. Of particular
19、 interest to us are the EEPROM Array, which is the actual EEPROM memory cells, the Status Register, which is a register that holds configuration and status information, and of course the Page Latches, which are the tempo
20、rary 'holding' areas for data being written. The other parts are also interesting, but I am going to ignore them for this article. </p><p> A Schematic</p><p> Connecting a serial EEPR
21、OM is really quite straight forward. I have been offering a board based on the 68HC912B32 Micro controller for some time now. I recently added a spot for a serial EEPROM to the backside of the board. The following snippe
22、t of the schematic shows the 25xxx series EEPROM connected to the SPI port for this board. Note that on my 912B32 board, this is an optional device. I left several cut jumpers (these are areas where the trace can be cut,
23、 and the wiring done differently) on</p><p> Connecting up a serial EEPROM is pretty straight forward, and it can be added to almost any CPU that supports the SPI bus. Note that I have chosen to leave the W
24、P (Write Protect) and HOLD lines wired high. I don't use them in my software, but you are certainly welcome to use them. On my board, you merely cut the trace on the jumper, and wire up the appropriate pins to a port
25、 for control.</p><p> Table of commands</p><p> There are a small number of commands that you can issue to the serial EEPROM. The following table is a quick summary.</p><p> Each
26、 instruction code has its own argument requirements. Read/Write, for example, is followed by an address. Writing the status register requires an 8-bit argument, and so on. A complete set of instructions and their formats
27、 are available in the data sheet for your particular part. Most of these SPI parts have extremely similar manuals! You can find a list of data sheets on the Microchip website at which will provide you with a lot of
28、 extra detail.</p><p> Speed issues</p><p> Most parts can operate with transfer speeds in excess of 1 megabit per second. Some parts can go up to 8 megabits per second. You need to take this
29、into consideration when you are selecting a part. Luckily, most of the SPI implementations, such as the 68HC11 and 68HC12 SPI ports, allow you to adjust the clock speed for the SPI port with a clock scalar. Thus, if you
30、are connecting a 25LC640, for example, to a 16mhz 68HC12, you will need to select an SPI presale that slows the SPI bus down to 2mhz</p><p> Cycle life</p><p> Serial EPROM’s are typically rat
31、ed to endure 1 million write operations per byte. That’s pretty decent. However, you still need to be careful here that you are not constantly writing data to the part. EEPROM is not a substitute for general purpose RAM.
32、 If you write to these parts in a tight loop, it would only take an hour or so to exceed the 1million write operations. Your software needs to be written to take that into account. </p><p><b> Softwar
33、e</b></p><p> As you can see, wiring up an SPI based EEPROM to the SPI port is relatively simple. Nothing comes for free, however, and you will find the software commands needed to work with the SPI m
34、emory is a little more complex than just doing memory writes. </p><p> The basic operation of the SPI based EPROM’s is to lower the CS line, send a command, such as WRITE, followed by an address and the dat
35、a, then raise the CS line. In a WRITE operation, raising the CS line causes the EEPROM to actually store the data. That is an important point you don't want to miss!</p><p> Serial EPROM’s allow you to
36、write in 'page' 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 us
37、es 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. </p><p> The key thing to watch for is when the
38、 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 th
39、e subsequent writes will wrap around on the current page and overwrite previously written data, which isn't what you wanted to do!</p><p> I have written a set of routines in Image craft 'C' tha
40、t deal with the serial EPROM’s. I have included links to the source below. </p><p> The software is structured in a simple way. There is an initialization routine, which sets up the SPI port appropriately.
41、It also defines read and write operations. </p><p> The read/write operations function the same basic way. You start the operation by calling the sermem_StartRead () function, giving the initial address. Th
42、en, you issue a series of sermem_Read () commands. When you are done, sermem_StopRead () is called. For ease of use, I have also defined a function called sermem_ReadBlock () that does the entire operation at once.</p
43、><p> The Write versions do the same basic functions. Here are the function prototypes from the sermon files: </p><p> // Sermem.h - Copyright 1998 (c) Kevin W Ross, all rights reserved</p>
44、<p><b> //</b></p><p> // Accompanies sermem.c and defines some of the basic information needed to</p><p> // Deal with the serial EEPROM memories.</p><p><
45、b> //</b></p><p><b> //</b></p><p> // Device Profiles - Here are the variables needed for each specific type of</p><p> // chip. Some have different page s
46、izes and data sizes</p><p><b> //</b></p><p> Void sermem_Initialize ();</p><p> Void sermem_StartRead (into address);</p><p> Void sermem_Read (unsigne
47、d char *puffin cuff);</p><p> Void sermem_StopRead (void);</p><p> Void sermem_ReadBlock (into address, unsigned char *puffin cuff);</p><p> Void sermem_StartWrite (into address)
48、;</p><p> Void sermem_Write (unsigned char *puffin cuff);</p><p> Void sermem_StopWrite (void);</p><p> Void sermem_WriteBlock (into address, unsigned char *puffin cuff);</p&g
49、t;<p> Void sermem_Fill (into address, unsigned char bitewing count);</p><p> You can find the full source code in sermem.c and sermem.h, which are fairly well commented and pretty easy to follow. T
50、his code is written for the 68HC12 series of chips, but is really trivial to port to the 68HC11 (an excursive left to the reader!). </p><p> Another file is called memtest.c, which is a test program that us
51、es the routines.</p><p> The Status Register</p><p> An important part of the serial EEPROM is the status register. I thought it important to point it out that you need to use this register. T
52、his register not only holds some configuration data that you will need to write to, it also contains an important bit called the WIP bit standing for "Write In Progress". Serial EEPROM requires a burn time whil
53、e it is saving data to the array. This can take up to 5 milliseconds, though it might be less. Rather than relying on a timer on your micro controller,</p><p> Void sermem_StopWrite (void)</p><p&
54、gt;<b> {</b></p><p><b> //</b></p><p> // Raise the CS line. That makes the memory part start its write cycle</p><p> // Then wait for the WIP bit to be
55、cleared</p><p><b> //</b></p><p><b> Do</b></p><p><b> {</b></p><p> spi_deselect ();</p><p> // Need to select th
56、e EEPROM for the read status operation</p><p> spi_select ();</p><p> Spinout (SERMEM_INST_RDSR);</p><p> // The Write in Progress (WIP) flag is bit 1. Wait for it to go low</
57、p><p> } While (spiting (SERMEM_INST_RDSR) & 0x01);</p><p> Spi_deselect ();</p><p> // Disallow further writes to the EEPROM. Prevents rouge clock signals</p><p>
58、 // From corrupting your data!</p><p> Sermem_WriteDisable ();</p><p><b> }</b></p><p> Above I show my implementation of the sermem_StopWrite () function. This funct
59、ions job is to cause the serial EEPROM to commit 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
60、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 EEP</p><p&
61、gt;<b> Summary</b></p><p> Serial EEPROM provide a great way to store non-volatile data on a small micro controller project. They require few I/O lines, relatively fast read/write operations, a
62、nd most operate from a single 5volt power supply. The software routines to drive these parts are not very complex. Next time you need to store some non-volatile data, such as configuration information or navigation maps,
63、 consider serial EEPROM.</p><p><b> 串行存儲器</b></p><p><b> 概述</b></p><p> 我們中的許多人喜歡使用小型的獨立芯片微控制器。它們相對較為便宜,容易接線運行,而且最重要的是使用非常方便。使用這些微控制器的一個不好的方面是它們缺乏大容量的存儲器。
64、當然,你可以給它們中的大多數(shù)掛上外部存儲器,但是,那要做許多工作,而且通常要消耗其他有價值的資源,僅僅是那些輸入/出引腳使芯片變得有用。</p><p> 這里能提供幫助!有幾種形式的存儲器不需要標準地址總線和數(shù)據(jù)總線配線方式。這些存儲器稱為串行存儲器,它們允許你在不放棄那些珍貴的輸入/出引線的條件下,存儲大容量的信息。存在幾種不同形式的串行電擦除可編程存儲器。本文的焦點就是基于SPI(串行外圍接口)的器件。也
65、有1線,2線和3線式串行電擦除可編程存儲器器件,它們以相似的方式工作,但是具有不同的接口邏輯。</p><p> 本文將介紹串行存儲器的基礎,并指出操作它所需要的驅動軟件。</p><p><b> 總線不見了</b></p><p> 使用串行電擦除可編程存儲器的最大優(yōu)勢是:配線時僅僅需要CPU的4根信號線來操作。與此比較,一個較為標準
66、的存儲器將需要地址總線和數(shù)據(jù)總線!操作串行電擦除可編程存儲器所需要的組合邏輯數(shù)量是相當?shù)偷摹?lt;/p><p> 例如,檢驗以下兩個封裝。一個傳統(tǒng)的存儲器,像27256,需要28個引腳來接線到你的電路。其中有15條地址線,8條輸出線,還有多種控制線。另一方面,一個有8引腳封裝的串行電擦除可編程存儲器能夠買到。其中有1條輸入線,1條輸出線,1條控制線,還需要1條時鐘線。一些其他的控制線可能會用到,但是如果你希望不用
67、它們,那么實際上并不需要。正如你能想象到的,這更容易接線,更小巧,而且最大的好處是非常便宜!一個8kx8器件在DIGIKEY的價格是1.61美元。</p><p> 當然,存在一些折中。由于串行電擦除可編程存儲器每次訪問一個bit,這要付出速度上的代價。然而,它們仍然是相當快速的器件。它們能以每秒200萬bit的速度輸出數(shù)據(jù)。這對于許多應用來說是很合適的。所以,對于小數(shù)量的軟件開銷和僅僅4個I/O引腳,你可以為
68、自己存儲一些基本數(shù)據(jù)。</p><p> 你想要一個大一點的型號嗎?</p><p> 串行電擦除可編程存儲器有各種型號可供使用。它們從128字節(jié)一直到32K字節(jié)不等。與此對應,Atmen也有一個128K字節(jié)的器件。所有這些器件在電氣上都是兼容的。然而,一些器件需要有較小的軟件變化。例如,某些器件允許一次寫32字節(jié),而其他的允許一次寫64字節(jié)。這些較小的差別很容易在軟件中解決。<
69、/p><p> 顯然,串行電擦除可編程存儲器可以從幾個不同的廠商那里得到。至少兩個,Microchip和Atmel,擁有兼容的芯片。我還沒有考察其他的廠商,但是可以預見,它們的也同樣(兼容)。</p><p> 它們(EEPROM)也有幾種封裝型號,包括一個8引腳雙列直插封裝以及SOIC。</p><p><b> 基礎部分</b></
70、p><p> 這些器件之一具有8個引腳。以下是引腳列舉和它們的功能。</p><p> ?。?表示低電平有效)</p><p><b> 方塊圖</b></p><p> 通常,工程師們愛看方塊圖!下面就是你在本文中找到的Microchip 25C640的方塊圖:</p><p> 正如你所看
71、到的,方塊圖里有一些不同的部分。對于我們尤其有趣的是EEPROM陣列(它實際上是EEPROM存儲單元),狀態(tài)寄存器(保存結構和狀態(tài)信息),當然還有頁鎖存(它是暫時保存當前寫入數(shù)據(jù)的區(qū)域)。其他部分也是有趣的,但是在這篇文章里我將忽略它們。</p><p><b> 一個示意圖</b></p><p> 連接一個串行EEPROM是很簡單的。我提供一個基于68HC91
72、2B32微控制器的板子已有一段時間了。最近我在板子的背面為串行EEPROM添加了一塊地方。接下來示意的圖片展示了連接到板子SPI端口的25xxx串行EEPROM。注意,在我的912B32板子上,這是一個最優(yōu)器件。我在板子上留下了幾個切換開關(在該區(qū)域,跟蹤能被切斷,配線方式不同)它們顯示在示意圖中。</p><p> 連上一個串行EEPROM太簡單了,它能添加到幾乎所有的CPU,只要該CPU支持SPI總線。注意
73、,我已經(jīng)選擇將WP和HOLD線接為高電平。在我的軟件中,我不使用它們,但我歡迎你使用它們。在我的板子上,你僅僅在開關上切斷跟蹤并為控制端口連接到合適的引腳就行了。</p><p><b> 命令表</b></p><p> 你可以發(fā)給串行EEPROM一些為數(shù)不多的命令。以下表格是一個簡單的總結。</p><p> 每個指令編碼有它自己的格
74、式要求。例如Read/Write,緊接著它的是地址。寫入狀態(tài)寄存器需要8bit的格式,等等。一套完整的指令及格式可以在你的特殊器件的數(shù)據(jù)手冊上得到。多數(shù)SPI器件具有相當類似的手冊!你能在下面的微芯片網(wǎng)址上找到數(shù)據(jù)手冊的列表,里面將給你提供大量的額外細節(jié)。 </p><p><b> 速度問題</b></p><p> 多數(shù)器件能在傳輸速度超過1兆比特每秒的條件下
75、操作。當你選擇了一個器件后需要將此考慮進去。幸運的是,多數(shù)SPI的執(zhí)行,例如68HC11和68HC12的SPI端口,允許你根據(jù)時鐘標量來調整SPI端口的時鐘速度。所以,如果你連接的是25LC640,例如,連到16mhz的68HC12,那將需要選擇一個SPI比例因子來降低SPI總線到2mhz。這是個普通的疏忽,也是錯誤的重要來源!</p><p><b> 使用壽命</b></p>
76、;<p> 串行EEPROM的典型值為每字節(jié)能承受一百萬次寫操作。這是相當好的。然而,在這里你仍然需要注意,你并不是不斷地給器件寫數(shù)據(jù)。EEPROM不是一般用途的RAM的替代品。如果你以一個短周期往這些器件(EEPROM)里寫數(shù)據(jù),那將僅僅花費一小時左右來超過一百萬次寫操作。你的軟件在寫的時候需要將此考慮進去。</p><p><b> 軟件</b></p>
77、<p> 正如你所見到的,基于EEPROM的SPI配線到SPI端口相對簡單。沒有不需要代價的東西,然而,你將發(fā)現(xiàn)需要與SPI存儲器一起工作的軟件命令比存儲器寫操作更為復雜。</p><p> 基于EEPROM的SPI基本操作是拉低CS線,發(fā)送一條命令,像WRITE,接著是地址和數(shù)據(jù),然后升高CS線。在一個WRITE操作中,升高CS線引起EEPROM存儲數(shù)據(jù)。這是你不想丟掉(數(shù)據(jù))的關鍵!</p
78、><p> 串行EEPROM允許你以頁模式進行寫操作,那意味著你每次能發(fā)送1頁數(shù)據(jù)。每頁的字節(jié)數(shù)取決于具體的器件。例如,Atmel 25128使用64字節(jié)的頁。微芯片25C640使用32字節(jié)的頁。思路是每次地址跨越一頁,你需要升高CS線以便芯片能將一頁數(shù)據(jù)寫入存儲器。</p><p> 觀察的關鍵是什么時候地址跨越頁邊界。你可以寫一字節(jié)直到一頁,那意味著如果你僅僅想寫單個字節(jié),那沒問題。如
79、果你在跨越頁邊界后繼續(xù)寫,那么后面的寫操作將在當前頁循環(huán)并覆蓋以前寫過的數(shù)據(jù),那不是你要做的!</p><p> 我已經(jīng)在Image craft ‘C’下寫過一套規(guī)則,用來處理處理串行EEPROM的問題。我把如下資源的鏈接包括在內了。</p><p> 該軟件以一個簡單的方式構造起來。有一個初始化過程,建立起合適的SPI端口。它也定義了讀和寫操作。</p><p&g
80、t; 讀/寫操作工作于相同的基本方式。你通過調用sermem_StartRead()函數(shù)開始操作,同時要給出初始化地址。然后,你發(fā)出一系列sermem_Read()命令。當你完成時,sermem_StopRead()會被調用。為了使用容易,我還定義了一個稱為sermem_ReadBlock()的函數(shù),它能一次執(zhí)行全部操作。</p><p> 寫翻譯執(zhí)行相同的基本功能。以下是sermon文件中的功能原型:<
81、;/p><p> // 配合 sermem.c文件,定義了一些需要的基本信息</p><p> // 處理串行EEPROM存儲器</p><p> // 器件聲明——這是每類芯片需要的變量。其中一些具有不同的頁容量和數(shù)據(jù)//容量</p><p> Void sermem_Initialize ();</p><p>
82、; Void sermem_StartRead (into address);</p><p> Void sermem_Read (unsigned char *puffin cuff);</p><p> Void sermem_StopRead (void);</p><p> Void sermem_ReadBlock (into address,
83、unsigned char *puffin cuff);</p><p> Void sermem_StartWrite (into address);</p><p> Void sermem_Write (unsigned char *puffin cuff);</p><p> Void sermem_StopWrite (void);</p>
84、;<p> Void sermem_WriteBlock (into address, unsigned char *puffin cub);</p><p> Void sermem_Fill (into address, unsigned char bitewing count);</p><p> 你可以在sermem.c和sermem.h文件中找到所有源代碼,它
85、們已被相當好地注釋,很容易理解。這個代碼是為68HC12系列芯片寫的,但是對于68HC11端口實在微不足道。</p><p> 另外一個文件稱為memtest.c,是使用該規(guī)則的一個測試程序。</p><p><b> 狀態(tài)寄存器</b></p><p> 串行EEPROM的一個重要部分就是狀態(tài)寄存器。我認為,你需要使用該寄存器,指出這一
86、點是重要的。該寄存器不僅保持一些你寫時需要的描述數(shù)據(jù),它還包括一個稱為WIP的重要bit,意思是“Write In Progress”。串行EEPROM在它往陣列里保存數(shù)據(jù)時需要一個爆發(fā)時間。盡管可以更短些,但這將花費5毫秒。在你的微控制器上不是依靠一個計時器,你可以檢查WIP標志位的狀態(tài),來獲知什么時候器件已經(jīng)結束寫頁操作并為新數(shù)據(jù)做好了準備。</p><p> Void sermem_StopWrite (
87、void)</p><p><b> {</b></p><p><b> //</b></p><p> // 升高CS信號,導致存儲器開始它的寫周期</p><p> // 然后等待WIP位被清除</p><p><b> //</b>&l
88、t;/p><p><b> Do</b></p><p><b> {</b></p><p> spi_deselect ();</p><p> // 用來選擇EEPROM進行讀狀態(tài)操作</p><p> Spi_select ();</p><
89、p> Spinout (SERMEM_INST_RDSR);</p><p> // 寫入過程(WIP)標志位為1。等它變低</p><p> } While (spiting (SERMEM_INST_RDSR) & 0x01);</p><p> spi_deselect ();</p><p> // 不允許對E
90、EPROM進一步寫入。阻止多余的時鐘信號打擾你的數(shù)據(jù)!</p><p> Sermem_WriteDisable ();</p><p><b> }</b></p><p> 以上我展示了sermem_StopWrite()函數(shù)的執(zhí)行。這個函數(shù)的工作是引起串行EEPROM提交一個之前傳輸過的頁。該函數(shù)升高CS線,然后發(fā)出一個RDSR指令
91、和循環(huán)等待WIP比特直到其為0。注意spi_deselect() 和spi_select()指令在此是必需的。狀態(tài)轉換之所以重要是因為CS線在微控制器和串行EEPROM之間被用作主要的握手線。它是開始和結束操作的信號。</p><p><b> 總結</b></p><p> 串行EEPROM為小型微控制器工程中存儲穩(wěn)定數(shù)據(jù)提供了一條極好的途徑。它們需要少量的I/
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 眾賞文庫僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
評論
0/150
提交評論