View previous topic :: View next topic |
Author |
Message |
Christophe
Joined: 10 May 2005 Posts: 323 Location: Belgium
|
External EEPROM questions |
Posted: Tue Mar 20, 2007 10:22 am |
|
|
Hi,
we are having a new project where we want to read from a typewriter (used by visual impaired people, having 8 braille-keys),
[img]http://www.polarprint.se/download?ID=448[/img] **tags not working, admins **
http://www.polarprint.se/download?ID=448
and store the characters as text. I'm considering storing data in an extenal EEPROM and maybe to SD-card.
Now this is about the external EEPROM. I pretty new to interfacing those, so here are some questions:
* What EEPROM's are most commonly used? (what are good IC's). What chip do you use and why?
* What are supply voltages. We will have 3V3 available.
* Maybe stupid question, but does the IC always has to be powered? (I might switch the supply voltage off in order to save standby current)
* The application is battery powered, so the consumption has to be as low as possible.
* I have to store a text, strings. How large should the memory be? How many pages of text is a 4KByte EEPROM?
* Electrical interfacing goes via I2C. Is it hard to write a driver?
* CCS has some drivers for atmel chips. Are these good chips and drivers?
* Are there chips without the 3 adress bis? What packages are there available?
* Are chips pin compatible with chips that have larger amounts of memory? So can I replace a 4Kbyte chip with a 32 KByte chip?
Thx +
Any kind of ti^ps/advice are welcome! |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1909
|
|
Posted: Tue Mar 20, 2007 11:59 am |
|
|
Consider using a Ramtron FRAM device. It has an essentially unlimited read/write lifetime (it won't wear out like conventional EEPROM). They are available in 3.3V versions. Instead of I2C, use SPI interface - faster than I2C. Easy to write a driver too. Lots of examples available if you have trouble.
As for some of your other questions.....
- You should be able to power one of these things by using a PIC's output, so, yes, you can turn it off to save power.
- Yes, data is retained if the power is turned off.
- Yes, you can drop in a larger replacement and it will be pin compatible with the smaller memory.
- You can store one character per byte of memory. Bear in mind that you'll need a 'separator' character to delineate multiple strings, such as the null character (0x00) or a carriage return or whatever....
- A common package for the FRAM serial memories is a standard 8 pin SOIC. |
|
|
Christophe
Joined: 10 May 2005 Posts: 323 Location: Belgium
|
|
Posted: Wed Mar 21, 2007 1:47 am |
|
|
So an FRAM chip is an EEPROM chip?
About how many pages of text go in 4Kbyte?
Do those FRAM devices work with I2C? My SPI interface is allready taken by another device. (SD card)
btw www.ramtron.com => offline?
on this forum I can't find any example on the FM24 chips.. |
|
|
Ttelmah Guest
|
|
Posted: Wed Mar 21, 2007 5:36 am |
|
|
The FRAM devices are a magnetic store,rather than the charges used in an EEPROM. They are directly software compatible with the I2C EEPROMs, but are vastly faster (remember that writing a page to an EEPROM, takes typically 4mSc, and this can add up to a significant time, if more than a very few bytes are being written), and have vastly higher 'life' (how many times they can be written. EEPROMs, are greeat for data that changes rarely, but if it is changing often, they can easily run out of their write lifetime...
The Ramtron website, functions fine for me.
Count the characters on a page!. Typically a 'page' is normally quoted as around 2000 characters. So,a 4KB device would hold just two pages. I'd be looking at something like a 24LC64, which would hold over 30 pages.
You can get FRAM devices that use I2C, SPI, or parallel interfacing. The Lc64, uses I2C.
Best Wishes |
|
|
Christophe
Joined: 10 May 2005 Posts: 323 Location: Belgium
|
|
Posted: Wed Mar 21, 2007 6:14 am |
|
|
Thanks for the support..
I've allready ordered some FM24LC64 samples ( the 256Kbit memory chips working on 3V3 do not exist yet? strange, why is that?)
Now I will have OR-wire 2 or more chips in order to have more memory. (I'll do that for sure, and might not stuff them)
Perhaps if they develop it later I could replace it?
I 've found a driver on the forum. Does that work with this chip (FM24LC64):
http://www.ccsinfo.com/forum/viewtopic.php?t=24099
Does the driver still work for the IC with FRAM + RTC included? |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1909
|
|
Posted: Wed Mar 21, 2007 8:52 am |
|
|
Here is proven, working code for accessing an I2C FRAM:
Code: | #define WRITE 0
#define READ 1
int8 control_byte = 0xa0;
int8 load_data_from_address(int16 address) {
int8 high_byte, low_byte;
high_byte = address >> 8;
low_byte = address;
i2c_start();
i2c_write(control_byte | WRITE); // write
i2c_write(high_byte);
i2c_write(low_byte);
i2c_start(); // restart
i2c_write(control_byte | READ); // read
low_byte = i2c_read(0); // no ack
i2c_stop();
return (low_byte);
}
int8 load_data_no_address(void) {
int8 data;
i2c_start();
i2c_write(control_byte | READ); // read
data = i2c_read(0); // no ack
i2c_stop();
return (data);
}
void write_one_byte(int16 address, int8 data) {
int8 high_byte, low_byte, ack = 1;
high_byte = address >> 8;
low_byte = address;
while (ack == 1) { // wait until FRAM is ready to write
i2c_start();
ack = i2c_write(control_byte | WRITE);
}
i2c_write(high_byte);
i2c_write(low_byte);
i2c_write(data);
i2c_stop();
} |
You earlier said that you can't use SPI because you are using another SPI peripheral.....you do realize that all you need is an extra /CS line for the FRAM? The FRAM can share the SCK, MOSI, and MISO lines with the other SPI device as long as it has a dedicated (unique) /CS.
If you find that you can use an SPI FRAM, here is (untested) code for it:
Code: | // *******************************************
// spi FRAM code begins
// /CS: pin C1 - to FRAM pin 1
// MISO: pin C5 - to FRAM pin 2
// MOSI: pin C4 - to FRAM pin 5
// SCK: pin C3 - to FRAM pin 6
#define CHIP_SELECT PIN_C1
#define WREN 0x06 // write enable
#define RDSR 0x05 // read status register
#define WRSR 0x01 // write status register
#define READ_EE 0x03 // read instruction
#define WRITE_EE 0x02 // write instruction
int16 local_copy_of_address;
void init_eeprom(void);
void enable_eeprom_write(void);
void enable_eeprom(void) {
setup_spi(SPI_MASTER|SPI_XMIT_L_TO_H|SPI_CLK_DIV_4);
output_high(CHIP_SELECT);
// SPI FRAM requires a 10 ms dead time before it can be accessed
delay_ms(11);
init_eeprom();
}
void enable_eeprom_write(void) {
// send the WREN (write enable) command to EEPROM
output_low(CHIP_SELECT);
spi_write(WREN);
output_high(CHIP_SELECT);
}
void init_eeprom(void) {
// initializes the block protect bits in the eeprom's status register
enable_eeprom_write();
output_low(CHIP_SELECT);
spi_write(WRSR);
spi_write(0x80); // sets bank protect bits to 0, and enables external WP line
output_high(CHIP_SELECT);
}
void write_one_byte(int16 address, int8 data) {
enable_eeprom_write();
output_low(CHIP_SELECT);
spi_write(WRITE_EE);
spi_write(address >> 8); // address MSB
spi_write(address); // address LSB
spi_write(data);
output_high(CHIP_SELECT);
}
int8 load_data_from_address(int16 address) {
int8 data;
local_copy_of_address = address; // save this for any subsequent reads
output_low(CHIP_SELECT);
spi_write(READ_EE);
spi_write(address >> 8); // address MSB
spi_write(address); // address LSB
data = spi_read(0);
output_high(CHIP_SELECT);
return (data);
}
int8 load_data_no_address(void) {
int8 data;
local_copy_of_address++; // increment to point at next location
output_low(CHIP_SELECT);
spi_write(READ_EE);
spi_write(local_copy_of_address >> 8); // address MSB
spi_write(local_copy_of_address); // address LSB
data = spi_read(0);
output_high(CHIP_SELECT);
return (data);
}
// spi FRAM code ends |
Both sets of code are taken from a project of mine. I initially developed (and tested) the code with an I2C FRAM chip, then switched to SPI. I have yet to test the SPI interface but it should work.
I had to bodge the load_data_no_address() function to maintain compatibility with the rest of my code. I2C EEPROMs can sequentially read from memory without actually setting the read address. The SPI versions apparently don't have this feature - that's why I had to keep a 'local' copy of the last address accessed in the FRAM. |
|
|
Christophe
Joined: 10 May 2005 Posts: 323 Location: Belgium
|
|
Posted: Wed Mar 21, 2007 9:14 am |
|
|
So actually you use the CS pin to enable or disable the peripheral? So I'll be using wired OR? with MOSI and MISO pulled up?
SC = 1 : device enabled
SC = 0 : device disabled
In that case I can disable the SD, enable the FRAM en then write to it. That saves me 2 output pins. Thanks for that hint.
What made you change from I2C to SPI ? What are the main differences.
The project will be having a PIC18LF6722, probably running on 4Mhz. |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1909
|
|
Posted: Wed Mar 21, 2007 9:19 am |
|
|
Christophe wrote: | So actually you use the CS pin to enable or disable the peripheral? So I'll be using wired OR? with MOSI and MISO pulled up?
SC = 1 : device enabled
SC = 0 : device disabled
In that case I can disable the SD, enable the FRAM en then write to it. That saves me 2 output pins. Thanks for that hint.
What made you change from I2C to SPI ? What are the main differences.
The project will be having a PIC18LF6722, probably running on 4Mhz. |
/CS = Chip Select. The '/' means 'active low'. To interface any SPI peripheral, you have to set its chip select line low, then do any spi writes/reads, then finally you have to set the chip select line high to 'release' the device.
I changed from I2C to SPI because SPI is much, much faster. |
|
|
Christophe
Joined: 10 May 2005 Posts: 323 Location: Belgium
|
|
Posted: Wed Mar 21, 2007 9:26 am |
|
|
what happens if, accidentually, you both enable the chips and write data to it?
How many chips can you OR-wire?
edit:
btw: How do you power the chips? Do you power the chips from your PIC? Why? why not? |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1909
|
|
Posted: Wed Mar 21, 2007 9:34 am |
|
|
Christophe wrote: | what happens if, accidentually, you both enable the chips and write data to it?
How many chips can you OR-wire? |
Don't do that.
If you want to add more than one FRAM, just assign each a dedicated /CS line. Then make VERY SURE that you only enable (lower) one /CS line at a time. |
|
|
Christophe
Joined: 10 May 2005 Posts: 323 Location: Belgium
|
|
Posted: Wed Mar 21, 2007 9:34 am |
|
|
btw: How do you power the chips? Do you power the chips from your PIC? Why? why not? |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1909
|
|
Posted: Wed Mar 21, 2007 9:36 am |
|
|
They get dedicated power - I don't ever turn them off. The reason? The product isn't battery powered. |
|
|
Christophe
Joined: 10 May 2005 Posts: 323 Location: Belgium
|
|
|
newguy
Joined: 24 Jun 2004 Posts: 1909
|
|
Posted: Wed Mar 21, 2007 9:47 am |
|
|
I've never had to worry about power consumption so I've never really had a close look at that portion of the datasheet before, but.....It appears as though you don't have to worry about it either. The chip automatically enters 'standby' mode when /CS, SCK, and MOSI lines are all high. In standby, it consumes only 1 uA at room temperature. Take a look at Note 2 at the bottom of page 9 of the data sheet. |
|
|
Christophe
Joined: 10 May 2005 Posts: 323 Location: Belgium
|
|
Posted: Wed Mar 21, 2007 10:17 am |
|
|
What do you actually save in that memory?
Is my application I'm going to have to save typed texts, meaning TXT - files. Can you save that on an EEPROM? How can you differ different txt files?
Can you support directories, where you can save your files into?
This smells like creating an own file system.. Is that hard? |
|
|
|