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

CCS MMC/SD code problems

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
MikeP



Joined: 07 Sep 2003
Posts: 49

View user's profile Send private message

CCS MMC/SD code problems
PostPosted: Tue Sep 09, 2008 10:19 pm     Reply with quote

Compiler: PCWH V4.078
Hardware: CCS 3.3volt Ethernet board.

I am having a hard time getting fat32 to work so I am trying to make sure the card I am trying to use is compatible with the CCS fat/MMCSD code. Here is a small program that calls 2 functions in mmcsd.c to print out data about the MMC/SD card.

Code:

#include <18F67J60.h>
#fuses NOWDT, HS, NOPROTECT
#use delay(clock=25M)

#use rs232(baud=9600, UART1)

//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 org PIN_C4
#define MMCSD_PIN_SDO     PIN_C5 //o org PIN_C5
#define MMCSD_PIN_SELECT  PIN_C2 //o  org PIN_C2
#include <mmcsd.c>

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

void main(void)
{

   
   printf("\r\n\n%s\r\n%s %s\r\nPCH V%s\r\n\n\n", "MMC/SD Test", __DATE__, __TIME__, __PCH__);
   
    printf( "\r\nRC: %X\r\n", fat_init());
 
   printf( "\r\nRC: %X\r\n", mmcsd_print_cid());
   printf( "\r\nRC: %X\r\n", mmcsd_print_csd());
   printf( "\r\nRC: %X\r\n", mmcsd_print_csd());
 
}


Here is the output.

Code:

MMC/SD Test                                                                           
09-Sep-08 23:39:52                                                                     
PCH V4.078                                                                             
                                                                                       
                                                                                       
                                                                                       
RC: 00                                                                                 
                                                                                       
Manufacturer ID: 03                                                                   
OEM/Application ID: SD                                                                 
OEM/Application ID: SU01G                                                             
Product Revision: 80                                                                   
Serial Number: 20686224                                                               
Manufacturer Date Code: 0065                                                           
CRC-7 Checksum: 63                                                                     
RC: 00                                                                                 
                                                                                       
RC: 82                                                                                 
                                                                                       
CSD_STRUCTURE: 00                                                                     
TAAC: 26                                                                               
NSAC: 00                                                                               
TRAN_SPEED: 32                                                                         
CCC: 05F5                                                                             
READ_BL_LEN: 09                                                                       
READ_BL_PARTIAL: 01                                                                   
WRITE_BLK_MISALIGN: 00                                                                 
READ_BLK_MISALIGN: 00                                                                 
DSR_IMP: 00                                                                           
C_SIZE: 22                                                                             
VDD_R_CURR_MIN: 05                                                                     
VDD_R_CURR_MAX: 05                                                                     
VDD_W_CURR_MIN: 06                                                                     
VDD_W_CURR_MAX: 06                                                                     
C_SIZE_MULT: 07                                                                       
ERASE_BLK_EN: 01                                                                       
SECTOR_SIZE: 1F                                                                       
WP_GRP_SIZE: 7F                                                                       
WP_GRP_ENABLE: 01                                                                     
R2W_FACTOR: 04                                                                         
WRITE_BL_LEN: 09                                                                       
WRITE_BL_PARTIAL: 00                                                                   
FILE_FORMAT_GRP: 00                                                                   
COPY: 01                                                                               
PERM_WRITE_PROTECT: 00                                                                 
TMP_WRITE_PROTECT: 00                                                                 
FILE_FORMAT: 00                                                                       
CRC: A5                                                                               
RC: 00


Notice the two calls to mmcsd_print_csd(). One returns 0X82 second call returns 0x00. Wondering why I have to call it two times. Hopfully knowing the 0x82 error code means will help me out there

Anyone know what error code 0x82 is? It is not listed in the enum MMCSD_err type it stops at 0x80.




Code:

enum MMCSD_err
   {MMCSD_GOODEC = 0,
   MMCSD_IDLE = 0x01,
   MMCSD_ERASE_RESET = 0x02,
   MMCSD_ILLEGAL_CMD = 0x04,
   MMCSD_CRC_ERR = 0x08,
   MMCSD_ERASE_SEQ_ERR = 0x10,
   MMCSD_ADDR_ERR = 0x20,
   MMCSD_PARAM_ERR = 0x40,
   RESP_TIMEOUT = 0x80};
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Tue Sep 09, 2008 11:52 pm     Reply with quote

I tryed to understand the 0x82 result code. To my opinion, its's a result from the underlying spi_xfer(), unfortunately undocumented in the present built-in function documentation, as far as I see.
ckielstra



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

View user's profile Send private message

PostPosted: Wed Sep 10, 2008 6:13 pm     Reply with quote

I don't think 0x82 is an error code but caused by a wrong timing in the SPI bus readings. I have a long standing bug report with CCS, id nr. 8F1552: the SPI bus is now configured for mode 2. This is an invalid configuration for MMC cards as these only support SPI mode 0 or 3.

In mmcsd.c change the line
Code:
#use spi(MASTER, DI=MMCSD_PIN_SDI, DO=MMCSD_PIN_SDO, CLK=MMCSD_PIN_SCL, BITS=8, MSB_FIRST, IDLE=1, stream=mmcsd_spi)
to
Code:
#use spi(MASTER, DI=MMCSD_PIN_SDI, DO=MMCSD_PIN_SDO, CLK=MMCSD_PIN_SCL, BITS=8, MSB_FIRST, IDLE=1, SAMPLE_RISE, stream=mmcsd_spi, FORCE_HW)
MikeP



Joined: 07 Sep 2003
Posts: 49

View user's profile Send private message

PostPosted: Thu Sep 11, 2008 12:47 pm     Reply with quote

I went and got 2 more SD cards to try out and I have one sorta working. Can dir it with the ex_fat.c code but the filenames are messed up a little.

I don't get the 0x82 return code from these SD cards. Both are 1g ones, no microsd to SD adapters.

ckielstra:

Thanks I will have to try that next tuesday when I get back home where my dev board is.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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