View previous topic :: View next topic |
Author |
Message |
miro
Joined: 15 Jan 2011 Posts: 62
|
ex_fat.c example - mmcsd_init() |
Posted: Sun Mar 04, 2012 4:26 am |
|
|
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: 9225 Location: Greensville,Ontario
|
|
Posted: Sun Mar 04, 2012 6:41 am |
|
|
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
|
|
Posted: Sun Mar 04, 2012 7:12 am |
|
|
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
|
|
Posted: Sun Mar 04, 2012 7:35 am |
|
|
@temtronic: did you run that successfully?? Or you do think it works? |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sun Mar 04, 2012 8:00 am |
|
|
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
|
|
Posted: Sun Mar 04, 2012 8:11 am |
|
|
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: 19504
|
|
Posted: Sun Mar 04, 2012 9:00 am |
|
|
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: 9225 Location: Greensville,Ontario
|
|
Posted: Sun Mar 04, 2012 9:24 am |
|
|
yes, code is good....
what PIC are you using ? |
|
|
miro
Joined: 15 Jan 2011 Posts: 62
|
|
Posted: Sun Mar 04, 2012 9:27 am |
|
|
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
|
|
Posted: Sun Mar 04, 2012 9:49 am |
|
|
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: 1634 Location: Perth, Australia
|
|
Posted: Sun Mar 04, 2012 6:50 pm |
|
|
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
|
|
Posted: Mon Mar 05, 2012 12:21 am |
|
|
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
|
|
Posted: Mon Mar 05, 2012 1:57 am |
|
|
@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
|
|
Posted: Mon Mar 05, 2012 10:36 am |
|
|
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
|
|
Posted: Tue Mar 06, 2012 1:34 am |
|
|
Has someone reported this to CCS? |
|
|
|