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

SD kart programming using elm chan PetitFat library
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Ttelmah



Joined: 11 Mar 2010
Posts: 13054

View user's profile Send private message

PostPosted: Thu Feb 22, 2018 1:55 am     Reply with quote

'Answers on a postcard', regarding PetitFat...

I've use the CCS drivers, and the Brush Electronics drivers. Both of these work. The CCS ones needed some tweaks (in the code library). The Brush Electronics ones work. They need a little tweaking if you want to run DMA (I do on a PIC24), but because they are logically written it is actually fairly easy to do this.
There are a lot of posts on the MicroChip forums with people having what is apparently the same problem with PetitFat, but the fixes I have posted here should fix the issue they are talking about.
salih260



Joined: 19 Feb 2018
Posts: 23

View user's profile Send private message

PostPosted: Thu Feb 22, 2018 3:31 am     Reply with quote

Thanks Ttelmah, for you helping.

Also my max spi speed 2 MHz. This effected on FAT or not ?
if I over 2MHz speed, sd card not respond.

I communicate with the SD card, but unfortunately it does not come to the library.
I do not understand this. I will now experiment with pic18f4431. Maybe the problem is dspic33.
I will write the results here.

Good work.
temtronic



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

View user's profile Send private message

PostPosted: Thu Feb 22, 2018 6:25 am     Reply with quote

The reason I asked about testing with a 24 PIC is that PetitFAT has code for a 24 series PIC. I'll 'assume' it worked for them, otherwise they would not have published it.
Now you're going to an 18 Series PIC, which PetitFAT do not have an example, so you may run into problems. You're best to confirm proper speed and operation of the PIC before attempting any FAT code.

Now with the 18 PIC you can use the CCS supplied driver, just be sure to read all the embedded comments and search this forum as well.

Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 13054

View user's profile Send private message

PostPosted: Thu Feb 22, 2018 1:08 pm     Reply with quote

You do realise the 4431 is a 5v PIC, so you need level shifting to operate an SD card. Look at the sticky at the head of the forum.
You also do realise you are not meant to just run at 2MHz. The SPI specification _requires_ the initial communications to be done at 400K max. Only after you have established comms and verified the chip supports a higher rate can you switch up to this rate.
salih260



Joined: 19 Feb 2018
Posts: 23

View user's profile Send private message

PostPosted: Thu Feb 22, 2018 11:48 pm     Reply with quote

I read Datasheet, I know. first <400kHz. I'm doing the speed 2 MHz after the SD card is initialize.
salih260



Joined: 19 Feb 2018
Posts: 23

View user's profile Send private message

FatFs Library
PostPosted: Fri Feb 23, 2018 12:01 am     Reply with quote

Thanks Ttelmah.

I'm now in the FatFs library. Because PetitFat has failed most people.
When I include the Fat library, I get this error.

This error line:
Code:

FRESULT f_forward (FIL* fp, UINT(*func)(const BYTE*,UINT), UINT btf, UINT* bf);   /* Forward data to the stream */


this faulty part
Code:

UINT(*func)(const BYTE*,UINT)


and these error messages:
Code:

*** Error 28 ff.h" Line 266(33,34): Expecting an identifier
*** Error 48 ff.h" Line 266(35,39): Expecting a (
*** Error 43 ff.h" Line 266(40,41): Expecting a declaration
*** Error 28 ff.h" Line 266(52,53): Expecting an identifier
*** Error 43 ff.h" Line 266(57,58): Expecting a declaration
*** Error 43 ff.h" Line 266(58,59): Expecting a declaration
*** Error 31 ff.h" Line 266(70,74): Identifier is already used in this scope
*** Error 48 ff.h" Line 266(76,78): Expecting a (
*** Error 43 ff.h" Line 266(79,80): Expecting a declaration


good work.
Ttelmah



Joined: 11 Mar 2010
Posts: 13054

View user's profile Send private message

PostPosted: Fri Feb 23, 2018 2:25 am     Reply with quote

Why not use a CCS library?.
salih260



Joined: 19 Feb 2018
Posts: 23

View user's profile Send private message

PostPosted: Fri Feb 23, 2018 2:57 am     Reply with quote

i use it but not working. so mmcsd.c is work but fat.c not working.
salih260



Joined: 19 Feb 2018
Posts: 23

View user's profile Send private message

PostPosted: Fri Feb 23, 2018 3:01 am     Reply with quote

Ttelmah wrote:
Why not use a CCS library?.

Are you use CCS library?
Ttelmah



Joined: 11 Mar 2010
Posts: 13054

View user's profile Send private message

PostPosted: Fri Feb 23, 2018 3:27 am     Reply with quote

As you have already been told, you should add the fixes from the code library.

However the CCS library will largely work without these. The fact that we are back to "it doesn't work", says to me that you do have a fault somewhere in your hardware. Though you say you can read the card, have you tried a basic test of reading a sector, and comparing the result to what A PC shows for the same sector?. Also that it goes notably wrong over 2MHz, suggests you may well have a signalling problem somewhere.

Basic requirements for SD:

3.3v PIC or level translation to 3.3v.
Capacitor with really good HF response adjacent to the card (the instantaneous pulses at nSec timings introduced by the card are huge). Ideally something like a 47uF multi-layer ceramic. or a electrolytic paralleled with a smaller standard ceramic.
10K pullups on DAT1, DAT2, The cards Data_Out, and the CS line. The Data_Out one is needed to speed up the rising edge of the data. The DAT1 & DAT2 ones ensure the card wakes up in the correct mode. The CS one ensures this line is held high while the PIC is booting.
Lines run as HF signals, so no sharp corners, kept reasonably short, preferably with a continuous ground plane underneath (avoid crossing plane splits), and with reasonable spacing to other tracks. Keep capacitance low. Preferably keep the signal traces close to the same length (especially if they are longer than perhaps 75mm). Have the pullups immediately adjacent to the tracks (no 'stubs' running to resistors mounted a distance away). You should be able to clock to 8MHz on a modern SD without issues.

Have a look at this:
<http://www.embedded-code.com/source-code/resources/signal-noise-issues-with-mmc-sd-memory-cards-clocked-devices-in-general>

Which describes the issue very well.
salih260



Joined: 19 Feb 2018
Posts: 23

View user's profile Send private message

PostPosted: Fri Feb 23, 2018 3:48 am     Reply with quote

my pull up resistor value 4.7k. this cause a problem? Also i do not think so.
Because i read/write sd card sectors.
salih260



Joined: 19 Feb 2018
Posts: 23

View user's profile Send private message

PostPosted: Fri Feb 23, 2018 3:52 am     Reply with quote

I will go nuts. would you look at the following line:

Code:

\ff.c" Line 544(59,60): Undefined identifier   TBL_DC


how am I going to fix this error ?
Ttelmah



Joined: 11 Mar 2010
Posts: 13054

View user's profile Send private message

PostPosted: Fri Feb 23, 2018 6:28 am     Reply with quote

By finding the definition for TBL_DC.

It suggests there is another file that needs to be loaded first.

However I repeat my question of whether you have genuinely checked you are getting the right result from reading a sector. Try reading sector 0, and displaying it or sending it to the serial. Then do the same for the same sector on a PC, and make sure everything agrees totally. Even a single bit error will prevent every driver from working.

It should not go wrong with increasing frequency. That is does says you have got a signalling problem .
temtronic



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

View user's profile Send private message

PostPosted: Fri Feb 23, 2018 6:28 am     Reply with quote

As MR T explains, you need to get the hardware 100% correct BEFORE trying any software. For instance, the 4K7 will pull 2x the current the 10K will. Depending on the capacitance of the layout that will affect performance.
A simple test, since you must 'boot' at 400KHz STAY at 400KHz and test the card at the 'slow' speed. Does it 100% work? (read,write,bytes, sectors,etc) a COMPLETE test of all functions? IF so then you know a) basic hardware is ok (note lower case OK) and b) the driver is OK. If it fails at a higher speed, then you KNOW it's a hardware issue. Possibly board layout, wrong value of components, bad power. Board issues include high capacitance, cross talk, etc. You're usng 4k7 pullups when 10K is the suggested values. Power supply could be 'marginal'. I'd suspect a solid 1 amp would be the minimum WITH proper bypass and filter caps at PIC and SD connector.
For the best support here, use the CCS drivers, they are KNOWN to work and are familiar to users here.
salih260



Joined: 19 Feb 2018
Posts: 23

View user's profile Send private message

PostPosted: Fri Feb 23, 2018 7:57 am     Reply with quote

thank you very much Ttelmah and temtronic..
Does the SD card draw much current? If so, it means 100% hardware problem. Because SD card + Pic + etc. It is fed from 3v3 regulator.
(Regulator max. output current is 1A.)


Last edited by salih260 on Sat Feb 24, 2018 1:31 am; edited 2 times in total
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
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