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

FAT.c init function is not working ...

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



Joined: 12 Oct 2010
Posts: 5

View user's profile Send private message

FAT.c init function is not working ...
PostPosted: Tue Oct 12, 2010 5:08 am     Reply with quote

Below is my code structure please can anybody suggest what might be the problem.
I am using PIC18F67 and 2 GB SD card.
(I am able to read write to raw memory of SD).
step1:
Code:

#define MMCSD_PIN_SCL     PIN_D6
#define MMCSD_PIN_SDI     PIN_D5
#define MMCSD_PIN_SDO     PIN_D4
#define MMCSD_PIN_SELECT  PIN_D7
          //mmcsd.c file is included

step2:
Code:

#use spi(SPI2, MODE=0, BAUD=1000000, 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)

step3:
Code:

fat_init()        // from the file fat.c

After this step if I check my SD card in pc its asking for format. Every time I format then only I tried for coding.
I tried with mk_file(temp_buff) -->fatopen(temp_buff,wcmd,&fichier);-->fatclose(&fichier);
Please can anybody help this out Rolling Eyes


Last edited by Arjun on Tue Oct 12, 2010 6:57 am; edited 2 times in total
Arjun



Joined: 12 Oct 2010
Posts: 5

View user's profile Send private message

PostPosted: Thu Oct 14, 2010 8:32 am     Reply with quote

can anybody know the solution.....
Crying or Very sad
Is anybody there who can confirm me that they are able to create a file read/write in SD card using fat32 lib files.
andrewg



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

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

PostPosted: Fri Oct 15, 2010 2:03 am     Reply with quote

I think your #use spi code is wrong. This is what I have in my mmcsd.c:
Code:
#use spi(MASTER,CLK=MMCSD_PIN_SCL, DO=MMCSD_PIN_SDO, DI=MMCSD_PIN_SDI, BITS=8, MODE=3, STREAM=MMCSD_SPI, FORCE_HW)
The important differences are mode 3, no baud, no idle, and no sample_rise.

Also, make sure the card is formatted using the same FAT type (16 or 32) as the code is compiled for.
_________________
Andrew
Arjun



Joined: 12 Oct 2010
Posts: 5

View user's profile Send private message

PostPosted: Mon Oct 18, 2010 12:31 am     Reply with quote

Thanks Andrew for help... Idea

#use spi(MASTER,CLK=MMCSD_PIN_SCL, DO=MMCSD_PIN_SDO, DI=MMCSD_PIN_SDI, BITS=8, MODE=3, STREAM=MMCSD_SPI, FORCE_HW)

For FORCE_HW its giving error.
I tested my code once I use MY_FILE function and then if I try to see my card using card reader in PC, its asking for format. If I see my card memory using property its showing 0 bytes used. The same thing if I try to see SD memory using some HEX editor. I can see my file name in the starting location in SD card (Any file name which I try to create using MY_FILE function).

Can anybody help me out ....
andrewg



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

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

PostPosted: Mon Oct 18, 2010 2:26 am     Reply with quote

You say you're using an 18F67....what? Also, what version of the compiler are you using? You probably need a very recent one to support SPI2.
_________________
Andrew
Arjun



Joined: 12 Oct 2010
Posts: 5

View user's profile Send private message

PostPosted: Mon Oct 18, 2010 3:02 am     Reply with quote

Thanks Andrew ,
am using PIC18F67 and 2 GB kingstone SD card.
CCS is new ver ie CCS 4.1,i am able to see raw memory in which i can notice my file name in there. Sad

waiting for ur inputs....
andrewg



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

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

PostPosted: Mon Oct 18, 2010 7:28 am     Reply with quote

If you're using the mmcsd.c and fat.c library files provided by CCS, then you should read my two threads:

http://www.ccsinfo.com/forum/viewtopic.php?t=43417
http://www.ccsinfo.com/forum/viewtopic.php?t=43402

The first addresses a bug in cluster chaining and the second adds MBR support.
_________________
Andrew
andrewg



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

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

PostPosted: Mon Oct 18, 2010 7:33 am     Reply with quote

I forgot to mention, in future, please be more precise, otherwise you end up wasting everyone's time. There is no such device as a 18F67, there are 10 devices that start with that designation and for future questions it might be important to know exactly which PIC you're using. Same for the CCS version. There are three digits after the decimal place, and they all can be important. eg, 4.112, or whatever.
_________________
Andrew
Arjun



Joined: 12 Oct 2010
Posts: 5

View user's profile Send private message

PostPosted: Mon Oct 18, 2010 12:02 pm     Reply with quote

Thanks Andrew , Cool
Just want to tell you, you really helped me a lot and its working fine.
Thanks a lot.
Laughing
martind1983



Joined: 22 Mar 2013
Posts: 16

View user's profile Send private message

PostPosted: Wed Apr 03, 2013 1:55 am     Reply with quote

andrewg wrote:
I think your #use spi code is wrong. This is what I have in my mmcsd.c:
Code:
#use spi(MASTER,CLK=MMCSD_PIN_SCL, DO=MMCSD_PIN_SDO, DI=MMCSD_PIN_SDI, BITS=8, MODE=3, STREAM=MMCSD_SPI, FORCE_HW)
The important differences are mode 3, no baud, no idle, and no sample_rise.

Also, make sure the card is formatted using the same FAT type (16 or 32) as the code is compiled for.


Andrewg I read my card also in MODE=0 so I don't know why do you always suggest people to use MODE=3?
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Wed Apr 03, 2013 2:29 am     Reply with quote

Have a look at the simplified SPI timing diagrams:

<mfb.nopdesign.sk/datasheet/cat_d/MMC/spitiming.pdf>

Notice where the clock line sits between bytes (high). Realise that this also means the pull up resistors are not wasting power being driven when data is not being sent. What mode numbers give this?. (not 0.....).

Best Wishes
martind1983



Joined: 22 Mar 2013
Posts: 16

View user's profile Send private message

Re: FAT.c init function is not working ...
PostPosted: Wed Apr 03, 2013 11:49 pm     Reply with quote

Arjun wrote:
Below is my code structure please can anybody suggest what might be the problem.
I am using PIC18F67 and 2 GB SD card.
(I am able to read write to raw memory of SD).
step1:
Code:

#define MMCSD_PIN_SCL     PIN_D6
#define MMCSD_PIN_SDI     PIN_D5
#define MMCSD_PIN_SDO     PIN_D4
#define MMCSD_PIN_SELECT  PIN_D7
          //mmcsd.c file is included

step2:
Code:

#use spi(SPI2, MODE=0, BAUD=1000000, 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)

step3:
Code:

fat_init()        // from the file fat.c

After this step if I check my SD card in pc its asking for format. Every time I format then only I tried for coding.
I tried with mk_file(temp_buff) -->fatopen(temp_buff,wcmd,&fichier);-->fatclose(&fichier);
Please can anybody help this out Rolling Eyes


I seen the problem might also be, that in directive #USE SPI you use both SPI2 option and optional pins for software SPI. If you use SPI2 option it automatically switches pins assigned with SPI2 hardware so you cannot set your own election. And I am not sure, but when you use #SPI_HARDWARE option the result is the same. Compiler automatically build code to set pins associate with hardware SPI. I can't tell you for 100%, because I have never tried this combination.
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