Connecting and code for 4KB EEPROM 24LC32A
chris jones
Posts: 391
Hello
i have a basic stamp 2 board of education and i was needing help connecting the chip and some simple code to read and write to the chip.
i have a basic stamp 2 board of education and i was needing help connecting the chip and some simple code to read and write to the chip.
Comments
' {$STAMP BS2}
'Code by Shaun Wilson November 01/99
'This is code writes data reads data to 25LC640 64K EEPROM and
'displays it in the debug screen. It will give you in idea of
'how to read and write data to the EEPROM. To use it in your
'specific app just insert the subroutines into you code
'
Constants
WRSR_EERPOM CON $01 'write status register
WRITE_EEPROM CON $02 'write data to memory beginning at selected address
READ_EEPROM CON $03 'read data from memory beginning at selected adress
WRDI_EEPROM CON $04 'Reset the write enable latch
RDSR_EEPROM CON $05 'read status register
WREN_EEPROM CON $06 'set the write enable latch
Serdata CON 2 'serial data in/out
SerClk CON 1 'Serial clock input
'
Varibles
EEPROM_data VAR Byte 'data
Status_register VAR Byte 'read status byte
EEPROM_busy VAR Status_register.LOWBIT 'first bit of the read status
address VAR Word '
'
Program
address = 0 'address to start writing data to
EEPROM_data = $AA 'data to write to EEPROM
main:
DEBUG " Writing ", HEX EEPROM_data, " to location ",HEX address DIG 3,HEX address DIG 2, HEX address DIG 1, HEX address DIG 0, " of the EEPROM", CR
GOSUB writeEEPROM 'subroutine to write data to EEPROM
IF address > 20 THEN readEEPROM 'only right to the first 20 locations
address=address+1 'counter to increment the memory address
GOTO main
'
Subroutines
WriteEEPROM:
GOSUB EEPROMreadstatus 'check to see if the EEPROM is busy
IF EEPROM_Busy =1 THEN WriteEEPROM 'if its busy loop until its not
SHIFTOUT SerData,SerClk,MSBFIRST,[noparse][[/noparse]WREN_EEPROM] 'tell the EEPROM you want to
'set the write enable latch
'Tell the EEPROM you want to write to it, send the 16bit address to write to,
'and send a byte of data to write to that location
SHIFTOUT SerData,SerClk,MSBFIRST,[noparse][[/noparse]Write_EEPROM,Address\16,EEPROM_data\8]
RETURN
EEPROMreadstatus:
'send the command to EEPROM that a device wants to read the status register
SHIFTOUT SerData,SerClk,MSBFIRST,[noparse][[/noparse]RDSR_EEPROM]
'return the byte containing the status of the read register
SHIFTIN SerData,SerClk,MSBPRE,[noparse][[/noparse]Status_register\8]
EEPROM_busy = Status_register
RETURN
ReadEEPROM:
address =0 'set address back to 0
PAUSE 10
FOR address = 0 TO 30 'read 30 locations of the EEPROM
'send command to EEPROM that a device wants to read data from a memory location
SHIFTOUT SerData,SerClk,MSBFIRST,[noparse][[/noparse]READ_EEPROM,Address\16]
'returns a byte of data from the EEPROM
SHIFTIN SerData,SerClk,MSBPRE,[noparse][[/noparse]EEPROM_data\8]
DEBUG " The data in location ", HEX address DIG 3,HEX address DIG 2, HEX address DIG 1, HEX address DIG 0, " of the EEPROM is ",HEX EEPROM_data, CR
NEXT
GOSUB done
RETURN
done:
DEBUG " Done "
PAUSE 1000
GOTO done
Serdata CON 1 'serial data in/out
SerClk CON 2 'Serial clock input
Here is the link to the datasheet. Read it first.
Your code has Serdata for both input and output.
This EEPROM has separate signals·for input and output.
Aslo make sure all you other (EEPROM)·pins are properly conected and your timing is correct also.
Minor addition - if your code "reads EEPROM status" ( and yours at present time·cannot·for the above reason) you should add a DEBUG command and "print it out". That way you know for sure what the hardware is doing.
Post Edited (vaclav_sal) : 9/28/2009 10:44:42 PM GMT
24LC32A
ALSO note this is the link that a parallax tech gave me and whats listed with the chip
http://www.parallax.com/Portals/0/Downloads/docs/prod/compshop/24LC32A.pdf
Check out another thread here - it has some hardware info in it.
The key here is - you are dealing with two different devices and need to have correct hardware setup before you start coding.
It will save you time in the long run and you will avoid lots of frustration and disappointments.
PS I think ( but I may be confused with another chip) you can set all of the address pins to OPEN, thus saving some pesky wiring, and have the corresponding address scheme. ·But I am not sure, check it in the spec sheet first.
Never mind - I was wrong. You need to connect the address pins.
Up to eight devices may be connected to the same bus
by using different Chip Select bit combinations. These
inputs must be connected to either VCC or VSS.
Post Edited (vaclav_sal) : 9/28/2009 11:16:03 PM GMT
[noparse][[/noparse] I love 'magic numbers.' ]
SDA is P0, SCL is P1 and the device's chip_select number·should be configured as '00'.
PS My C code is always full of "MN's "!
i get a blank screen when i run this program is there something i need to add
the only thing i can think of isd that my cables are hooked in wrong does anyone have a basic stamp homework board that a screenshot can be taken and posted.
Nothing has to be added.
The program posted uses DEBUGs.· If your BoE programs OK, then why won't the DEBUGs go?· You may need to make sure that your DEBUG window COM Port is appropriate.
I didn't write the program on the fly, untested; it works.· My suggestion is that you strategically place some DEBUG statements within the program [noparse][[/noparse]e.g.·from the top·-- DEBUG "Starting...", CR ] so that you can monitor its progress and determine where you're cratering.
Check your wiring, re-check it, and then check it again.
i have been up all night beating myself up on this issue i have rewired the board about 100 times i think and still nothing.I also uncommented some debug statements befor the sub calls and it displays text in the debug window.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Don't worry. Be happy
Which EEPROM are you trying to use?
·
4KB EEPROM 24LC32A
i am sorry about any mixup but the subject of the post is 4KB EEPROM 24LC32A
http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/vol5/col/nv115.pdf
http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/vol5/code/nv115.zip
The zip has a 24C32 demo.· If it won't go, I cannot help further.
Thanks Agian
Chris Jones
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Don't worry. Be happy
Can you run this "program"?
Main:
DEBUG "Test",cr
end
Main:
DEBUG "Test",cr
end
How about you take a good picture of your set-up and post that?· A blurry photo or one lacking detail won't help, but anyway.
This isn't rocket science and it's not about a "bad batch" of "chips."· Something·is missing·or·there's some other mistake.
i hope this helps
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php