&^%)(*$#%# wordwrapping ^&%##$(*!
hi Wouter,
That listing is not Forth, just a formatted diagnostic I quickly wrote
so you can see the traffic. Of course bytes are bytes so it helps to
know if we are reading or writing them, that's all.
The actual code snippets are;
: CMD ( data cmd -- res )
ON SDCS \ assert SD CS (in case it isn't yet asserted)
SD@ DROP \ dummy read - discard result
3Fh AND 40h OR SD! \ encode cmd and send (cmd used from stack)
DUP 18h SHR SD! \ send msb of data
DUP 10h SHR SD! \ next byte
DUP 8 SHR SD! \ next byte
SD! \ send last byte (SD! only uses byte)
95h SD! \ dummy checksum (to suit CMD0)
RES@ \ read the result onto the data stack
;
\ Initialize SD CARD and return with ocr or false
\
: InitSdCard ( -- ocr | false )
OFF SDPWR \ turn off SD CARD POWER (I/O to VSS)
5 ms \ 5ms delay
ON SDPWR \ turn on power
5 ms \ 5ms delay
200 0 TIMER ! \ 200ms timeout for fault handling
\ begin sending CMD0(0) until res=1
BEGIN ?TIMEOUT 0 0 CMD 1 = UNTIL
\ begin sending ACMD41(0) until res = 0
BEGIN ?TIMEOUT 0 41 ACMD 0= UNTIL
\ card may be busy - keep trying for CMD58(0)
BEGIN 0 58 CMD 0= UNTIL
SD4@ \ read 4 bytes of the ocr onto data stack
GETCID GETCSD \ read CID and CSD as well
OFF SDCS \ turn off chip select
;
*Peter*
armqamp wrote:
>Peter,
>
>been away for a week, but now busy again :)
>Your code looks good only I'm not that familiar with Forth.
>Can you shortly explane what happens when you do a r.. or w.. ? I
>understand that this are the read and write commands, but is it a
>function ore something or does it just writes or reads bytes from the
>SPDR (data register)?
>Message
Re: SPI / SD initialization sequence - my way
2005-10-25 by Peter Jakacki
Attachments
- No local attachments were found for this message.