|
|
View previous topic :: View next topic |
Author |
Message |
Arjun
Joined: 12 Oct 2010 Posts: 5
|
FAT.c init function is not working ... |
Posted: Tue Oct 12, 2010 5:08 am |
|
|
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
Last edited by Arjun on Tue Oct 12, 2010 6:57 am; edited 2 times in total |
|
|
Arjun
Joined: 12 Oct 2010 Posts: 5
|
|
Posted: Thu Oct 14, 2010 8:32 am |
|
|
can anybody know the solution.....
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
|
|
Posted: Fri Oct 15, 2010 2:03 am |
|
|
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
|
|
Posted: Mon Oct 18, 2010 12:31 am |
|
|
Thanks Andrew for help...
#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
|
|
Posted: Mon Oct 18, 2010 2:26 am |
|
|
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
|
|
Posted: Mon Oct 18, 2010 3:02 am |
|
|
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.
waiting for ur inputs.... |
|
|
andrewg
Joined: 17 Aug 2005 Posts: 316 Location: Perth, Western Australia
|
|
|
andrewg
Joined: 17 Aug 2005 Posts: 316 Location: Perth, Western Australia
|
|
Posted: Mon Oct 18, 2010 7:33 am |
|
|
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
|
|
Posted: Mon Oct 18, 2010 12:02 pm |
|
|
Thanks Andrew ,
Just want to tell you, you really helped me a lot and its working fine.
Thanks a lot.
|
|
|
martind1983
Joined: 22 Mar 2013 Posts: 16
|
|
Posted: Wed Apr 03, 2013 1:55 am |
|
|
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: 19535
|
|
Posted: Wed Apr 03, 2013 2:29 am |
|
|
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
|
Re: FAT.c init function is not working ... |
Posted: Wed Apr 03, 2013 11:49 pm |
|
|
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 |
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. |
|
|
|
|
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
|