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 CCS Technical Support

MMC SD libraries - yap this topic again
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
Jerry I



Joined: 14 Sep 2003
Posts: 96
Location: Toronto, Ontario, Canada

View user's profile Send private message

PostPosted: Mon Aug 11, 2014 1:47 pm     Reply with quote

I also see your SD Card adapter with 4 wires showing.
they appear to be going to the pic PORTC CLK, DAT, CS, DOUT.

I don't see the +3.3v & Gnd wires to the SD Adapter, are the behind the adapter.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Aug 11, 2014 1:48 pm     Reply with quote

I'm working on putting together a breadboard circuit. It will take me
a while to do this.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Aug 11, 2014 3:53 pm     Reply with quote

I finished the hardware and tested it. I get the same results you did.
The result of 0 is the #define value for GOODEC, which means a
successful result.

Your complaint was that you get GOODEC if the SD card is plugged in
or not. But there is a difference. If the card is plugged in, I get the
GOODEC response at a rapid rate. When I un-plug the card, the
response occurs once every 10 seconds.

So clearly there is some kind of timeout process going on in the CCS
driver files. It should be handled better than that. It should return
an error code. I notice the CCS drivers don't support the CD signal
(card detect). If they did, the drivers would immediately know that
the card was not there.
electr0dave



Joined: 10 Aug 2014
Posts: 24

View user's profile Send private message

PostPosted: Mon Aug 11, 2014 4:05 pm     Reply with quote

Jerry I wrote:

I don't see the +3.3v & Gnd wires to the SD Adapter, are the behind the adapter.

Hello.

Yes, these wires are behind the card.

PCM programmer wrote:
I'm working on putting together a breadboard circuit. It will take me
a while to do this.


Thanks PCM programmer, to be helping me to understand what is happening!

PCM programmer wrote:

The result of 0 is the #define value for GOODEC, which means a
successful result.
.

Yes, that was my question. How could it be a success if the card was not inserted?
I was confused ...

PCM programmer wrote:

Your complaint was that you get GOODEC if the SD card is plugged in
or not. But there is a difference. If the card is plugged in, I get the
GOODEC response at a rapid rate. When I un-plug the card, the
response occurs once every 10 seconds.


I also noticed that ...

With card, sometimes I get answers ranging between -1 and 0 (EOF , GOODEC).

PCM programmer wrote:

So clearly there is some kind of timeout process going on in the CCS
driver files. It should be handled better than that. It should return
an error code. I notice the CCS drivers don't support the CD signal
(card detect). If they did, the drivers would immediately know that
the card was not there.


Okay.
We ought not to warn developers of CCS for this problem?
In my case, the main function of "fat_init ()" would be to detect if the card was inserted ...
electr0dave



Joined: 10 Aug 2014
Posts: 24

View user's profile Send private message

PostPosted: Mon Aug 11, 2014 4:27 pm     Reply with quote

Now I tried to do something else.

I wait to get 5 positive readings (resp == 0).
After this I try to create a file.

Unfortunately, without success .... :(

Code:

#include <main.h>

#use rs232(baud=9600, UART1, errors)

//media library, a compatable media library is required for FAT.
#use fast_io(c)
#define MMCSD_PIN_SCL     PIN_C3 //o
#define MMCSD_PIN_SDI     PIN_C4 //i
#define MMCSD_PIN_SDO     PIN_C5 //o
#define MMCSD_PIN_SELECT  PIN_C2 //o
#include <mmcsd.c>

//FAT library.
#include <fat.c>

void MakeFile(char *fileName)
{
   printf("\r\nMaking file '%s': ", fileName);
   if(mk_file(fileName) != GOODEC)
   {
      printf("Error creating file");
      return;
   }
   printf("OK");
}


void main(void)
{
   char i;
   char fileN[255];
   int resp;
   
   delay_ms(1000);

   for(i=0;i<5;i++)
   {
      while(resp != 0)
      {
         resp = fat_init();
         printf ("\r\nresp = %d\r\n", resp);
         delay_ms(100);
      }
   }
   
   strcpy(fileN, "test.txt");
   
   MakeFile(fileN);
   
   while(1);
}



imageupload
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Aug 11, 2014 5:00 pm     Reply with quote

I have to add andrewg's bug fixes to the drivers before I can proceed.
http://www.ccsinfo.com/forum/viewtopic.php?t=43417
I'll do that, then I'll test it.
electr0dave



Joined: 10 Aug 2014
Posts: 24

View user's profile Send private message

PostPosted: Mon Aug 11, 2014 5:18 pm     Reply with quote

Okay.
Keep me informed, please.
electr0dave



Joined: 10 Aug 2014
Posts: 24

View user's profile Send private message

PostPosted: Tue Aug 12, 2014 6:33 am     Reply with quote

Hello.

I replaced library mmcsd.c by that which is in the link.

But I only get "begin initialization" ....

After this, it seems that he is trapped in an infinite loop.

This occurs with or without the card.


image upload no limit


Last edited by electr0dave on Tue Aug 12, 2014 7:03 am; edited 1 time in total
electr0dave



Joined: 10 Aug 2014
Posts: 24

View user's profile Send private message

PostPosted: Tue Aug 12, 2014 6:57 am     Reply with quote

Hmmm .....

I made some changes ...

I put:
* Pull-down resistor in SD_DO;
* Pull-up resistor in CS, DAT1 and DAT2;


how to screenshot on windows

Then I went to test the new library "mmcsd.c".

Without the card inserted, I only get "begin initialization" and "update date"!


print screen windows 7

But with the card inserted, I get the first things ...


image free hosting

What do you think of this?


Last edited by electr0dave on Tue Aug 12, 2014 7:04 am; edited 1 time in total
electr0dave



Joined: 10 Aug 2014
Posts: 24

View user's profile Send private message

PostPosted: Tue Aug 12, 2014 7:02 am     Reply with quote

I tried again to create a file, but failed ...


image upload no size limit
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Tue Aug 12, 2014 9:06 am     Reply with quote

The breadboard photograph shows an SD card protruding from the breadboard but no signs of how the connection was made between the board and the card.

I have not used the driver you are using and cannot comment on how that particular driver works however your printout shows an offset address which appears to imply the FAT has been read. This means the card has been initialised and successfully read.

So the problem is you cannot write to the media. There are all sorts of reasons that writing can fail. For example:

is the media write protected?

SD cards draw a high current for a very short time during a write. Are you supplying a low impedance power source to the SD card? (hint - if not it will fail). Have you followed best practice for implementing SD card interfaces by utilizing bypass and power supply decoupling capacitors close to the power pins of the SD card (I cannot see them on the breadboard)?

Have you configured the driver for the correct mode to match your card type. Some file system drivers do not automatically detect the FAT type in use and therefore must be configured accordingly.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
electr0dave



Joined: 10 Aug 2014
Posts: 24

View user's profile Send private message

PostPosted: Tue Aug 12, 2014 9:44 am     Reply with quote

asmallri wrote:
The breadboard photograph shows an SD card protruding from the breadboard but no signs of how the connection was made between the board and the card.



uploading pictures

Why SD_DO is working with a pull-down resistor? There should only work with pull-up?

The media is not protected against writing.

Power for the circuit is being provided by my bench power supply.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Aug 12, 2014 11:00 am     Reply with quote

You're trying to create your own test program. I read some previous posts
where forum members say it does work. It occurred to me that they were
likely using the Ex_fat.c example to control the fat commands. So I did
that. It works.

I test this with compiler vs. 5.026. I did a clean install of the compiler.
The files don't have any of andrewg's fixes, or any changes.

First I edited Ex_fat.c to match my board, as shown below:
Code:

#include <18F4620.h>
//#include <18F67J60.h>  // *** Commented out
#device PASS_STRINGS = IN_RAM
#fuses NOWDT, HS, NOPROTECT
#use delay(clock=20M)  // *** Was 25 MHz


Actually, before that, I checked my hardware by running Brush Electronic's
SD Utils program. It said the SD card was activated OK. So I'm pretty
sure my hardware is working. I'm using a PNY brand, 2 GB SD card.
It's not an SDHC card.

I started TeraTerm and ran the Ex_fat program. The Ex_fat.c file has
a list of commands near the start of the file.

1. First I did a "makefile test.txt" command but it froze. It didn't display
a result code. So then I reset and re-started the Ex_fat program.

2. Then I did a Dir command (as shown below). It showed no files.

3. Then I decided it would be a good idea to format the card.
2 GB is 2097152 KB. So I used that as a parameter. It said OK.

4. Then I made test.txt and it said OK.

5. Then I did a Dir and it showed test.txt was there.

Code:

/> dir
--/--

/> format 2097152
Formatting media (size=2097152): OK

/> make test.txt
Making file '/test.txt': OK

/> dir
--/--
test.txt

/>
electr0dave



Joined: 10 Aug 2014
Posts: 24

View user's profile Send private message

PostPosted: Tue Aug 12, 2014 12:04 pm     Reply with quote

Oh God ...

I will test the sample program again .... but I still do not understand the reason for all this mess ...

You have pull-up in SD_DO?

I will do everything as you say!
I'm currently making a new installation of my version of CCS (5.025).
Ttelmah



Joined: 11 Mar 2010
Posts: 19515

View user's profile Send private message

PostPosted: Tue Aug 12, 2014 2:16 pm     Reply with quote

As a comment, one thing that might apply, is lack of good smoothing. The SD card draws significant current spikes, and required good smoothing close to it. This is the sort of thing that PCM_programmer would do 'automatically'....

On the pull-ups, it is worth quoting from the SD card spec's:

"All hosts shall provide pull-up resistors on all data lines DAT[3:0] as described in section 6 of the SD Physical Specification Version 1.01."

D3, can be 'got away with', since this has an internal 50K resistor in the card, that is enabled by default. The 'shall' says it all.

The point is that any line set as an input, can float into the 'transition' area, and this results in high consumption, and erratic behaviour...
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