Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
09/05/02 17:51
Read: times


 
#28662 - 1-wire eeprom problem. can anyone help?
I'm trying to use a 1-wire eeprom for a project I'm working on... The mcu is an atmel 4051 (12 clock cylces per standard instruction cycle) running at 12mhz... Which, if I'm not being silly with the math, 1us per instruction cycle. My eeprom seems to be responding to reset/presence pulses, but I can't seem to read/write data from it properly. The eeprom is a Dallas DS2430A whose instruction sequence is reset-rom-memory-data. I'm not dinking with the rom just yet (it's the only device on the bus), so the rom command I'm using is simply 'CC' (skip rom) The only data commands I'm using are -
Read data - 'F0'
Write data to scratchpad - '0F'
Read scratchpad - 'AA'
and Write scratchpad - '55' (which then requires a validation key of 'A5'
The eeprom does seem to be responding... When I remove my verification routine, the program will continue normally, but it always reads unusable data from the eeprom, no matter what I write. If I put the verification routine in, it continually fails verification & tries to rewrite indefinitely.

I keep thinking, I *must* have something off on the sending or recieving data timing. I know the reset pulse is working, because if I remove the eeprom and lock the port bit high or low either one, it will lock up waiting for a presence pulse (I don't have a timeout routine built in yet). So, here are the routines I'm using:
Basically, all they're supposed to do is read 10 memory addresses from 30h to 3ah and save them to eeprom, then read from eeprom to those same memory addresses. The memory addresses 40h through 4ah are all unused, so I just used them for the dupe addresses for the verify routine. The delay routines are strictly intended to be useless junk that takes up the given number of microseconds (instruction cycles).
Keep in mind, this is my first attempt to do 1-wire interfacting, so I'm sure I did some silly mistake that's going to be horribly obvious to you guys, so please don't rip me for my terrible code structure or for whatever silly mistake I made! I'm learning :)


READ_EEP:
CLR TR0
mov R0,#2fh
mov addrttl,#10d
acall RESETEEP
mov A,#CCh
acall sendedat
mov A,#F0h
acall sendedat
mov A,#00h
acall sendedat
READ_EEPx:
acall readedat
inc r0
mov @r0,A
djnz addrttl,READ_EEPx
acall RESETEEP
setb TR0
ret

WRITE_EEP:
CLR TR0
mov r1,#3fh
mov r0,#2fh
mov addrttl,#10d
acall RESETEEP
mov A,#CCh
acall sendedat
mov A,#0Fh
acall sendedat
mov A,#00h
acall sendedat
WRITE_EEPx:
inc r0
mov a,@r0
acall sendedat
djnz addrttl,WRITE_EEPx
VERIFY_EEP:
mov addrttl,#10d
acall RESETEEP
mov A,#CCh
acall sendedat
mov A,#AAh
acall sendedat
mov A,#00h
acall sendedat
VERI_EEPx:
inc r1
acall readedat
mov @r1,A
djnz addrttl,VERI_EEPx
mov addrttl,#10d
mov r1,#3fh
mov r0,#2fh
VERIEEPLP:
inc r1
inc r0
mov A,@r1
mov B,@r0
cjne a,b,WRITE_EEP
djnz addrttl,VERIEEPLP

acall RESETEEP
mov A,#CCh
acall sendedat
mov A,#55h
acall sendedat
mov A,#A5h
acall sendedat
setb EPPORT.EPBIT
setb TR0
mov B,#2d
acall PAUSE
acall RESETEEP
ret

RESETEEP:
clr EPPORT.EPBIT
acall WAIT500us
setb EPPORT.EPBIT
INITEPLP:
jb EPPORT.EPBIT,INITEPLP
INITEPLP2:
jnb EPPORT.EPBIT,INITEPLP2
ret

wait10us:
push a
MOVC A,@A+DPTR
pop a
ret

wait60us:
push A
mov A,#0
mov A,#50d
here:
djnz a,here
pop A
ret

WAIT500us:
push A
mov A,#245d
herea2:
djnz a,herea2
mov A,#245d
herea3:
djnz a,herea3
pop A
ret

readedat:
push b
mov B,#8d
readeloop:
clr EPPORT.EPBIT
acall wait10us
setb EPPORT.EPBIT
nop
setb c
jb EPPORT.EPBIT,readeepok
clr c
readeepok:
rrc A
acall wait60us
acall wait60us
djnz B,readeloop
pop b
ret

sendedat:
push b
mov B,#8d
sendeloop:
clr EPPORT.EPBIT
acall wait10us
jnc sendeep0ok

sendeep1ok:
setb EPPORT.EPBIT
acall wait60us
acall wait60us
djnz B,sendeloop
jmp sendeepover

sendeep0ok:
acall wait60us
setb EPPORT.EPBIT
rrc A
acall wait60us
djnz B,sendeloop
sendeepover:
pop b
ret


List of 3 messages in thread
TopicAuthorDate
1-wire eeprom problem. can anyone help?            01/01/70 00:00      
RE: 1-wire eeprom problem. can anyone help?            01/01/70 00:00      
RE: 1-wire eeprom problem. can anyone help?            01/01/70 00:00      

Back to Subject List