PDA

View Full Version : 93c46 Eeprom Writing/reading Help



EDWARD
- 13th June 2005, 04:17
I WAS AT THIS Thread just a minute ago and i wish i knew if dark solved his problem.
http://www.picbasic.co.uk/forum/showthread.php?t=1214

93c46 datasheet:
http://leonardo.caltech.edu/~ee5x/ee50/homework/hw6/93c46.pdf


i have the same problem, but i dont know whether its my reading or writing that is flawed. I am trying to write 3 different byte sized variables to the 93c46. i have attached a pic that shows how it is all connected. I dont think that there are any pull up resistors on the CLK or CS line, not sure if this is a problem. I simply need someone to correct my subs.

here are my eeread and eewrite subs.

include "modedefs.bas"
DEFINE SHIFT_PAUSEUS 500

CS var PORTB.1 ' Chip select pin
SCK var PORTB.2 ' Clock pin
SI var PORTC.6 ' Data in pin
SO var PORTC.7 ' Data out pin

B0 var byte '<------- data to be written
addr var BYTE '<------ eeprom memory location 1,2,3

d var byte
t var byte
ed var byte

ADCON1=7 ' set all analog pins to digital
TRISA=%011000 'PORT A
TRISB=%11110001 'PORT B
TRISC=%10100000 'PORT C




eeread:

for addr = 1 to 3 'eeprom address


CS = 1
Shiftout SI, SCK, MSBFIRST, [%110\3, addr\6]
Shiftin SO, SCK, MSBPOST, [B0]
CS=0


if addr = 1 then
d = B0
endif

if addr = 2 then
t = B0
endif

if addr = 3 then
ED = B0
endif

pause 10
next addr
return







ewrite:
for addr = 1 to 3

if addr = 1 then
B0 = D
endif

if addr = 2 then
B0 = T
endif

if addr = 3 then
B0 = ED
endif

CS = 1 ' Enable serial EEPROM
Shiftout SI, SCK, MSBFIRST, [%10011\5, 0\7] ' Send write enable command
CS = 0

PAUSE 10

CS = 1 ' Enable
Shiftout SI, SCK, MSBFIRST, [%101\3, addr\6, B0] ' Send address and data
CS = 0
pause 10
next addr
Return



the ports that the CLK and CS are connected to (portb.1 and portb.2) have programmable weak internal resistors if necesary (Option_reg.7) BUT SI and SO dont. they are on port C.6 and c.7

mister_e
- 13th June 2005, 04:25
As i remind some PM Darkman solved his problem and much more.
FIRTS of all add


LOW CS
pause 50

before your main loop.
those are working. Just change your Shiftin/Shiftout statements


eeread:
CS = 1 ' Enable serial EEPROM
Shiftout DI, CLK, MSBFIRST, [%110\3, addr\6]
Shiftin DO, CLK, MSBPOST, [B0] ' Read data
CS = 0 ' Disable


' Subroutine to write data at addr in serial EEPROM
eewrite:
CS = 1 ' Enable serial EEPROM
Shiftout DI, CLK, MSBFIRST, [%10011, 0\4] ' Send write enable command and dummy clocks
pause 10
CS = 0 ' Disable

CS = 1 ' Enable serial EEPROM
Shiftout DI, CLK, MSBFIRST, [%101\3 ,addr\6,B0]
pause 10
CS = 0 ' Disable


You don't need any resistor

EDWARD
- 13th June 2005, 07:43
yo dude, thanks alot for the reply. ill try it out tommorow, 2.40 am right now. and let ya know if it worked for me. i have been bashing my brain trying to understand how to use the instructions.

EDWARD
- 13th June 2005, 20:40
the code you gave me works with just a minor tweak. i had to make the eeproms address (addr) increment by 2. so i used addr= 0, addr=2, addr=4,...etc..

heres the working code. refer to my 1st post for the port settings,variables, n stuff.


eeread:

for addr = 0 to 5 step 2 'eeprom address 0

'read from eeprom
CS = 1
Shiftout SI, SCK, MSBFIRST, [%110\3, addr\6]
Shiftin SO, SCK, MSBPOST, [B0]
cs=0 ' Disable


if addr = 0 then
d = B0
endif

if addr = 2 then
t = B0
endif

if addr = 4 then
ED = B0
endif

pause 10
next addr
return







eewrite:
for addr = 0 to 5 step 2

if addr = 0 then
B0 = D
endif

if addr = 2 then
B0 = T
endif

if addr = 4 then
B0 = ED
endif

CS = 1 ' Enable serial EEPROM
Shiftout SI, SCK, MSBFIRST, [%10011, 0\4] ' Send write enable command
CS = 0

pause 10

CS = 1 ' Enable
Shiftout SI, SCK, MSBFIRST, [%101\3, addr\6, B0] ' Send address and data
CS = 0
pause 10
next addr
Return

end



thank you SO much!!!