CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

PIC18F47J53 CCS C Compiler 5.090 mmcsd.c library issue
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Marco27293



Joined: 09 May 2020
Posts: 110

View user's profile Send private message

PostPosted: Tue Sep 22, 2020 8:49 am     Reply with quote

What does it mean?
Any suggestion on how to fix this ?
Shall I comment the wait for token part?

I'm using a SDHC 1GB card, if I call mmcsd_init() multiple times, the first one I have:
g_card_type = SDHC;

The successive calls give me:

g_card_type = SDSC;

I hope this could be useful...
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Tue Sep 22, 2020 9:20 am     Reply with quote

That is saying the same thing. The R1 read is not working right. This value
is dependant on the value retrieved from R1.
I assume you are running everything off 3.3v?.
Have you got a really good reservoir capacitor really close to the SD card?.
SD cards generate really large momentary supply spikes. The behaviour
has all the symptoms that the supply may not be 100% reliable....
Marco27293



Joined: 09 May 2020
Posts: 110

View user's profile Send private message

PostPosted: Tue Sep 22, 2020 9:24 am     Reply with quote

I have 47uF in parallel with a ceramic capacitor very
close to the card's Vdd connection.

Do you suggest a different capacitor value? All works at 3.3v
newguy



Joined: 24 Jun 2004
Posts: 1899

View user's profile Send private message

PostPosted: Tue Sep 22, 2020 10:15 am     Reply with quote

For all my projects that have a micro SD card, I use a 22uF 10% X5R 10V (at least) ceramic in parallel with 0.1uF 10% 50V X7R. I don't see any weird issues.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Tue Sep 22, 2020 11:23 am     Reply with quote

Yes. The small ceramic ought to give the HF performance the electrolytic
lacks but if this was a fairly poor electrolytic there might be an issue with
some spikes. A ceramic capacitor is much better.
One of the SD recommendations is for a ground plane, and these
capacitors to be within 12mm of the pins.
The point here is that a semi random 'wrong' value from the card has
all the symptoms of a hardware issue.
Have you tried dropping the selected speed of the SD card?.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Tue Sep 22, 2020 12:15 pm     Reply with quote

I realise there is something slightly puzzling in what you say.
A 1GB card, cannot be SDHC. SDHC cards start at 2GB (originally 4GB).
If you have a card that claims to be 1GB SDHC, then it is almost certainly
a 'rip off' card, which may well be the problem. Sad
Marco27293



Joined: 09 May 2020
Posts: 110

View user's profile Send private message

PostPosted: Wed Sep 23, 2020 1:23 am     Reply with quote

I use this capacitor (10mm near to SD, all recommendations about ground plane are well satisfied): https://www.mouser.it/ProductDetail/KEMET/T491D476K010ATAUTO?qs=%2Fha2pyFadujo9R5fj5RoGRgpS5bFFmfD0TulWbkiU%252B%2FBTAKwhB9DgAvcoT2rePYv

Can you suggest a better one ? Please give me all the details.

#use spi(MASTER,SPI2, DI=MMCSD_PIN_MISO, DO=MMCSD_PIN_MOSI, CLK=MMCSD_PIN_SCK, BITS=8, MSB_FIRST, MODE=3, baud=400000)

In order to dropping the selected speed, what should I change in the above configuration? Please suggest me a good baudrate value.
I'll try to use another card, maybe this is the solution...
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Wed Sep 23, 2020 2:37 am     Reply with quote

You don't change that.
The SPI, runs in two different speeds. This is the 'boot speed' (slow), which
is needed when the card first wakes. During the init, the speed is increased.
Code:

/// this would be a good time to set a higher clock speed, 20MHz
#ifdef MMCSD_SPI_HW
  setup_spi(SPI_MASTER | SPI_H_TO_L | SPI_XMIT_L_TO_H | SPI_CLK_DIV_4);
#else
  #use spi(MASTER, DI=MMCSD_PIN_MISO, DO=MMCSD_PIN_MOSI, CLK=MMCSD_PIN_SCK, BITS=8, MODE=3)
#endif

Depending on whether you have MMCSD_SPI_HW defined, you should
reduce either the first or second line here. For the first change
SPI_CLK_DIV_4 to SPI_CLK_DIV_8. For the second add:

,baud=4000000

after MODE=3

There is potentially an issue here. At your 64MHz clock, by default the
compiler on the second line, will select 'as fast as possible'. This will
actually exceed the maximum SPI clock allowed on this chip (it is slower
for chips using PPS, than ones with permanent hardware). The maximum
allowed is just over 5MHz to meet all the datasheet timings. Hence 4Mhz
is nicely safe.
I realise also, we have not queried whether you actually have the pull up
resistors on the SPI lines. These are _required_ (not optional).
Otherwise the card can get into the wrong mode at boot, and the rising
edge timings may be out of spec.
You still have not answered about the 'impossibility' of a 1GB SDHC card.
Marco27293



Joined: 09 May 2020
Posts: 110

View user's profile Send private message

PostPosted: Wed Sep 23, 2020 3:15 am     Reply with quote

The card is 16GB (sorry for my misunderstanding)

I have 51k pullup only on MISO/DAT0 line, SCK line does not have any pullup, while on MOSI/CMD and CS/DAT3 lines pullup resistors are not soldered but I can add them.

"There is potentially an issue here. At your 64MHz clock, by default the
compiler on the second line, will select 'as fast as possible'. This will
actually exceed the maximum SPI clock allowed on this chip (it is slower
for chips using PPS, than ones with permanent hardware). The maximum
allowed is just over 5MHz to meet all the datasheet timings. Hence 4Mhz
is nicely safe." -> Why 64MHz? Is this problem fixed selecting a slower speed for SPI2 (adding the code suggested by you) ?

Thank you very much for the essential support
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Wed Sep 23, 2020 3:48 am     Reply with quote

You should have pull-ups on DAT1, DAT2, DATA_OUT, and CS.

The latter is needed, because the PIC takes time to wake, and during this
the CS line will be floating if a pull up is not there. DAT1 and DAT2 must
have pull-ups to ensure the card is in the correct mode at boot. The
DATA_OUT line needs a pull up, or it will be floating to the PIC, when the
card is not inserted. Result higher drawn current and unwanted data
seen.
51K is rather large. Suggest perhaps 22K.

I thought you were running at 64M.

Reducing the rate is a worthwhile experiment.
Marco27293



Joined: 09 May 2020
Posts: 110

View user's profile Send private message

PostPosted: Wed Sep 23, 2020 3:55 am     Reply with quote

DAT1 and DAT2 are marked as NOT-connect in my schematic, is that wrong?

Without changing my hardware I only put 10K resistors on MISO, MOSI, CS. Could be enough?

I can control power-on/power-off of SD supply through a switch driven by the PIC...
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Wed Sep 23, 2020 5:42 am     Reply with quote

Those pins are not driven when you are working in SPI mode. _BUT_
they must not be left floating. Quote from the SD card specifications:
Quote:

RDAT external pull-up resistor value to prevent bus
floating; DAT0, DAT1 and DAT2
MIN MAX
10 100 k


The DAT1 & DAT2 pins must have pull up resistors on them.
DAT3 has an internal one inside the actual SD card).
Marco27293



Joined: 09 May 2020
Posts: 110

View user's profile Send private message

PostPosted: Wed Sep 23, 2020 5:51 am     Reply with quote

Where can I find SD card specification doc ?
Please, semd me a link to your quote.

Now my hw layout has NOT pullup on DAT1 and DAT2, is any fw workaround possible?
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Wed Sep 23, 2020 5:58 am     Reply with quote

To actually get the full specs you have to be either a registered member
or producer of SD card products, with the SD association. However a
search online for SD card physical specifications will find many of the older
versions.
The three year old version is here:
<https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=&cad=rja&uact=8&ved=2ahUKEwivjbHCm__rAhXGMMAKHcjDASEQFjAaegQIARAB&url=https%3A%2F%2Fwww.taterli.com%2Fwp-content%2Fuploads%2F2017%2F05%2FPhysical-Layer-Simplified-SpecificationV6.0.pdf&usg=AOvVaw17v1_twwYzeGkjcDzOG1JA>
Look at page 13:
Quote:

Host shall not leave these unused lines floating, but keep them at a defined high or low level.


Generally, input lines should _never_ be left floating on a chip.
Marco27293



Joined: 09 May 2020
Posts: 110

View user's profile Send private message

PostPosted: Wed Sep 23, 2020 6:30 am     Reply with quote

OK, so can I connect DAT1 and DAT2 to GND?

Last question: could SCK2 line be left without any pullup ?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
Jump to:  
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