\u00a0 \u00a0What is an EEPROM?\u00a0 \u00a0<\/span><\/strong><\/span><\/h3>\n <\/p>\n
EEPROM, pronounced as Double-E-PROM, stands for Electrically Erasable Programmable Read-Only Memory. This kind of memory devices is re-programmable by the application of electrical voltage and can be addressed to write\/read each specific memory location.<\/span><\/p>\nThe EEPROM memory devices have evolved from the old EPROM memories. Which was the previous technology in this area. A typical EPROM has a window on the top side of the IC to allow the ultraviolet rays to reach the memory cells in order to erase the memory. The EPROMs had to be exposed to ultraviolet light for a convenient time period in order to get fully-erased.<\/span><\/p>\n<\/p>\n
You should also know that EEPROM memories are non-volatile. Which means it won’t lose the data contents when the power goes OFF. It can only be erased electrically whether it’s internal within a microcontroller (By Code) or external IC (By Electronic Device). On the contrary, the RAM memory is volatile. Which means it does lose all of its contents when the power goes OFF.<\/span><\/p>\nEEPROMs are fabricated and shipped as standalone IC chips and Microchip Technology has a significant share of this area in the market. External EEPROMs are manufactured to be interfaced in two different ways. There are parallel & serial address\/data lines versions of EEPROMs.<\/span><\/p>\n<\/p>\n
However, we won’t be considering these devices in this tutorial. Instead, we’ll discuss the internal EEPROM memory integrated within the microcontrollers themselves.<\/span><\/p>\nThe internal EEPROM memories (Built-in Within Microcontrollers) can be accessed for reading\/writing operations by code. Writing a few lines of code will enable you of storing and\/or retrieving data from the built-in EEPROM memory. And this is going to be our task in this tutorial. To develop the required firmware to drive this memory module.<\/span><\/p>\n <\/p>\n
\n\u00a0 \u00a0Applications For EEPROMs\u00a0 \u00a0<\/span><\/strong><\/span><\/h3>\n <\/p>\n
Let me give you a quick recap of the features of EEPROM memories before discussing their applications in real-life. A typical EEPROM device regardless of its type (internal\/external) has the following features:<\/span><\/p>\n\n- Electrical erase-ability<\/span><\/li>\n
- Electrical re-programmability<\/span><\/li>\n
- Non-volatile memory locations<\/span><\/li>\n
- Serial\/Parallel interfaces for address\/data lines (For External EEPROMs)<\/span><\/li>\n
- Easy programmatically-controlled memory interface (For Internal EEPROMs)<\/span><\/li>\n<\/ul>\n
With all of these features in mind. What applications do you think are a good fit for EEPROMs?<\/span><\/p>\nWell, there are many situations indeed. I’ll list down some of these and you can think of or search for any further applications. There is a ton of ways in which we can take advantage of the features provided by EEPROMs. And there are countless situations in which we use this kind of memory devices.<\/span><\/p>\n\n- If you’re building a computer system that needs to switch between programs (partially), you should have a memory to store these program instructions. Then you can easily load these instructions to your flash memory when you need to.<\/span><\/li>\n
- Building an embedded system that needs to remember a user-given data even after a power-restart or a power-down condition. Such as a digital lock password-protected money locker. When the power goes OFF, the user’s password must be stored in a safe place.<\/span><\/li>\n
- When you’re building a robot that’s doing a specific mission (scanning, searching, trolling around) where it’s collecting some sort of critical data. It’s a good idea to have a backup copy of this data on your local (internal) EEPROM. In an emergency, you can stream this data via a serial bus to your computer anytime you want.<\/span><\/li>\n
- For a multi-computer system where there are many controllers working together in a robotic system or the like. If there is a sharable data, it’d be a good idea to store it on shared EEPROM via the serial bus (e.g. I2C). Any device can update\/read this data without adding the overhead of sending\/receiving data requests\/updates between all the computers involved.<\/span><\/li>\n
- And much more…<\/span><\/li>\n<\/ul>\n
There are millions of EEPROM chips are being shipped every single year. These devices are actually embedded in almost all electronic devices you might ever know. If it’s not existent as a standalone IC chip, it should be integrated within the embedded computer (e.g. MCU) which controls your device behind the scenes.<\/span><\/p>\nEnough of theory! Let’s get some hands-on experience with a real EEPROM.<\/span><\/p>\n <\/p>\n
\n\u00a0 \u00a0Internal EEPROM in PIC16F87XA\u00a0 \u00a0<\/span><\/strong><\/span><\/h3>\n <\/p>\n
The PIC Microcontroller that we’ve chosen for these tutorials has the following EEPROM features:<\/span><\/p>\n\n- Up-to 256 x 8 Bytes of EEPROM Data Memory<\/span><\/li>\n
- 1,000,000 Erase\/Write Cycles EEPROM<\/span><\/li>\n
- Low-Power, High-Speed EEPROM Memory<\/span><\/li>\n<\/ul>\n
The (data EEPROM & Flash Program) Memory is readable and writable during normal operation (Over The Full VDD<\/sub> range). The EEPROM memory isn’t directly mapped in the register file space. Instead, it’s indirectly addressed through the special function registers (SFRs) dedicated to this job. There are exactly 6 SFRs used to Read\/Write the EEPROM memory:<\/span><\/p>\n\n\n\nEECON1<\/span><\/strong><\/span><\/td>\nEEDATA<\/span><\/strong><\/span><\/td>\nEEADR<\/span><\/strong><\/span><\/td>\n<\/tr>\n\nEECON2<\/span><\/strong><\/span><\/td>\nEEDATH<\/span><\/strong><\/span><\/td>\nEEADRH<\/span><\/strong><\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n\n\n\nEECON1<\/strong><\/span><\/td>\n EECON1 is the control register for memory accesses.<\/span><\/td>\n<\/tr>\n\nEECON2<\/strong><\/span><\/td>\n EECON2 is not a physical register. Reading EECON2 will read all \u20180\u2019s. The EECON2 register is used exclusively in the EEPROM 5-steps write sequence.<\/span><\/td>\n<\/tr>\n\nEEDATA<\/strong><\/span><\/td>\nWhen interfacing to the data memory block, EEDATA holds the 8-bit data for read\/write.<\/span><\/td>\n<\/tr>\n\nEEDATAH<\/strong><\/span><\/td>\nWhen interfacing the program memory block, the EEDATA and EEDATH registers form a two-byte word that holds the 14-bit data for read\/write.<\/span><\/td>\n<\/tr>\n\nEEADR<\/strong><\/span><\/td>\n When interfacing to the data memory block, EEADR holds the address of the EEPROM location being accessed.<\/span><\/td>\n<\/tr>\n\nEEADRH<\/strong><\/span><\/td>\n When interfacing the program memory block, the EEADR and EEADRH registers form a two-byte word that holds the 13-bit address of the program memory location being accessed.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n The EEPROM data memory allows single-byte read\/write operations. The procedure for reading and writing the EEPROM memory locations is simplified by Microchip’s hardware designers. The typical step-by-step procedures for reading\/writing is clearly given in the datasheet. And we’ll discuss them right now in the next section.<\/span><\/p>\n <\/p>\n \n\u00a0 \u00a0Writing \/ Reading Internal EEPROM\u00a0 \u00a0<\/span><\/strong><\/span><\/h3>\n <\/p>\n The exact steps for writing and reading EEPROM data memory locations are fully-listed in the microcontroller’s datasheet (page33). It’s going to be our own task to convert these step-by-step instructions to the c-code firmware. But, here I’ll list these steps as is<\/span><\/p>\n\u00a0Steps For Writing To EEPROM\u00a0<\/span><\/h4>\n\n- If step 10 is not implemented, check the WR bit to see if a write is in progress.<\/span><\/li>\n
- Write the address to EEADR. Make sure that the address is not larger than the memory size of the device.<\/span><\/li>\n
- Write the 8-bit data value to be programmed in the EEDATA register.<\/span><\/li>\n
- Clear the EEPGD bit to point to EEPROM data memory.<\/span><\/li>\n
- Set the WREN bit to enable program operations.<\/span><\/li>\n
- Disable interrupts (if enabled).<\/span><\/li>\n
- Execute the special five instruction sequence:<\/span>
\n\u2022 1,2) Write 55h to EECON2 in two steps (first to W, then to EECON2)<\/span> \n\u2022 3,4) Write AAh to EECON2 in two steps (first to W, then to EECON2)<\/span> \n\u2022 5)\u00a0 \u00a0 Set the WR bit<\/span><\/li>\n- Enable interrupts (if using interrupts).<\/span><\/li>\n
- Clear the WREN bit to disable program operations.<\/span><\/li>\n
- At the completion of the write cycle, the WR bit is cleared and the EEIF interrupt flag bit is set. (EEIF must be cleared by firmware.) If step 1 is not implemented, then firmware should check for EEIF to be set, or WR to clear, to indicate the end of the program cycle.<\/span><\/li>\n<\/ol>\n
\u00a0Steps For Reading From EEPROM\u00a0<\/span><\/h4>\n\n- Write the address to EEADR. Make sure that the address is not larger than the memory size of the device.<\/span><\/li>\n
- Clear the EEPGD bit to point to EEPROM data memory.<\/span><\/li>\n
- Set the RD bit to start the read operation.<\/span><\/li>\n
- Read the data from the EEDATA register.<\/span><\/li>\n<\/ol>\n
In the next section, we’ll write a c-code implementation for each of these procedures. We’ll be using these procedures in the practical LAB testing hereafter in this tutorial.<\/span><\/p>\n | | | | | | | | | | | | | | | | | |