View previous topic :: View next topic |
Author |
Message |
hemasc_
Joined: 01 Aug 2012 Posts: 15 Location: Brazil
|
SD Card FAT CCS |
Posted: Thu Sep 12, 2013 2:52 pm |
|
|
Guys, I'm trying to write data to an SD Card (FAT).
I tried to use the library of CCS but no success.
Could anyone help me which way to go? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Thu Sep 12, 2013 3:11 pm |
|
|
99% of all 'problems' are with hardware !
You either need a 3V ( LF series) PIC dirctly connected to the SD card OR logic level translator chip between 5V PIC and 3V SD card.
Use the 'search' feature here and you'll get 100s of hits about how to interface PICs with SD cards...
If I knew I'd get paid, I'd write a book about this one subject.....
hth
jay |
|
|
hemasc_
Joined: 01 Aug 2012 Posts: 15 Location: Brazil
|
|
Posted: Thu Sep 12, 2013 3:28 pm |
|
|
My hardware was tested. It´s okay. I make a simple communication by SPI and it´s okay.
But the problem is FAT format.
I tried to use the library of CCS, but not compiled.
I have not found here topics that FAT library was used correctly... |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Thu Sep 12, 2013 6:06 pm |
|
|
obvious question...
what size is the SD card ? |
|
|
hemasc_
Joined: 01 Aug 2012 Posts: 15 Location: Brazil
|
|
Posted: Thu Sep 12, 2013 7:29 pm |
|
|
temtronic, what can be obvious for you, can not be for others...
my SD card is 2G, but I can't compile the FAT library |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Sep 12, 2013 9:30 pm |
|
|
1. What's your CCS compiler version ?
2. What's your PIC ?
3. Post a list of the CCS files that you are trying to compile.
3. Post the compiler errors that you get. If there are many of them,
then just post the first 10 errors. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Fri Sep 13, 2013 5:17 am |
|
|
I asked about the size, as the library only runs on 2GB or smaller cards.Your reply to me, says you can't compile which is different than what I read in your OP.
As PCM P says, we need more 'data'.
Since you say the hardware is 'ok', then it's probably a simple miscoding issue.
jay |
|
|
hemasc_
Joined: 01 Aug 2012 Posts: 15 Location: Brazil
|
|
Posted: Fri Sep 13, 2013 8:45 am |
|
|
PCM progammer:
1 - 4.120
2 - 18F87k90
3 - fat.h and mmcsd.h (I changed the extension to .h, both were .c)
4 -
fat.h" Line 607(26,27): Undefined identifier -- mmcsd_write_data
fat.h" Line 614(28,29): Undefined identifier -- mmcsd_read_data
temtronic:
I knew the size of the SD card that can be used with FAT |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19496
|
|
Posted: Fri Sep 13, 2013 9:10 am |
|
|
Change the extensions back to c. The files each 'use' the names of the other part as .c.
It is a matter of 'taste' using .h, or .c. The point is that these are compilable code, not just 'defines', so .c is perfectly correct as the extension for these. Most CCS examples, use .h for the files that just define things or link other stuff, and .c for actual code, _and are setup to compile this way_. mmcsd_write_data, and read_data, are defined in mmcsd.c. Which is 'where' fat.c looks for it.
If you change the extension, you will need to change every reference to the files as well.
Best Wishes |
|
|
hemasc_
Joined: 01 Aug 2012 Posts: 15 Location: Brazil
|
|
Posted: Fri Sep 13, 2013 9:46 am |
|
|
I changed the extensions to .c and
fat.c" Line 607(26,27): Undefined identifier -- mmcsd_write_data
fat.c" Line 614(28,29): Undefined identifier -- mmcsd_read_data
when I changed to .h, I modified all references |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Sep 13, 2013 12:14 pm |
|
|
It compiled OK for me. First I did a text search to find which CCS
example files use those driver files and I found Ex_Fat.c is the file.
I installed PCH vs. 4.120 and used the Project Wizard in MPLAB vs. 8.91
to make a project called Ex_Fat in the CCS \Examples directory. I added
the source file Ex_Fat.c to the project and made sure MPLAB was set to
compile in Release mode.
I edited the first few lines of Ex_Fat.c to change the #include for the PIC
and the #fuses so they would work with the 18F87K90:
Code: |
//#include <18F67J60.h>
#include <18F87K90.h> // *** Changed PIC
#device PASS_STRINGS = IN_RAM
//#fuses NOWDT, HS, NOPROTECT
#fuses NOWDT, HSH, NOPROTECT // *** Changed oscillator fuse
#use delay(clock=25M) |
Then I clicked the compile button and it compiled without errors:
Quote: |
Executing: "C:\Program Files\PICC\Ccsc.exe" +FH "ex_fat.c" +DF +LN -T +A +M -Z +Y=9 +EA #__18F87K90=TRUE
>>> Warning 202 "ex_fat.c" Line 28(5,8): Variable never used: rs232_errors
Memory usage: ROM=21% RAM=36% - 47%
0 Errors, 1 Warnings.
Loaded C:\Program Files\PICC\Examples\ex_fat.cof.
BUILD SUCCEEDED: Fri Sep 13 11:06:38 2013
|
From the .LST file:
Code: |
CCS PCH C Compiler, Version 4.120, xxxx 13-Sep-13 11:06
Filename: C:\Program Files\PICC\Examples\ex_fat.lst
ROM used: 27778 bytes (21%)
Largest free fragment is 65536
RAM used: 1381 (36%) at main() level
1806 (47%) worst case
Stack: 17 locations
|
|
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Fri Sep 13, 2013 12:20 pm |
|
|
Sigh...
Why did you start to modify the CCS supplied library code? It is supposed to work the way it is.
I hope you have learned an important lesson: don't fix anything if it ain't broken!!!
Go back to the original situation. Perhaps install the CCS compiler again to make 100% sure you have not modified anything.
The error you show is because the function mmcsd_write_data() can not be found. If you look into the file fat.c you will see it is not there, that's because it is in the file mmcsd.c. To fix the error you will have to include this file as well.
All these problems would have been avoided when you would have started to use the example program ex_fat.c. My suggestion is that you start using this program now and only when things are working you make the next step to create your own program.
Just a few more tips to help you:
- Don't use the format function from the CCS fat driver. It only implements a limited format and several people reported problems with it.
- The CCS FAT driver can not handle cards that are formatted with multiple partitions. Once a card is formatted with multiple partitions this is hard to remove again. Even brand new cards often come pre-formatted and might be wrong for this library. Best is to format your card in a photo camera.
- The CCS library is known to have a few bugs. Have a look in the Code Library section of this forum to find the work arounds.
Edit: I see PCM posted an answer while I was typing this but decided to have my answer here as well. |
|
|
hemasc_
Joined: 01 Aug 2012 Posts: 15 Location: Brazil
|
|
Posted: Fri Sep 13, 2013 12:46 pm |
|
|
thanks PCM programmer, I compiled
I will make tests and then post the results here
ckielstra, I learned my lesson |
|
|
hemasc_
Joined: 01 Aug 2012 Posts: 15 Location: Brazil
|
|
Posted: Fri Sep 20, 2013 12:41 pm |
|
|
I was testing new hardware and noticed something very strange
when I run output_high(MMCSD_PIN_SELECT); //port D7 (18F87k90).... the voltage was 3.3 V for 0.3V with or without the SD card
when I run output_low(MMCSD_PIN_SELECT); //port D7 (18F87k90).... the voltage was 0.3 V for 3,8V with SD Card and for 3,2V without the SD card
I dont found short circuit
my electrical schematic
http://dl.dropboxusercontent.com/u/3490869/c%C3%B3digos/Sd%20Card/esquema/esquema.png |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Fri Sep 20, 2013 2:30 pm |
|
|
First answer in this thread was: temtronic wrote: | 99% of all 'problems' are with hardware !
You either need a 3V ( LF series) PIC dirctly connected to the SD card OR logic level translator chip between 5V PIC and 3V SD card. | Your answer: hemasc_ wrote: | My hardware was tested. It´s okay. | Now it turns out you are using a 5V processor and voltage divider...
I'm out. |
|
|
|