0
\$\begingroup\$

I am wanting to add some readable/writeable memory to my ATmega8/attiny project where I can store data, recall the stored data, then overwrite the stored data. The stored data must be able to be retrieved even after a power loss. The data types I am wanting to store are character arrays (strings) that are stored inside of a type of lookup table (kind of like a hash in which key:value pairs are used).

I know that flash memory is used (or EEPROM), but I am not exactly sure of a part number to be looking for that is compatible with a ATmega8/attiny nor which protocols/pins it uses on the IC.

Likewise how does one normally interact with an external storage IC? Are there specific protocols that are used to do the task? And how about specific libraries to interact with these pieces of hardware.

Over all I am wanting to know:

  • What are some part numbers for flash/eeprom storage devices compatible with an ATmega8/attiny
  • How does these external storage ICs normally hook up/interact with eachother
  • What protocols do they use for communication
  • If there are libraries to simplify communications between ICs

Thanks!

\$\endgroup\$

closed as too broad by PeterJ, nidhin, Daniel Grillo, Ricardo, Nick Alexeev Feb 24 '16 at 20:06

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    \$\begingroup\$ There are 1000's of SPI and I2C memory ICs which would work. Some are Flash, others are EEPROM. The same manufacturer which makes your ATmega makes them (Atmel), along with many others like Microchip, ST, NXP, TI, etc, etc, etc. \$\endgroup\$ – brhans Feb 23 '16 at 23:03
  • \$\begingroup\$ @brhans, thanks. How do I know which ICs would work? Is there a compatibility chart, or is it more about which protocol the storage IC uses? \$\endgroup\$ – randy newfield Feb 23 '16 at 23:08
  • \$\begingroup\$ The latter. Your ATmega/ATtiny can probably do SPI or I2C; there are many non-volatile memories that interface via SPI or I2C. Digikey parametric tables are your friend. \$\endgroup\$ – uint128_t Feb 23 '16 at 23:22
3
\$\begingroup\$

Internal EEPROM

atmega8/attiny microcontrollers have up to 512 bytes internal EEPROM, if that's enough for your application, just use it. Otherwise, you might want to use the internal EEPROM for keys and pinters, and the external one for strings.

External EEPROM

They are commonly available in sizes up to 1 Mbit or maybe 2. Check the voltage requirements, decide the size and the interface.

Pick one from the Atmel AT24C series, they'll be most probably OK.

External Flash

If you'd need more than 256 kbyte, then it should be a serial flash, available up to 1 Gbit. There are more constraints here, as they usually have SPI only, no I2C. Supply and I/O voltage is in the 1.7V/3.3V range, if your ATmega is powered with 5V, you might get away with wiring MISO directly, and using simple voltage divider resistors for the oher lines.

For more than 1 Gbit, use a SD card, it can be accessed with SPI too.

Interface: I2C or SPI

I2C (sometimes called TWI) requires only 2 pins. You can connect more I2C devices to one bus, as long as they have different addresses.

Just connect SCL with SCL, SDA with SDA, add a pullup resistor to both of them, 1 kOhm for 3.3V, 1.6 kOhm for 5V. Configure them as open drain outputs. There are code examples in the atmel datasheets.

The protocol for accessing EEPROMS is dead simple, put the device address followed by the memory address and the actual data to write, or initiate an I2C read after the address bytes to read. Always check the returned NACK bit to see whether the memory is still busy storing the previous byte.

SPI

There are four lines: Clock, Chip Select, MISO (master in slave out) and MOSI (master out slave in). No pullups required, all 4 are unidirectional, MISO goes from memory to processor, the other 3 from processor to memory. The protocol is somewhat more complicated than I2C, especially for writing flash.

\$\endgroup\$
  • \$\begingroup\$ Thank you for this write up you have answered all my questions. I only need around 512kbyte (possibly up to 1mbyte) or so of storage, so I will look into both flash with SPI or EEPROM with I2C and see which will suit my project better. Thanks again. \$\endgroup\$ – randy newfield Feb 24 '16 at 22:15
  • \$\begingroup\$ You can connect two AT24CM02 eeproms to a single I2C bus, that would give you 512 kbytes. It's the simplest solution both hardware and software-wise. OTOH, flash would be much cheaper if you plan to sell more than a few hundred units. \$\endgroup\$ – berendi Feb 25 '16 at 11:08

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