|
|
View previous topic :: View next topic |
Author |
Message |
msa
Joined: 07 Apr 2010 Posts: 15
|
mmcsd always read value 00 |
Posted: Wed Dec 15, 2010 5:38 am |
|
|
Hello All,
18F2550 @ internal oscillator 8MHz
compiler version is 4.093
Sandisk 128MB micro SD card
Power Supply : DC 3.6V
RS-232 interface : Slim USB to Serial UART Converte (TTL to RS-232)
I used mccsd.c to read data from microSD, but when I read microSD
the PIC always return 00 value.
///////// for example /////////////
Add, 00000000 , Val, 00
Add, 00000001 , Val, 00
Add, 00000002 , Val, 00
Add, 00000003 , Val, 00
Add, 00000004 , Val, 00
Add, 00000005 , Val, 00
Add, 00000006 , Val, 00
Add, 00000007 , Val, 00
Add, 00000008 , Val, 00
Add, 00000009 , Val, 00
Add, 0000000A , Val, 00
Add, 0000000B , Val, 00
Add, 0000000C , Val, 00
Add, 0000000D , Val, 00
Add, 0000000E , Val, 00
Add, 0000000F , Val, 00
Add, 00000010 , Val, 00
////////////////////////////////////////
Schematic :
------------
<script src='http://img842.imageshack.us/shareable/?i=sdpic.jpg' type='text/javascript'></script><noscript></noscript>
Code: |
#include <18F2550.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES INTRC_IO //Internal RC Osc
#FUSES NOPROTECT //Code not protected from reading
#FUSES DEBUG // Debug mode for ICD
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOMCLR //Master Clear pin enabled
#FUSES NOPUT
#use delay(clock=8M)
#use rs232(baud=9600, UART1, errors)
#include <stdlib.h> // for atoi32
#use fast_io(b)
#use fast_io(c)
#define MMCSD_PIN_SCL PIN_B1 //o
#define MMCSD_PIN_SDI PIN_B0 //i
#define MMCSD_PIN_SDO PIN_C5 //o
#define MMCSD_PIN_SELECT PIN_A0 //o
#include <mmcsd.c>
#include <input.c>
void main(void)
{
BYTE value;
int32 address;
setup_oscillator(OSC_8MHZ);
printf("\r\n\n Wellcome \r\n\n");
if (mmcsd_init())
{
printf("Could not init the MMC/SD!!!!");
while(TRUE);
}
for(address = 0x00000000; address <= 0x00000200; address++)
{
mmcsd_read_byte(address, &value) ;
printf("Add, %lX , Val, %X\n\r", address, value) ;
}
do {
} while (TRUE);
} |
Last edited by msa on Wed Dec 15, 2010 4:53 pm; edited 3 times in total |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9254 Location: Greensville,Ontario
|
|
Posted: Wed Dec 15, 2010 6:40 am |
|
|
I assume this is not real hardware but a simulation, as you do not have correct RS-232 interface in the schematic,nor show the power supply design.
Also, you're using fastio() functions, which unless you're a seasoned programmer, will cause you problems. |
|
|
msa
Joined: 07 Apr 2010 Posts: 15
|
|
Posted: Wed Dec 15, 2010 7:29 am |
|
|
Power Supply : DC 3.6V
RS-232 interface : Slim USB to Serial UART Converte (TTL to RS-232) |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9254 Location: Greensville,Ontario
|
|
Posted: Wed Dec 15, 2010 8:04 am |
|
|
Have you verified that the SD card actually has data on it at those locations using some sort of low level reader program on a PC or other computer? |
|
|
msa
Joined: 07 Apr 2010 Posts: 15
|
|
Posted: Wed Dec 15, 2010 11:59 am |
|
|
the SD card contains 100 M of files |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9254 Location: Greensville,Ontario
|
|
Posted: Wed Dec 15, 2010 12:51 pm |
|
|
what is the data you have read from those memory locations, and on what software? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19563
|
|
Posted: Thu Dec 16, 2010 3:15 am |
|
|
msa wrote: | the SD card contains 100 M of files |
Doesn't mean it contains much in the first few hundred bytes....
Depending on how the card was formatted, the first sector, will either be a boot sector, or the MBR. If the former, there should be data right at the start (an Intel jump instruction!), _but_ if the latter, the sector will probably be empty, right up to byte 446. Then only contain a handful of bytes. It is then quite common for the next sector to be empty. Are you sure you might not miss a few bytes with data, in a 'sea' of empty ones?.
So try restricting your count range, and pull the bytes from address 0x1BE, to 0x1FF. The ones at 0x1CA, are the most critical (4 bytes, giving the size of the card).
Best Wishes |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Thu Dec 16, 2010 6:47 am |
|
|
You defined PIN_C5 as SDO, but unfortunately, the pin is input only at 18F2550. Select a suitable pin instead.
Using PIN_C7 would basically enable fast hardware SPI, but I fear, #use SPI() doesn't work correctly with some
CCS C versions and hardware SPI. |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1636 Location: Perth, Australia
|
Re: mmcsd always read value 00 |
Posted: Sat Dec 18, 2010 12:01 am |
|
|
msa wrote: | ..I used mccsd.c to read data from microSD, but when I read microSD the PIC always return 00 value. |
You are missing the pull-up resistor on DO from the card. This will prevent the card being put into SPI mode and effectively you are reading a floating input.
If the circuit is "real" then be aware that 3.6V is the absolute maximum rating for the SD card. Ideally you should be using 3.3 volts. I assume you also have power supply filtering and decoupling capacitors. _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sat Dec 18, 2010 3:40 am |
|
|
By SD specification, the DO level is not involved in switching to SPI mode. It's done by sending CMD0
with CS asserted (low). Pull-up resistors at DAT0/DO and unused DAT1 and DAT2 pins should be placed to avoid
excessive current consumption with intermediate levels. |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1636 Location: Perth, Australia
|
|
Posted: Sat Dec 18, 2010 3:45 am |
|
|
FvM wrote: | By SD specification, the DO level is not involved in switching to SPI mode. It's done by sending CMD0
with CS asserted (low). Pull-up resistors at DAT0/DO and unused DAT1 and DAT2 pins should be placed to avoid
excessive current consumption with intermediate levels. |
I guarantee that if you use one of my drivers without a pullup resistor on DO it will fail. _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sat Dec 18, 2010 7:03 am |
|
|
Quote: | I guarantee that if you use one of my drivers without a pullup resistor on DO it will fail. |
I love those assumptions, that can be easily verified. But I couldn't. I regularly have an internal pull-up
activated at the DO pin (with PIC24). By disabling the pull-up and even by enabling a pull-down, I didn't
manage to disturb the SD card operation. (Tested with Kingston 2 GB microSD). |
|
|
gpsmikey
Joined: 16 Nov 2010 Posts: 588 Location: Kirkland, WA
|
|
Posted: Sat Dec 18, 2010 12:16 pm |
|
|
The assumption here is that the cards follow the spec .... There is a reason the camera manufacturers publish a list of what cards have been tested with their cameras. It is not at all unusual for some cards to not work at all with some cameras. Like the spec for DVD's - if you look at the spec for NTSC DVD's, it says that at least one audio track must be either AC3 or PCM. Most DVD creation software (slide shows, video editors etc) default to Mpeg Layer2 for the audio. *MOST* dvd players will handle that just fine, but every now and then you find (usually an older one) one that only follows the spec and it will take you a while to discover that is why only on that player, the show has no audio (took me a while to track that one down!). You may find some cards with pull up/down on the card so your interface may work with some and not with others and only by looking at the signals with a scope can you see that the voltages are not correct. Best you can do is try to follow the spec as close as possible. The nice thing about specs is there are so many to chose from
mikey _________________ mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3 |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1636 Location: Perth, Australia
|
|
Posted: Sat Dec 18, 2010 10:14 pm |
|
|
FvM wrote: | Quote: | I guarantee that if you use one of my drivers without a pullup resistor on DO it will fail. |
I love those assumptions, that can be easily verified. But I couldn't. I regularly have an internal pull-up
activated at the DO pin (with PIC24). By disabling the pull-up and even by enabling a pull-down, I didn't
manage to disturb the SD card operation. (Tested with Kingston 2 GB microSD). |
Well what can I say, I support a lot of customers using my drivers and the number one hardware related problem is the missing pull-up. I am guilty of this myself a couple of hours last week bringing up a new board with a missing pull-up. I fitted the pull-up and problem disappeared immediately. In this specific case the card was a PNY 2G microSD however I have seen this with multiple card types. _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sun Dec 19, 2010 3:50 am |
|
|
Of course, I've no reason to doubt your observation. Placing pull-ups for all potentially floating SD (or MMC)
pins is suggested by the SD and MMC specification, so you should have it. I don't exactly understand, what
causes the reported failure with missing pull-up, but I don't actually need to know it.
In the present case posted by msa, the interface can't work with or without a pull-up anyway. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|