• AVR Freaks

LockedMMC or SD card in SPI mode

Page: << < ..678910.. > >> Showing page 6 of 14
Author
Guest
Super Member
  • Total Posts : 80503
  • Reward points : 0
  • Joined: 2003/01/01 00:00:00
  • Location: 0
  • Status: online
RE: MMC or SD card in SPI mode 2005/12/02 08:23:17 (permalink)
0
Thanks asmallri for your confirmation. Both my mmc and sd cards are formatted fat16 - and readable by a PC. I am starting to wonder about my hardware. Everytime I load the zeroth (the MBR) sector of the SD card I get the same thing. It is almost all zeros, with about 15 bytes of hex data IN THE MIDDLE of the sector, followed by a 0x55AA as the last two bytes. It seems to read the same value every time. Different SD cards exibit the same problem. Also, if I read the second sector, I get different (but wrong) data. This time - ALL zeros.

I am using a hex editor on the PC to verify the actual contents of the SD card. There are several that can read individual sectors off a disk (or card). Here is the one I am currently using: www.sf-soft.de/winhex

My hardware is like this. 5v 18f452 - SPI ports to the 3.3v MMC card, with resistor voltage dividers so the output doesn't hurt the mmc. The data out of the mmc is easily read when connected directly to the input of the PIC SPI. This works fine with the mmc. Reads the fat16, reads the directory, gets the mp3 files and plays them fine on the V1001 decoder. But several other SD cards are giving me problems.
asmallri
Super Member
  • Total Posts : 1864
  • Reward points : 0
  • Joined: 2004/05/26 09:00:05
  • Location: Perth, Australia
  • Status: offline
RE: MMC or SD card in SPI mode 2005/12/02 19:15:15 (permalink)
0
Did you solve the level shift problem beteen the SDO out of the card and SDI in of the PIC? If not then I would not be surprised with the results you are getting.

Regards, Andrew

http://www.brushelectronics.com/index.php?page=software
Home of Ethernet, SD Card, and Encrypted Serial and USB Bootloaders for PICs!!
upand_at_them
Super Member
  • Total Posts : 765
  • Reward points : 0
  • Joined: 2005/05/16 07:02:38
  • Location: Pennsylvania
  • Status: offline
RE: MMC or SD card in SPI mode 2005/12/02 19:27:48 (permalink)
0
Ugh!

Dennis,

Please RE-read my previous post where I said that the free version of WinHex will NOT read the MBR.

Mike
Guest
Super Member
  • Total Posts : 80503
  • Reward points : 0
  • Joined: 2003/01/01 00:00:00
  • Location: 0
  • Status: online
RE: MMC or SD card in SPI mode 2005/12/02 21:18:26 (permalink)
0
The free version of WinHex I have, 12.7 SR-1 reads the MBR just fine. Using the menu bar at top, go to Position, Sector, and select sector=0. When using the 32meg MMC card, the MBR read by WinHex and the PIC match. On the 1Gb SD card, WinHex reads the MBR fine, the PIC reads junk - as I described above.

Regarding the question of the level shift for the 3v output of the SD, into the 5v PIC, I don't think that is the problem. To verify this, I tried a different circuit, ran the PIC at 3.3v and wired directly to the MMC. Using my same code, the results were exactly the same.

Are any pull up or down resistors required between the SD and the PIC? I tried a pull up on the SPI data leads, but that made no difference.
asmallri
Super Member
  • Total Posts : 1864
  • Reward points : 0
  • Joined: 2004/05/26 09:00:05
  • Location: Perth, Australia
  • Status: offline
RE: MMC or SD card in SPI mode 2005/12/03 00:05:38 (permalink)
0

Hi Dennis,

I think you might be chasing your tail. Here are a couple of dumps from a SD256 card formatted with FAT16.

The first sector is the MBR, the first sector of the disk (sector 0 or 1 depending on your frame of reference). The first location is not an 0xEB or 0xE9 so this is not the boot sector we are looking. We need to examine the partition tables located at offset 0x01BE in this sector. From this we can see only a single partition has been defined (so far). This partition table contains the sector address for the Partition boot sector. This information is located at offset 8 to 11 in the partition table.

Sector 0:
00000000 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000010 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000020 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000030 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000040 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000050 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000060 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000070 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000080 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000090 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000000A0 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000000B0 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000000C0 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000000D0 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000000E0 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000000F0 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000100 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000110 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000120 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000130 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000140 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000150 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000160 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000170 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000180 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000190 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000001A0 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000001B0 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 ................
000001C0 - 06 00 06 0F E0 CF 65 00 00 00 9B 9F 07 00 00 00 ....àÏe...›Ÿ....
000001D0 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000001E0 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000001F0 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 AA ..............Uª

Here is the partition table extraced from above
Master Boot Record - address 0 at offset 0x01BE:
000001BE - 00 03 06 00 06 0F E0 CF 65 00 00 00 9B 9F 07 00 ......àÏe...›Ÿ..

The sector number of the partition boot sector is 0x00000065 (101). The sector address is therefore 512 * 101 = 51712 (0xCA00). The following is the dump of the partition boot sector.

Partition Boot Sector:
0000CA00 - EB 00 90 20 20 20 20 20 20 20 20 00 02 20 01 00 ë. .. ..
0000CA10 - 02 00 02 00 00 F8 3D 00 20 00 10 00 65 00 00 00 .....ø=. ...e...
0000CA20 - 9B 9F 07 00 80 00 29 A9 3D 30 FC 4E 4F 20 4E 41 ›Ÿ..€.)©=0üNO NA
0000CA30 - 4D 45 20 20 20 20 46 41 54 31 36 20 20 20 00 00 ME FAT16 ..
0000CA40 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0000CA50 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0000CA60 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0000CA70 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0000CA80 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0000CA90 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0000CAA0 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0000CAB0 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0000CAC0 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0000CAD0 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0000CAE0 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0000CAF0 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0000CB00 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0000CB10 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0000CB20 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0000CB30 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0000CB40 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0000CB50 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0000CB60 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0000CB70 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0000CB80 - 44 44 00 00 00 00 00 00 00 00 00 00 00 00 00 00 DD..............
0000CB90 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0000CBA0 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0000CBB0 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0000CBC0 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0000CBD0 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0000CBE0 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0000CBF0 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 AA ..............Uª

Regards, Andrew

Regards, Andrew

http://www.brushelectronics.com/index.php?page=software
Home of Ethernet, SD Card, and Encrypted Serial and USB Bootloaders for PICs!!
Guest
Super Member
  • Total Posts : 80503
  • Reward points : 0
  • Joined: 2003/01/01 00:00:00
  • Location: 0
  • Status: online
RE: MMC or SD card in SPI mode 2005/12/03 06:15:40 (permalink)
0
You guys are both right. The hex editor I was using DID NOT read the zeroth sector of my card (the MBR). AND I was confussed because the MMC card that did work, had the partition sector in the (physical) zeroth sector of the card. The SD card that didn't work had a MBR that looked COMPLETELY different! The MBR of the SD card defined the partition sector somewhere else. My PIC hardware and software was working just fine. It was my FAT software that was broke.

(The really funny thing is, due to a PC/MPASM problem, I am temporarally unable to run and debug my PIC project. Once that is fixed, I am sure this information will get me going.)

Here are two urls that have more info on this:
http://www.win.tue.nl/~aeb/partitions/partition_tables.html#toc2

http://www.ata-atapi.com/hiwtab.htm

Thanks much guys
Guest
Super Member
  • Total Posts : 80503
  • Reward points : 0
  • Joined: 2003/01/01 00:00:00
  • Location: 0
  • Status: online
RE: MMC or SD card in SPI mode 2005/12/05 00:24:11 (permalink)
0
I tried to write a block onto the MMC, I got a good response after issuing the MMC Write Command. But, after issuing the 0xFE data token, my PIC gets 0x04 responses while sending the 512 bytes.

The 0x04 responses say Card ECC failed if referred from the manual. What does this mean? Is the card busted?
Guest
Super Member
  • Total Posts : 80503
  • Reward points : 0
  • Joined: 2003/01/01 00:00:00
  • Location: 0
  • Status: online
RE: MMC or SD card in SPI mode 2005/12/06 05:14:36 (permalink)
0
This is a follow-up to post what I found about the missing MBR on a MMC card. Seems that every MMC or SD card doesn't need an MBR. (After all, a floppy doesn't have one.) When a MMC, SD, USB card etc. are formatted without a MBR in the first sector (hence no partition information) - it is called "superfloppy" format. In the case of superfloppy format, the boot sector is the first sector on the card.

So when initing my card, I have to check for each format, and handle the card appropriately. Thanks guys, for all your help.
Guest
Super Member
  • Total Posts : 80503
  • Reward points : 0
  • Joined: 2003/01/01 00:00:00
  • Location: 0
  • Status: online
RE: MMC or SD card in SPI mode 2005/12/06 05:28:13 (permalink)
0
to: meister Seems like it doesn't like the ECC bytes you sent after the data. Maybe check this doc: http://www.sandisk.com/Assets/File/OEM/Manuals/manual-rs-mmcv1.0.pdf section 5.
Guest
Super Member
  • Total Posts : 80503
  • Reward points : 0
  • Joined: 2003/01/01 00:00:00
  • Location: 0
  • Status: online
RE: MMC or SD card in SPI mode 2005/12/14 11:51:37 (permalink)
0
I'm stuck trying to initialize my card in spi mode.

I have read through this entire forum several times and tried almost every idea that people have come up with to get it working but I haven't been able to.

Here's what I do:

I have verified that my card is receiving the correct voltage level and that all of the pins on the connector are setup properly

I set my spi clock frequency below 400 kHz
I set CS# inactive then send 0xFF ten times for 80 clock cycles total
I set CS# active then send CMD0 padded on either side by 0xFF so to be specific I send [0xFF (0x40, 0x00, 0x00, 0x00, 0x00, 0x95) 0xFF]
I am verifying all of this on an o-scope and I do not receive anything back on my MISO line

The initialization routine completes in less than 500ms

I have tried a Sandisk 256 MB SD Card and a Lexar 128 MB MMC Card

Any ideas or suggestion would be helpful please.
asmallri
Super Member
  • Total Posts : 1864
  • Reward points : 0
  • Joined: 2004/05/26 09:00:05
  • Location: Perth, Australia
  • Status: offline
RE: MMC or SD card in SPI mode 2005/12/14 18:16:21 (permalink)
0
Do you have a pull up resistor on the SPI in to the PIC?

Are you running the PIC at 3.3volts?

If not how have you handled the level conversion form the MMC to the PIC outbound and inbound.

What hardware design are you using?

Regards, Andrew

http://www.brushelectronics.com/index.php?page=software
Home of Ethernet, SD Card, and Encrypted Serial and USB Bootloaders for PICs!!
Guest
Super Member
  • Total Posts : 80503
  • Reward points : 0
  • Joined: 2003/01/01 00:00:00
  • Location: 0
  • Status: online
RE: MMC or SD card in SPI mode 2005/12/15 06:18:51 (permalink)
0
The micro runs off of 5V and I use a 5V to 3.3V bidirectional level translator to convert the signal.

I have verified that the init sequence is running with an oscilliscope. I have verified this on both sides of the level translator to see if there was some sort of delay or bad connection, but there was not. The part that I am using for level translation is an ADG3308 by Analog Devices.

The thing that baffles me is that I can verify that the MOSI, CLK and CS# signals are doing what they are supposed to be doing when they are supposed to do it. I have checked all of this on a scope many times.
Guest
Super Member
  • Total Posts : 80503
  • Reward points : 0
  • Joined: 2003/01/01 00:00:00
  • Location: 0
  • Status: online
RE: MMC or SD card in SPI mode 2005/12/17 15:59:34 (permalink)
0
MMC/SD driver works!!!

I am busy with some Data Logger, that reads the sensors, buffers the measured/formatted stream to the RAM(512 bytes) and sequentuele writers this block of 512 bytes to the end of the file on SD cart.

Can some one translate me how can I find the adres of the first copy of FAT and the RootDirectory?

I use 128Mb SD card.

I have find some example, but I cant underestand what he does ... :(
http://www.cc5x.de/MMC/MMC_FAT.htm
dplm
New Member
  • Total Posts : 24
  • Reward points : 0
  • Joined: 2005/12/18 11:50:04
  • Status: offline
RE: MMC or SD card in SPI mode 2005/12/18 12:12:11 (permalink)
0
Hi all,

I have been reading and doing allot of reasearch. I am new to this SD Pic interface. Been trying out different things and seems to be working but not.

This is what I am using :

-PIC16F877A
-Lexar 256MB SD Card
-LP2950ACZ-3.3 [voltage regulator for the sd card]
-4MHz crystal

Now I have voltage dividers going to and from every SPI pin. 5*(2.2K / 3.3k) = 3.3V

This is my code.

I am writing it in Basic to get the concept of it then will write it in assembly with MPLAB.

This is only the beggining. I only add code when I have succeded the first part


INCLUDE "modedefs.bas"

DEFINE OSC 4
DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 4
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 2
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 3
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2

'=======SD CARD PINOUTS========
CS0 VAR PORTC.2 ' CHIP SELECT
SCLK VAR PORTC.3 ' CLOCK
MISO VAR PORTC.4 ' DATA IN
MOSI VAR PORTC.5 ' DATA OUT

RESULT VAR BYTE
Y VAR BYTE

TRISA = 0
TRISB = 0
TRISC = $10
TRISD = 0
TRISE = 0

ADCON1 = 7

LCDOUT $FE,1,"INIT_MMC"
PAUSE 1000

INIT_MMC :
HIGH CS0
FOR Y = 1 TO 10
SHIFTOUT MOSI,SCLK,1,[$FF]
NEXT Y
LOW CS0

CMD0 :
LCDOUT $FE,1,"cmd0:"
PAUSE 500

FOR Y = 0 TO 5
LOOKUP Y,[$40,$00,$00,$00,$00,$95],RESULT
SHIFTOUT MOSI,SCLK,1,[RESULT]
NEXT Y

RESULT = 0
WHILE RESULT <> 1
SHIFTIN MISO,SCLK,0,[RESULT]
LCDOUT $FE,1, HEX RESULT
PAUSE 100
WEND

HIGH CS0
PAUSE 50
LOW CS0
LCDOUT $FE,1,"cmd0: DONE"
LCDOUT $FE,$C0, HEX RESULT
END



but I never get to :
LCDOUT $FE,1,"cmd0: DONE"
LCDOUT $FE,$C0, HEX RESULT

all I read on the LCD is result = 0xFF and if I try to send command 1 instaed of Command 0 the result = 0x00

So something must be working.

After this I can set up so I can read/write secotrs. Will be sending in binary data and reading binary data.

If anyone has any suggestions plz let me no.

In the mean time will keep trying out different settings and reasearch.

Thanks
Guest
Super Member
  • Total Posts : 80503
  • Reward points : 0
  • Joined: 2003/01/01 00:00:00
  • Location: 0
  • Status: online
RE: MMC or SD card in SPI mode 2005/12/18 18:09:30 (permalink)
0
I hope that this will help you :)

the code below is writen in macro assembler, and it works...



; Macro for SPI litera
SPI_L macro dataToSend
MOVLW dataToSend ; move dataToSend into w
call SPImacro
endm

;Macro for SPI variable
SPI_F macro dataToSend
MOVFW dataToSend
call SPImacro
endm

; Chek response R1 , if ok w == 0, if not ok w == 01
CHK_R1 macro r1
MOVLW r1
call Chk_R1
endm

SELECT_MMC macro
BCF MMC_CS
endm

DESELECT_MMC macro
BSF MMC_CS
endm

NCR macro
SPI_L 0xFF
endm


; This macro uses function MMC_Send_Cmd. Cmd and CRC are literas, and adresses Adr1 - Adr4 are literas.
MMC_SEND_CMD_L macro Cmd, Adr1, Adr2, Adr3, Adr4, CRC, CMD_Response

movlw Cmd
movwf MMC_Cmd

movlw Adr1
movwf AdrByte1

movlw Adr2
movwf AdrByte2

movlw Adr3
movwf AdrByte3

movlw Adr4
movwf AdrByte4

movlw CRC
movwf MMC_CRC

movlw CMD_Response
movwf MMC_Response

call MMC_Send_Cmd

endm
;------------------------------------------------------------------

; Sends specified command
MMC_Send_Cmd

SPI_F MMC_Cmd
SPI_F AdrByte1
SPI_F AdrByte2
SPI_F AdrByte3
SPI_F AdrByte4
SPI_F MMC_CRC

NCR

movfw MMC_Response
CALL Chk_R1

BTFSS STATUS, Z
goto MMC_Send_Cmd
RETURN

mmc_init

DESELECT_MMC

SPI_L 0xFF
SPI_L 0xFF
SPI_L 0xFF
SPI_L 0xFF
SPI_L 0xFF
SPI_L 0xFF
SPI_L 0xFF
SPI_L 0xFF
SPI_L 0xFF
SPI_L 0xFF

SELECT_MMC

MMC_SEND_CMD_L 0x40, 0x00, 0x00, 0x00, 0x00, 0x95, 0x01

MMC_SEND_CMD_L 0x41, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00

DESELECT_MMC

RETURN



; Check response R1, if ERROR return 0x01 in W, if Ok return 0x00 in W
Chk_R1
MOVWF response
SPI_L 0xFF

MOVF response, 0
XORWF SPI_Data, w
BTFSC STATUS, Z
RETLW 0x00 ; OK

; Idle_State
BTFSC SPI_Data, 0
RETLW 0x01 ; OK; GOTO Idle_State_error

; Erase_Reset
BTFSC SPI_Data, 1
GOTO Erase_Reset_Error

; Illegal_Command_Error
BTFSC SPI_Data, 2
GOTO Illegal_Command_Error

; Com_CRC_Error
BTFSC SPI_Data, 3
GOTO Com_CRC_Error

; Erase_Seq_Error
BTFSC SPI_Data, 4
GOTO Erase_Seq_Error

; Address_Error
BTFSC SPI_Data, 5
GOTO Address_Error

; Parameter_Error
BTFSC SPI_Data, 6
GOTO Parameter_Error
goto Ondefined_ERROR ;RETLW 0x80 ; OK


; Send the value of SPI_Data, reseive the data to the SPI_Data
SPI_Out
MOVF SPI_Data, w ; move SPI_Data into w
SPImacro
BANKSEL SSPBUF
MOVWF SSPBUF ; place data in send buffer
SPI_Out_2
BANKSEL SSPSTAT
BTFSS SSPSTAT,BF ; has data been received?
GOTO SPI_Out_2 ; loop if not received yet

BANKSEL SSPBUF
MOVF SSPBUF,W ; empty the receive buffer
MOVWF SPI_Data ; put received byte into rxdata
RETURN




and so is SPI configurated:

MMC_Configuration macro
; Set up the SPI Support
BANKSEL TRISA ; BANK 1
movlw 0x00 ; Set PORTA as
movwf TRISA ; all Outputs
movlw 0x06 ; Turn off A/D
movwf ADCON1 ; so PORTA can be used

Setup_SPI
BANKSEL TRISC
MOVLW b'00010000' ;b'11010100' ;Set portc for using USART + MSSP, c0 and c1 for the decoder chip, and c2 for DREQ
MOVWF TRISC

BANKSEL SSPSTAT
CLRF SSPSTAT ;clear SSP status register
MOVLW 0x80 ;set up spi port, SPI master,
MOVWF SSPSTAT ;cke = 0 (mode 1,1)

BANKSEL SSPCON
CLRF SSPCON ;clear SSP control register
MOVLW 0x32 ;set up spi port, SPI master,
MOVWF SSPCON ;clk/64, ckp=1 (mode 1,1)
BANKSEL PORTA
endm


the hardware that I use looks like this:


Regards,

Ildar
< Message edited by nin2006 -- Dec. 18, 2005 6:15:37 PM >
dplm
New Member
  • Total Posts : 24
  • Reward points : 0
  • Joined: 2005/12/18 11:50:04
  • Status: offline
RE: MMC or SD card in SPI mode 2005/12/18 18:23:28 (permalink)
0
Thanks nin2006

Will look at your source code. Should be able to figure it out. Also I am using the same schematic but wit a PIC16F877A.

I had it working earlier today but now can't seem to get it working. But my pic is running from 5V and SD card on 3.3Volts. I have 2.2K resitors in series going from my pic to the 4 sd card pinouts for SPI configuration.

When I try to do CMD0 I get $FE $03 then all $FF

But before I could get passed this.

Here is my new code

INCLUDE "modedefs.bas"

DEFINE OSC 4
DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 4
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 2
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 3
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2

'=======SD CARD PINOUTS========
CS0 VAR PORTC.2 ' CHIP SELECT
SCLK VAR PORTC.3 ' CLOCK
MISO VAR PORTC.4 ' DATA IN
MOSI VAR PORTC.5 ' DATA OUT

RESULT VAR BYTE
Y VAR BYTE

TRISA = 0
TRISB = 0
TRISC = $10
TRISD = 0
TRISE = 0

ADCON1 = 7

LCDOUT $FE,1,"INIT_MMC"
PAUSE 1000

INIT_MMC :
HIGH CS0
FOR Y = 1 TO 10
SHIFTOUT MOSI,SCLK,1,[$FF]
NEXT Y
LOW CS0

CMD0 :
LCDOUT $FE,1,"CMD0:"
PAUSE 500

FOR Y = 0 TO 5
LOOKUP Y,[$40,$00,$00,$00,$00,$95],RESULT
SHIFTOUT MOSI,SCLK,1,[RESULT]
NEXT Y

WHILE RESULT <> 1
SHIFTIN MISO,SCLK,0,[RESULT]
LCDOUT $FE,1,HEX RESULT
PAUSE 500
WEND

HIGH CS0
PAUSE 50
LOW CS0
LCDOUT $FE,1,"CMD0: DONE"
LCDOUT $FE,$C0, HEX RESULT

CMD1:
LCDOUT $FE,1,"CMD1:"
PAUSE 1000

WHILE RESULT <> 0
HIGH CS0
SHIFTOUT MOSI,SCLK,1,[$FF]
SHIFTIN MISO,SCLK,0,[RESULT]
LOW CS0
FOR Y = 0 TO 6
LOOKUP Y,[$41,$00,$00,$00,$00,$00,$00],RESULT
SHIFTOUT MOSI,SCLK,1,[RESULT]
NEXT Y
SHIFTIN MISO,SCLK,0,[RESULT]
LCDOUT $FE,1,HEX RESULT
PAUSE 500
WEND
RESULT = $DD
LCDOUT $FE,1,"INIT OK!"
PAUSE 1500

' SET BLOCK LEGNTH
BLOCK_LEGNTH :
WHILE RESULT <> 0
HIGH CS0
SHIFTOUT MOSI,SCLK,1,[$FF]
SHIFTIN MISO,SCLK,0,[RESULT]
LCDOUT $FE,1,HEX RESULT
LOW CS0
FOR Y = 0 TO 5
LOOKUP Y,[$50,$00,$00,$02,$00,$FF],RESULT
SHIFTOUT MOSI,SCLK,1,[RESULT]
NEXT Y
SHIFTIN MISO,SCLK,0,[RESULT]
LCDOUT $FE,1,HEX RESULT
WEND
LCDOUT $FE,1,"DONE"
END



But I am not giving up yet. Been at this for 2 months now. Will get it. But is nice to see that some people are getting it.

Thanks
dplm
New Member
  • Total Posts : 24
  • Reward points : 0
  • Joined: 2005/12/18 11:50:04
  • Status: offline
RE: MMC or SD card in SPI mode 2005/12/20 20:24:20 (permalink)
0
Well it looks like it is easier to use the MMC Cards compared to the SD Cards.

So I think I will go and Purchase the MMC Card and try that. Really having a hard time with SD.

Also with all the research that I have been doing, if you are using a pic MMC Cards are the best way to go.

If I get it to Initialise will post my code for others.

grin
asmallri
Super Member
  • Total Posts : 1864
  • Reward points : 0
  • Joined: 2004/05/26 09:00:05
  • Location: Perth, Australia
  • Status: offline
RE: MMC or SD card in SPI mode 2005/12/20 22:08:02 (permalink)
0
I use MMC and SD cards interchangably. I have tested at least 10 different manufacturers of SD cards without problem.

I would offer to comiple some test code and send it to you but you are using a 16F series processor even though it is obviously not suitable for either MMC or SD operation as it is not capable of storing a full sector which would be an absolute minimum requirement for updating a directory entry.

Regards, Andrew

http://www.brushelectronics.com/index.php?page=software
Home of Ethernet, SD Card, and Encrypted Serial and USB Bootloaders for PICs!!
dplm
New Member
  • Total Posts : 24
  • Reward points : 0
  • Joined: 2005/12/18 11:50:04
  • Status: offline
RE: MMC or SD card in SPI mode 2005/12/21 11:58:40 (permalink)
0
ASMALLRI,

You had asked LukeB if he had a pull up resistor on the SPI in to the PIC?

what pin would you put the pull up on if these were the pinouts.

=======SD CARD PINOUTS========
CS0 VAR PORTC.2 ' CHIP SELECT
SCLK VAR PORTC.3 ' CLOCK
MISO VAR PORTC.4 ' DATA IN
MOSI VAR PORTC.5 ' DATA OUT

Now I am changing my microcontoller to the pic18f452. I will be running it at 20MHz. The code will stay the same just will be a different pic as well as different osc.

As far as storing full sectors, I will have a 32Kbytes RAM chip that I will be using to store raw binary data. All that I am doing is storing data to each sector. Once I have accomplished that I will move onto FAT table entries. I have allot of documentation on this. But first thing is first. Initializing the card get it running read the CID register and write/read sectors.

Thanks for letting me no that you use MMC and SD cards interchangably, have tested at least 10 different manufacturers of SD cards without problem.

That is good news. This means that it it possible for me.

Thanks
asmallri
Super Member
  • Total Posts : 1864
  • Reward points : 0
  • Joined: 2004/05/26 09:00:05
  • Location: Perth, Australia
  • Status: offline
RE: MMC or SD card in SPI mode 2005/12/21 17:59:24 (permalink)
0
ORIGINAL: dplm

ASMALLRI,

You had asked LukeB if he had a pull up resistor on the SPI in to the PIC?

what pin would you put the pull up on if these were the pinouts.


MISO VAR PORTC.4 ' DATA IN


Now I am changing my microcontoller to the pic18f452. I will be running it at 20MHz. The code will stay the same just will be a different pic as well as different osc.


I usually use 10MHz with the H4 fuse to give me 40MHz internal.


As far as storing full sectors, I will have a 32Kbytes RAM chip that I will be using to store raw binary data. All that I am doing is storing data to each sector. Once I have accomplished that I will move onto FAT table entries. I have allot of documentation on this.


OK. Are you using a standard parallel bus interface for data and address to the RAM? I am planning to use a FRAM to so the same sort of thing but this requires only the SPI interface. In my case I need the external memory because I have a lot of incoming data that has to be buffered while waiting for SD/MMC operations to finish. I have another application that was able to do everything in the PIC without requiring the external memory. I am looking to use some of the larger PICs with 3000+ bytes of RAM as a "standard platform" for SD/MMC applications.


But first thing is first. Initializing the card get it running read the CID register and write/read sectors.


One trick I use is that if I detect an unexpected error on the card (someone removed and reinserted the card), I flush the SPI bus to the card sending 8 bytes of 0xFF and then going thru the usual init sequence. I found this works well.

Regards, Andrew

http://www.brushelectronics.com/index.php?page=software
Home of Ethernet, SD Card, and Encrypted Serial and USB Bootloaders for PICs!!
Page: << < ..678910.. > >> Showing page 6 of 14
Jump to:
© 2021 APG vNext Commercial Version 4.5