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

ex_fat.c example - mmcsd_init()

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



Joined: 15 Jan 2011
Posts: 62

View user's profile Send private message

ex_fat.c example - mmcsd_init()
PostPosted: Sun Mar 04, 2012 4:26 am     Reply with quote

Hi, is there any hands-on experience with the ex_fat.c example?
An sdcard connected to dspic33 (all 3v3, pullups on cs, sdi, sdo), all signals are there.

The function r1=mmcsd_go_idle_state() in mmcsd_init() always returns 0x80, so I get "ERROR INITIALIZING FAT".. I've decreased the SPI speed at the beginning of mmcsd_init() with

setup_spi(SPI_MASTER | SPI_MODE_0 | SPI_CLK_DIV_512);

and tried mode 0,1,2,3.. The fram device on the same SPI1 (but different /CS) works fine. M.
temtronic



Joined: 01 Jul 2010
Posts: 9246
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Mar 04, 2012 6:41 am     Reply with quote

The driver isn't at fault as CCS doesn't publish anything they haven't checked out several different ways.

You are aware that not ALL SD cards are the same ??? The 'standard' is not always followed !!

Simple test101...

does the card work in a PC ?

can the PIC read data previously stored from a PC ?

who made the SD card(mfr/make/model) . What are the specs (timing/pullup values,Vcc tol/etc.)

You've tried the 4 SPI modes but WHICH one is correct for your card ???
miro



Joined: 15 Jan 2011
Posts: 62

View user's profile Send private message

PostPosted: Sun Mar 04, 2012 7:12 am     Reply with quote

First issue I've found is the bug in setup_spi():

.................... setup_spi(SPI_MASTER | SPI_MODE_0 | SPI_CLK_DIV_512);
04994: BCLR.B 240.6 <<<< this shall be 241.7
04996: MOV #1A0,W4
04998: MOV W4,242
0499A: BSET.B 241.7
So it does not set the proper spi clock rate (measured with LA).

Done manualy:
.................... #WORD SPI1CON1 =0x242
.................... #BIT SPI1EN =0x240.15
.................... SPI1EN=0;
0498C: BCLR.B 241.7
.................... SPI1CON1=0x120;
0498E: MOV #120,W4
04990: MOV W4,242
.................... SPI1EN=1;
04992: BSET.B 241.7

That sets the spi clock rate properly..
miro



Joined: 15 Jan 2011
Posts: 62

View user's profile Send private message

PostPosted: Sun Mar 04, 2012 7:35 am     Reply with quote

@temtronic: did you run that successfully?? Or you do think it works?
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sun Mar 04, 2012 8:00 am     Reply with quote

With "bug in setup_spi()" you mean, that the module isn't disabled before reinitializing it,
e.g. to switch the SPI speed to high after card initialization?

This can be easily achieved with setup_spi(0)
miro



Joined: 15 Jan 2011
Posts: 62

View user's profile Send private message

PostPosted: Sun Mar 04, 2012 8:11 am     Reply with quote

That bug means (at least with dspi33) the spi frequency does not change if you change the prescaler value in setup_spi().
Ttelmah



Joined: 11 Mar 2010
Posts: 19551

View user's profile Send private message

PostPosted: Sun Mar 04, 2012 9:00 am     Reply with quote

Miro's bug is not with the MMC code, but with the settings for his chip.
CCS (unfortunately rather habitually), adds chips to the database, but often gets the control bits, port addresses etc., wrong. In most cases these are fixed after a few more releases, but in some cases they stay for a long time.
You need to contact CCS, with the chip number and compiler version number, pointing out that the code is accessing the wrong bit in the setup_spi function and hopefully they will fix this in the next release.
This is not a fault with the ex_fat example, but is specific to your chip.
If you have the IDE, then you can change the bits used yourself via the device editor.

Best Wishes
temtronic



Joined: 01 Jul 2010
Posts: 9246
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Mar 04, 2012 9:24 am     Reply with quote

yes, code is good....

what PIC are you using ?
miro



Joined: 15 Jan 2011
Posts: 62

View user's profile Send private message

PostPosted: Sun Mar 04, 2012 9:27 am     Reply with quote

However, not to waste too much time - is there somebody who is running the example with an sdcard (does not matter which chip, 4GB SDHC cards)? I've seen some patches related to fat32 but frankly I am in doubt whether the code actually works (ie the timeouts are mostly 0xFF which is a too small value for todays cards, etc). M.
ckielstra



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

View user's profile Send private message

PostPosted: Sun Mar 04, 2012 9:49 am     Reply with quote

Most libraries I've seen are lacking the initialization code for the SDHC cards, so only cards up to 4Gb are supported.
asmallri



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

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

PostPosted: Sun Mar 04, 2012 6:50 pm     Reply with quote

miro wrote:
However, not to waste too much time - is there somebody who is running the example with an sdcard (does not matter which chip, 4GB SDHC cards)? I've seen some patches related to fat32 but frankly I am in doubt whether the code actually works (ie the timeouts are mostly 0xFF which is a too small value for todays cards, etc). M.


I sell a library that supports FAT16 and FAT32 as well as standard and high capacity media.

ckielstra wrote:
Most libraries I've seen are lacking the initialization code for the SDHC cards, so only cards up to 4Gb are supported.

4G cards are only available in high capacity format (SDHC).
_________________
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

View user's profile Send private message

PostPosted: Mon Mar 05, 2012 12:21 am     Reply with quote

Quote:
That bug means (at least with dspi33) the spi frequency does not change if you change the prescaler value in setup_spi().
The changes in your manual coded SPI setup aren't related to prescaler settings in SPICON1, at least for popular dsPIC33 types. You modified SPICON1.7 which is SSEN. It won't be set in master mode (neither for dsPIC30 nor 33), but does no harm as far as I know.
miro



Joined: 15 Jan 2011
Posts: 62

View user's profile Send private message

PostPosted: Mon Mar 05, 2012 1:57 am     Reply with quote

@FvM: the change of 241.7 did the trick - SP1STAT, bit 15, SPIEN.

This works as well:
SPIEN=0;
setup_spi(...);
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Mon Mar 05, 2012 10:36 am     Reply with quote

As said, the problem occurs when the SPI interface had been enabled before. setup_spi(0) also helps in this case.

The problem is mentioned in the PIC24F family reference manual, but possibly missing in the dsPIC30/33 documents.

Quote:
SPIxCON1 and SPIxCON2 can not be written while the SPIx modules are enabled. The SPIEN (SPIxSTAT<15>) bit must be clear before modifying either register.
ckielstra



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

View user's profile Send private message

PostPosted: Tue Mar 06, 2012 1:34 am     Reply with quote

Has someone reported this to CCS?
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