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

SD card memory problem
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
andrewg



Joined: 17 Aug 2005
Posts: 316
Location: Perth, Western Australia

View user's profile Send private message Visit poster's website

PostPosted: Mon May 06, 2013 9:04 am     Reply with quote

I don't know what mmcsd_read_ocr() does, but it is described as a "non-user function". I would ignore all "non-user functions" and just consider "user functions". mmcsd_crc7() and mmcsd_crc16() are also "non-user functions". Ignore them too.

I didn't expect you to test the functions individually, just develop your project as normal, but include error checking of every mmcsd function you call.

If mmcsd_write_block() isn't returning, then there is a fault in the comms between the pic and the card, or a fault in the card itself. Try slowing down the SPI clock speed. Try a different SD card.
_________________
Andrew
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon May 06, 2013 3:02 pm     Reply with quote

Quote:
When i run the functions mmcsd_write_block,mmcsd_read_block the program stop (don't produce anything).
Code:

mmcsd_write_block(1, 1, *10);
from the help in mmcsd.c:
Quote:
//// mmcsd_write_block(a, s, p): ////
//// Writes an entire page to the SD/MMC. This will write an ////
//// entire page to the SD/MMC, so the address and size must be ////
//// evenly divisble by 512. At the application level it is much ////
//// more effecient to use mmcsd_write_data() or mmcsd_write_byte().////
//// Returns 0 if successful, non-zero if error. ////
Your address and size are wrong! That's why the driver hangs on this code.

Also, the notation '*10' is very, very, strange. It will give you the contents of the data stored at address 10, then mmcsd_write_block will use this (unknown) value as an address pointer for reading data to store on the SD card... Well, you are just testing so it isn't really important what data you are pointing to, but then, why not use the value '10' instead of '*10'? Still a stupid value, but little bit less confusing.

Better to try something like:
Code:
mmcsd_write_block(4096, 512, 10);
Try avoiding to the first few 512 byte blocks because that is where the Master Boot Record and other FAT32 info are stored so you will have to format the card again. (4096 might still be too low, I didn't do any research for safe low values).
Jim90



Joined: 27 Apr 2013
Posts: 55

View user's profile Send private message

SD card memory problem
PostPosted: Mon May 06, 2013 6:57 pm     Reply with quote

I used a component like this :
http://www.babelduck.com/sd-card-module/
IS this ok or maybe the problem is there ?

I used the following code
Code:

mmcsd_write_block(4096, 512, 10);
if (mmcsd_write_block(4096, 512, 10) == MMCSD_GOODEC)
{printf("(mmcsd_write_block(4096, 512, 10) successfully, proceed");
}
else
{  printf("didn't (mmcsd_write_block(4096, 512, 10) ");}



but the results are little strange as presented at the picture below:

http://obrazki.elektroda.pl/1788907500_1367887454.png

Then i put a printf statement in the function MMCSD_err mmcsd_write_block (as presented below).
The printf statement does not appear at the screen so the function is not accessed.
Code:

MMCSD_err mmcsd_write_block(uint32_t address, uint16_t size, uint8_t* ptr)
{   MMCSD_err ec;
   uint16_t i;
////////////////////////
printf("HELLO\n");
////////////////////////

Can you understand what is going wrong ?
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue May 07, 2013 3:41 am     Reply with quote

The garbage characters in your RS232 communication are most likely caused by the clock being driven from an RC-oscillator. Stable RS232 requires the clock to be within 3% error margin. Given that most capacitors have 10-20% tolerance I'm surprised you receive any readable data at all.
Then, with temperature changes the clock will change a lot too.

The only way to get reliable R232 is to use a crystal or external clock driver.

SPI is not sensitive to variations in the clock speed so this is not what causes your SD card problems.

I couldn't find a schematic for your SD card interface module. There are a lot more resistors mounted than I would expect. Most likely these are the required pull-up resistors for the clock and data lines. That's fine, as long as you didn't add extra pull up resistors on your own board as well.

The only reason for "HELLO" not being printed in your modified mmcsd_write_block() function I can think of is that you have made a copy of the C-file and that the compiler is still using the original file and not your modified copy. To prove this, make a syntax error in the file and see if the compiler generates an error message.
Jim90



Joined: 27 Apr 2013
Posts: 55

View user's profile Send private message

SD card memory problem
PostPosted: Wed May 08, 2013 8:05 pm     Reply with quote

ckielstra i tried to implement your advice but unfortunately without success.

I use the fuses below :
#fuses HS, NOWDT, PR, NOPUT,NOPROTECT
#use delay (clock=20M)

and a 20M crystal with resistor and 2, 27pF.

also i did the change below (after the compiler's message)

/*#use spi(MASTER, DI=MMCSD_PIN_SDI, DO=MMCSD_PIN_SDO, CLK=MMCSD_PIN_SCL, BITS=8, MSB_FIRST, MODE=3, stream=mmcsd_spi,BAUD=4800)
*/

#use spi(MASTER, DI=MMCSD_PIN_SDI, DO=MMCSD_PIN_SDO, CLK=MMCSD_PIN_SCL, BITS=8, MSB_FIRST, MODE=3, stream=mmcsd_spi,BAUD=9600)



Can you suggest me what to do ???
Ttelmah



Joined: 11 Mar 2010
Posts: 19529

View user's profile Send private message

PostPosted: Thu May 09, 2013 1:09 am     Reply with quote

and, with that done, have you tested that the unit is running at the expected frequency?.
Simple basic test. Pulse a line on ()feeding an LED). have it stay high for (say) ten seconds, and then drop. Time this with a stopwatch. Are you actually getting 10 seconds (not 9.5, or 10.5)?.
This is the core of all debugging an testing. Do one thing at a time, and _prove this is working rioght_, before trying to move forward.

Best Wishes
andrewg



Joined: 17 Aug 2005
Posts: 316
Location: Perth, Western Australia

View user's profile Send private message Visit poster's website

PostPosted: Thu May 09, 2013 6:03 am     Reply with quote

I thinks there's some confusion between SPI and RS232. The #use SPI should not have baud=9600 (or any baud at all).
_________________
Andrew
Jim90



Joined: 27 Apr 2013
Posts: 55

View user's profile Send private message

SD card memory problem
PostPosted: Thu May 09, 2013 6:45 pm     Reply with quote

Ttelmah i fix the problem (it was a bad connection of resistor to the crystal)

andrewg i replace the
Code:

#use spi(MASTER, DI=MMCSD_PIN_SDI, DO=MMCSD_PIN_SDO, CLK=MMCSD_PIN_SCL, BITS=8, MSB_FIRST, MODE=3, stream=mmcsd_spi,BAUD=9600) 

with

Code:

#use spi(MASTER, DI=MMCSD_PIN_SDI, DO=MMCSD_PIN_SDO, CLK=MMCSD_PIN_SCL, BITS=8, MSB_FIRST, MODE=3, stream=mmcsd_spi)



finally i can see to the screen the 2 messages that show that the two functions ( mmcsd_write_block and mmcsd_read_block) are not working.

The code which i used is :
Code:

   printf("\n");
mmcsd_write_block(4096, 512, 10);
if (mmcsd_write_block(4096, 512, 10) == MMCSD_GOODEC)
{
 printf("(mmcsd_write_block(4096, 512, 10) successfully, proceed");
}
else
{
 printf("didn't (mmcsd_write_block(4096, 512, 10) ");
}
printf("\n");
                                    mmcsd_read_block(4096, 512, 10);
if (mmcsd_read_block(4096, 512, 10) == MMCSD_GOODEC)
{
 printf("mmcsd_read_block(4096, 512, 10) successfully, proceed");
}
else
{
printf("didn't mmcsd_read_block(4096, 512, 10)");
}



What i need to change to fix these functions ?
andrewg



Joined: 17 Aug 2005
Posts: 316
Location: Perth, Western Australia

View user's profile Send private message Visit poster's website

PostPosted: Fri May 10, 2013 8:47 pm     Reply with quote

The code you've quoted seems to show calls mmcsd_write_block and mmcsd_read_block are duplicated, first not checking the return code, then checking the return code. You only want the call that checks the return code.

To assist in determining what the problem is, what is the error code returned by the calls?
_________________
Andrew
andrewg



Joined: 17 Aug 2005
Posts: 316
Location: Perth, Western Australia

View user's profile Send private message Visit poster's website

PostPosted: Fri May 10, 2013 8:52 pm     Reply with quote

I've also checked your method of calling the function. The ",10" part of the parameters "(4096, 512, 10)" does not seem correct. That should be a pointer to a buffer. Your code should be more like:
Code:
uint8_t buf[512];
MMCSD_err err;
// ...
err = mmcsd_write_block(4096, 512, buf);
if (err == MMCSD_GOODEC)
{
  printf("write block OK\n");
}
else
{
  printf("write block fail:%d\n", err);
}
// ...

_________________
Andrew
Jim90



Joined: 27 Apr 2013
Posts: 55

View user's profile Send private message

SD card memory problem
PostPosted: Sat May 11, 2013 7:21 am     Reply with quote

andrewg did you use the code that you wrote and test it ?

If yes what was the results ?

I tried the code and again i receive the message :

write block fail :-128

(128)10 = 80 in Hex


In enum MMCSD_err is define that

RESP_TIMEOUT = 0x80

what does mean this ? (communication problem between card and microcontroller ?)

How to fix it ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19529

View user's profile Send private message

PostPosted: Sat May 11, 2013 11:25 am     Reply with quote

The error is printed with %d. The format only has ':'. The -, is a negative sign. -128, is 0xFF hex.

If you look at the code, the returned error is from the defined values if the functions themselves return errors, but if the SD card returns anything that and's with 0xA, and is non zero, you get back the byte returned by the card.

Best Wishes
Jim90



Joined: 27 Apr 2013
Posts: 55

View user's profile Send private message

SD card memory problem
PostPosted: Sat May 11, 2013 7:48 pm     Reply with quote

Ttelmah, i have a little confusion.

If i replace the
printf("write block fail:%d\n", err);

to

printf("write block fail:%x\n", err);

and then i receive the value 80. (Ttelmah, according to what you described i expect it to receive -80).
andrewg



Joined: 17 Aug 2005
Posts: 316
Location: Perth, Western Australia

View user's profile Send private message Visit poster's website

PostPosted: Sat May 11, 2013 9:13 pm     Reply with quote

"%x" will print err as an unsigned hex value, e.g. "80" just like you see. If you like, you could change the printf to:
Code:
printf("write block fail:0x%x\n", err);
That isn't really dealing with the MMC problem.

If mmcsd_block_write is returning RESP_TIMEOUT, then a look at the source code reveals that it must be mmcsd_write_single_block returning RESP_TIMEOUT. It can't be the code path involving mmcsd_get_r1 because that will only return if (ec & 0x0A) is non-zero, which is not true if the ec is RESP_TIMEOUT.

If you follow the code, that will be because mmcsd_get_r1 times out waiting for a response from the card. In other words, a communications problem.

Just double-checking, but did mmcsd_init() return MMCSD_GOODEC?
_________________
Andrew
Jim90



Joined: 27 Apr 2013
Posts: 55

View user's profile Send private message

SD card memory problem
PostPosted: Sun May 12, 2013 8:08 pm     Reply with quote

andrewg, you said that :
"I've also checked your method of calling the function."

Did you try to compile the functions of mmcsd_write_block,mmcsd_read_block and program an SD card ?

If yes did it working ?(and if is working what are the differents from my code/design?)
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