【文章內(nèi)容簡介】
lecting 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 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. This is a mon oversight, and a good source of bugs!Cycle lifeSerial EPROM’s are typically rated 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. 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. SoftwareAs you can see, wiring up an SPI based EEPROM to the SPI port is relatively simple. Nothing es for free, however, and you will find the software mands needed to work with the SPI memory is a little more plex than just doing memory writes. The basic operation of the SPI based EPROM’s is to lower the CS line, send a mand, such as WRITE, followed by an address and the data, 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 don39。t want to miss!Serial EPROM’s allow you to write in 39。page39。 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 what you wanted to do!I have written a set of routines in Image craft 39。C39。 that deal with the serial EPROM’s. I have included links to the source below. The software is structured in a simple way. There is an initialization routine, which sets up the SPI port appropriately. It also defines read and write operations. The read/write operations function the same basic way. You start the operation by calling the sermem_StartRead () function, giving the initial address. Then, you issue a series of sermem_Read () mands. 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.The Write versions do the same basic functions. Here are the function prototypes from the sermon files: // Copyright 1998 (c) Kevin W Ross, all rights reserved//// Acpanies and defines some of the basic information needed to// Deal with the serial EEPROM memories.////// Device Profiles Here are the variables needed for each specific type of// chip. Some have different page sizes and data sizes//Void sermem_Initialize ()。Void sermem_StartRead (into address)。Void sermem_Read (unsigned char *puffin cuff)。Void sermem_StopRead (void)。Void sermem_ReadBlock (into address, unsigned char *puffin cuff)。Void sermem_StartWrite (into address)。Void sermem_Write (unsigned char *puffin cuff)。Void sermem_StopWrite (void)。Void sermem_WriteBlock (into address, unsigned char *puffin cuff)。Void sermem_Fill (into address, unsigned char bitewing count)。You can find the full source code in and , which are fairly well mented and pretty easy to follow. This code is written for the 68HC12 series of chips, but is really trivial to port to the 68HC11 (an excursive left to the reader!