I have used EEPROM to store data in embedded systems. I would like to know about the pattern of RAM and SD cards which were used to store data. Is it that complex in terms of using RAM or SD cards? I trust it must be a purpose-oriented choice of using RAM/EEPROM/SD cards.

I have two questions to ask:

  1. How is data storage different in these two from EEPROM as in EEPROM we can access byte wise 'read' and 'write'?

  2. How different is RAM and SD cards apart from the speed of transactions?

  • \$\begingroup\$ You do know that you're asking about three different technologies, right? And even more if you take into account all the different types of RAM. \$\endgroup\$ – Ignacio Vazquez-Abrams Apr 16 '14 at 7:09
  • \$\begingroup\$ yes @IgnacioVazquez-Abrams.I am expecting a brief comparison or generalized view on how RAM or SD cards are used in Embedded systems. \$\endgroup\$ – Rookie91 Apr 16 '14 at 7:13
  • \$\begingroup\$ I wonder if there are significant differences beyond obvious: RAM loses its content with loss of power and SD is detachable. \$\endgroup\$ – Vovanium Apr 16 '14 at 8:08

You already probably know that RAM loses his contents on a power loss (unless it is backed up by a cell battery or SuperCap), and EEPROM and SD cards are non-volatile, meaning they retain their contents over a power loss.

The other major differences are the way they are accessed, and how fast.

RAM is by far the easiest to access, and also the fastest -- as fast as tens or hundreds of nanoseconds. Furthermore, unlike non-volatile memory, read and write times are the same. In general, it is also the easiest, assuming it is either internal to the microcontroller, or connected to the microcontroller using a parallel bus designed for that purpose.

RAM is usually accessed directly, but it depends on the size of the microcontroller's address bus. 8 and 16-bit microcontrollers typically have a 16-bit address bus, meaning they can access up to 2^16 or 65536 bytes of RAM directly. A few 8-bit systems have much more than 64K of RAM -- addressed using a page register, which determines which bank of 64K RAM is to be accessed. This means you can't for example have an array in C over 64K bytes, unless you have a very clever compiler that makes this scheme transparent. 32-bit microcontrollers do not have this restriction, and can address up to 4 GB of RAM directly.

EEPROM is probably the next easiest to access. Again, it can be either internal to the microcontroller, or external, usually accessed using a I2C or SPI bus. If it is internal to the microcontroller, it is usually accessed through a set of special registers, rather than being mapped to a separate block of memory (although there are exceptions to this). It is almost always organized in blocks, e.g. 512 bytes each, since before you can write to the EEPROM, the corresponding blocks have to be erased first.

EEPROM memory will typically be a few to several KB's of memory, much smaller than the RAM available. The EEPROM might require setting up special registers in the microcontroller to gain access to the EEPROM, e.g. writing two special values to a register in a row, thus unlocking access to the EEPROM. This is done so a runaway program cannot write to the EEPROM accidentally.

Access to internal EEPROM will be in the microsecond range for reading, and perhaps several tens of milliseconds for writing since the block of EEPROM must be erased first. There are limits to the number of times an EEPROM can be erased, anywhere from 100 times to 100,000 or so. To get around this limitation, wear-leveling can be used to move data written frequently around to different blocks.

If the EEPROM is external to the microcontroller, it will require setting up both the address and data to be sent in the I2C or SPI registers. Most EEPROMs have a block mode, meaning once you set up the address, you can send consecutive bytes to the EEPROM and it will increment an internal address register.

SD cards are the most complicated. They are connected using either an SPI interface, or a proprietary 4-bit interface. In either case, there is a fairly complicated protocol for first identifying the type of SD card and initializing it. Access to the SD card is in sectors, or blocks of 512 bytes -- so if you want to write just one byte to the SD card, you have to read the entire sector, modify the byte, and write in back. Access time for SD cards can be a few milliseconds for reading, and in the tens of milliseconds for writing (since once again the sectors must be erased before writing).

Wear leveling is already provided in the brand-name SD cards, such as SanDisk and Kingston. A tiny processor inside the SD card handles wear leveling for you.

If the SD card must be accessible from a PC, then you cannot just read and write raw sectors randomly, but must use a file system such as FAT16 or FAT32. This will require including the appropriate firmware in the microcontroller to implement one of these file systems.


Not the answer you're looking for? Browse other questions tagged or ask your own question.