how to read and write to eeprom 24LC32A?
I just got my eeprom chips in today from Parallax and I cannot find any documentation on them on how to hook them up or to read/write to them [noparse]:([/noparse] I need help getting started please [noparse]:)[/noparse]
Comments
I use EEPROMs in a lot of projects; the framework I've attached works fine with the 24LC32.
[noparse][[/noparse]Edit] Added a bit of demo code to the framework -- just to make it absolutely clear.
Post Edited (JonnyMac) : 1/9/2009 1:59:30 AM GMT
I think your request is reasonable for this forum.· Look at the sticky threads at the top of the SX forum.· The thread labeled "Best SX Threads ..." has lots of valuable information posted by others.· There are several posts related to using EEPROMs.· The sticky thread is located at http://forums.parallax.com/showthread.php?p=642725·.
I did some work with EEPROMs a couple of years ago.· I spent a lot of time searching for information on the internet using AltaVista (I prefer it over Google).· I downloaded the data sheet for the EEPROM and studied it.· I couldn't get my code to work until someone on the forum pointed out that there was sample code in the SX tutorial book for an I2C interface.· I hadn't made the connection that a serial EEPROM device uses the I2C protocol.· I got my code working within hours after getting that valuable information.
Good luck on your project.· Please continue to post any questions you might have.
Dave
I know I will probably be told to Google it, but 90% of the time, my searches come up with things that are not exactly what I am looking for and they are not coded in SX/B. I am still learning the SX/B language so I have to ask questions to help me get farther.
The address following Address 0?· It's Address 1.
An address can only hold a Byte, 8 bits.· A·Word is two Bytes, 16 bits.· So, you have to break that into two Bytes (highbyte, lowbyte) and store each in a separate Address.
Post Edit -- If you want to "erase" the contents of an address, then write $FF to it (or 00.)
Post Edited (PJ Allen) : 1/10/2009 12:57:30 AM GMT
The Serial LCD understands everything you send it to be ASCII data; sometimes it's character·code (letters, numerals, etc.), sometimes it's control code (line_feed, carriage return, etc.)
SEROUT'ing·a·decimal 12 (which is really a $0C), the SX knocks out a $0C, a control code for Form Feed.· SEROUT'ing·a "12" makes the SX knock out the character codes for the numerals inside the quote_marks, a $31 and then a $32 for a numeral 1 and a numeral 2.
·
Here is the code :
Now, I have tried to put PUT_EE eeAddr, 12 and it prints on the LCD "<<". If I put PUT_EE, eeAddr, "12" it puts "11" on the LCD. I am guessing it is something wrong with my print sub then? I have been searching the help files and the forum and still cannot quite grasp what is going on.
Here is my updated "print" sub :
I need to be able to....
1 - Save a 0 - 255 number to the eeprom.
2 - Read the number back.
3 - Display the number on the LCD along with some pre-defined text.
4 - Use the number in a few math functions and display the result on the LCD.
That being said, I would start off on in the tutorial section. Download all the labs. Read any and all manuals and books that came with your SX/B - there might be something valuable in there. I know the homework board had a book with it call "What's a Microcontroller" that would be a big help for you as well. The only thing I can suggest is read, read, read.
I forgot to add.
byte, word, int, long - these are all storage sizes and are high level contstructs. This is an 8bit microcontroller so it only understands bytes. Technically a word should be 8 bits since a word is defined as the inherit storage size of the architecture - in this case 8 bits, but I think they treat it as an int with 16 bits.
So, to recap:
bit = 1 binary bit, 1 or 0
nibble = 4 bits or half a byte
byte = 8 bits
char = byte or 8 bits
word = 2 bytes or 16 bits
int = 2 bytes or 16 bits
long = 4 bytes or 32 bits
Unsigned just means that the MSB is used for the value and not a sign bit which doubles your positive range at the sacrifice of your negative range. All storage types (char, word, int, long) can be unsigned or signed.
More editing - sorry
The reason you have to pass the parameter differently is because of the storage size. Again, if you read a bit about how functions are called (low level stuff) you will realize that the called function has to retrieve the parameters from registers (or stack, but that's a different beast). Since the registers are 8 bits only you have to fill two registers in order to pass a word or integer value (it requires 2 moves of data from program memory into registers). On the caller side, the caller has to also know how to retrieve those values, hence why you declare the subs and functions before hand. The compiler will generate code to properly push and pull those parameters based on your declarations and proper usage of PARAM.
Post Edited (soshimo) : 1/10/2009 5:53:08 PM GMT
My suggestion is that you get the LCD'ing right, all on its own.· Get comfortable with displaying some CONstants (CON), VARs, or just plug numbers.· Then you can progress to the I2C reading/writing.·
You can save 255 in one address, but·displaying a number of two or more digits will require parsing, separating,·that number's digits and sending each digit's ASCII code.
Post Edit -- Another member was Replying while I was in the process and my missive here is unrelated.
Quitting is always an option.
Post Edited (PJ Allen) : 1/10/2009 6:03:27 PM GMT
Time to get up and do something else before tackling the EEPROM
One think I found out is that Google does not always have the answer!