View previous topic :: View next topic |
Author |
Message |
electr0dave
Joined: 10 Aug 2014 Posts: 24
|
MMC SD libraries - yap this topic again |
Posted: Sun Aug 10, 2014 2:46 pm |
|
|
Hello everyone.
I've tried all the codes I found here on the forum (yes, I know there are many).
I could not hit with any!
I'm using the PROTEUS to simulate the circuit with VDD of 3.3V (for the PIC and the card), I'm using a valid image of an MMC card (already tested with Flowcode).
I'm bored, because I'm following the example file of CCS, "ex_fat.c" but still does not work.
What is the idea of selling a compiler (which contains all libraries example) which then does not work. I do not understand the logic ....
I am using a PIC18F46K20.
upload foto
Code: |
#include <main.h>
#use rs232(baud=9600, UART1, errors)
//media library, a compatable media library is required for FAT.
#use fast_io(c)
//#define MMCSD_SPI_HW
#define MMCSD_PIN_SCL PIN_C3 //o
#define MMCSD_PIN_SDI PIN_C4 //i
#define MMCSD_PIN_SDO PIN_C5 //o
#define MMCSD_PIN_SELECT PIN_C2 //o
#include <mmcsd.c>
//FAT library.
#include <fat.c>
void main(void)
{
int resp; // pointer to the buffer
//output_low( PIN_C0);
delay_ms(1000);
while(1)
{
resp = fat_init();
printf ("\r\nresp = %d\r\n", resp);
delay_ms(100);
}
}
|
I always get the same value of fat_init () function, whether the card is inserted or not.
free image host
I've looked all over the forum ...
The threads I found are quite old and very confused. On the same topic I could find several times the same thing written.
Could not find a topic organized and documented so that really is a help for those who want to do something and not have to "invent the wheel again."
Can anyone help me or give me some guidelines to make progress.
Thank you |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
Re: MMC SD libraries - yap this topic again |
Posted: Sun Aug 10, 2014 3:18 pm |
|
|
electr0dave wrote: | Hello everyone.
I've tried all the codes I found here on the forum (yes, I know there are many).
I could not hit with any!
I'm using the PROTEUS to simulate the circuit with VDD of 3.3V (for the PIC and the card), I'm using a valid image of an MMC card (already tested with Flowcode).
I'm bored, because I'm following the example file of CCS, "ex_fat.c" but still does not work.
What is the idea of selling a compiler (which contains all libraries example) which then does not work. I do not understand the logic ....
I am using a PIC18F46K20.
I've looked all over the forum ...
The threads I found are quite old and very confused. On the same topic I could find several times the same thing written.
Could not find a topic organized and documented so that really is a help for those who want to do something and not have to "invent the wheel again."
Can anyone help me or give me some guidelines to make progress.
Thank you | Have you taken the trouble to read what other forum members think of PROTEUS/ISIS?
It is a more or less complete waste of time.
Answer to all your questions.
Mike |
|
|
electr0dave
Joined: 10 Aug 2014 Posts: 24
|
|
Posted: Sun Aug 10, 2014 4:38 pm |
|
|
Hello.
Thanks for the nice replies.
I just do not understand why I have done the same project in Flowcode and everything works fine.
In fact, more people were able to put it into operation ....
http://www.studentcompanion.co.za/post/2013/08/15/Interfacing-SD-Card-to-a-PIC-Microcontroller-Flowcode
About the links, I quote:
Quote: | Proteus works fine with MikroC and the FAT Libraries. |
Quote: | I have done SD card project using mikroC Compilers and it works fine in hardware and also Proteus. |
I do not want to start using mikroC.
It's annoying having to split the projects:
* Better reliability and control MCU - XC8
* Speed of building code - Flowcode
* Write data in MMC / SD card - mikroC
* .... |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1933 Location: Norman, OK
|
|
Posted: Sun Aug 10, 2014 5:11 pm |
|
|
Then I would suggest using MikroC if you insist on using Proteus...
Apparently you have been using everything else.. _________________ Google and Forum Search are some of your best tools!!!! |
|
|
electr0dave
Joined: 10 Aug 2014 Posts: 24
|
|
Posted: Sun Aug 10, 2014 5:21 pm |
|
|
dyeatman,
I do not insist on using PROTEUS ...
Obviously it's an excellent tool for quick test ... about it, no one can deny.
I try with this topic, an explanation for the fact that libraries do not work with PROTEUS.
Maybe better I go work with mikroC ... |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1634 Location: Perth, Australia
|
|
Posted: Sun Aug 10, 2014 10:33 pm |
|
|
I cannot comment on your specific code however your hardware implementation would not work on real hardware.
Proteus is known to have real world implementation limitations but in your specific case you are missing the pull-up resistor on DO of the card. When an SD powers up it comes up in native mode (not SPI mode) and in native mode the DO is an Open-Drain (open collector output).
Using Mikro C would not solve the hardware fault. _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19496
|
|
Posted: Mon Aug 11, 2014 3:13 am |
|
|
I's suspect that what happens is that the MicroC code ignores the error from the card, and then starts talking to it, and the Isis code doesn't 'know' that the card is in the wrong mode, and handles the line as push-pull, so it then works.
One fault hiding another....
Fairly typical of Proteus/Isis I'm afraid.
"Obviously it's an excellent tool for quick test ... about it, no one can deny. "
I'm afraid I think it costs more time in waste in the electronics development 'world' now, than it saves. The accountants at the company I'm currently contracted to, did a 'cost benefit' analysis of the licenses we had for it, a while ago, and decided there was not point in paying for an upgrade, since while the schematic draft, and PCB drafting were very acceptable, the simulator had led to more wasted cost/time in board development, than simply having earlier prototypes made... |
|
|
electr0dave
Joined: 10 Aug 2014 Posts: 24
|
|
Posted: Mon Aug 11, 2014 7:53 am |
|
|
Hello everyone.
I assembled the circuit on a breadboard.
I'm running the entire circuit with 3.3V.
I still did not put the card into the adapter, but the fat_init () function always return "0".
I put the pull-up resistor (10k) in SD_DO, as you can see in the photograph.
Any suggestions?
image search
One more note ...
with - //#define MMCSD_SPI_HW - resp = 0
with - #define MMCSD_SPI_HW - resp = -1 |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19496
|
|
Posted: Mon Aug 11, 2014 8:09 am |
|
|
Start with, you don't want the 3.3K/2.2K dividers. These are an attempt, to drop the output signals from a 5v PIC to not overdrive the 3.3v SD card. For a 3.3v PIC not wanted, and will ensure the PIC can't properly pull the SD card lines high.
Then you need the pull-up(s). One is absolutely required (10K on DO). Then there should also be a pull-up on CS (otherwise this can float before the PIC wakes up). Preferably you should also pull the DAT1, and DAT2 lines up as well.
The fat_init function will return 0, since the data in line on the PIC floats low, and its not pulled high.
This is really typical of what happens with SD. 90% of the circuits on the web, are faulty, or are 'misapplied'. The place to start is the SD data sheet, and the PIC data sheet. |
|
|
electr0dave
Joined: 10 Aug 2014 Posts: 24
|
|
Posted: Mon Aug 11, 2014 8:42 am |
|
|
Hands to Work ...
I'm running the entire circuit with 3.3V.
* PIC 3.3V - check! (PIC18F46K20)
* Pull-up in SD_DO - check!
* Pull-up in CS - check!
* Pull-up in DAT1 and DAT2 - check!
how to do a screen shot
upload pictures online
Unfortunately, I keep getting "0" of fat_init () function.
image hosting 20mb |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Aug 11, 2014 9:13 am |
|
|
Now you've given us something we can actually work with.
Something we can try to duplicate.
But what's your CCS compiler version ? It's given at the top
of the .LST file. Examples of version numbers:
http://www.ccsinfo.com/devices.php?page=versioninfo |
|
|
electr0dave
Joined: 10 Aug 2014 Posts: 24
|
|
Posted: Mon Aug 11, 2014 9:17 am |
|
|
Hello PCM programmer,
I'm using version 5.025.
Thanks for your help.
I will continue to make some attempts ... |
|
|
Jerry I
Joined: 14 Sep 2003 Posts: 96 Location: Toronto, Ontario, Canada
|
Pullup resistors |
Posted: Mon Aug 11, 2014 1:22 pm |
|
|
I see the picture of your protoboard. I see the black wire on the right hand of picture which is jumpering the 2 ground busses, I am assuming your using red wire for the 3.3v, but I don't see the pull-up resistors that are on the common bus getting 3.3v. It may be off the picture shown. |
|
|
electr0dave
Joined: 10 Aug 2014 Posts: 24
|
|
Posted: Mon Aug 11, 2014 1:33 pm |
|
|
Yes. You're right.
I do this way.
I put the wires in the breadboard extreme.
The red wire is on the left and not shown in photo;).
I can not get any improvement.
Either with the card inserted or not, the answer is always "0". |
|
|
|