View previous topic :: View next topic |
Author |
Message |
Elysion
Joined: 03 Aug 2010 Posts: 26
|
Problem related with "ex_mmcsd.c" |
Posted: Thu Dec 09, 2010 12:53 am |
|
|
I tried to work this example(ex_mmcsd.c).But I couldn't succeed to work.Could you show me an example connection to work this example, correctly?And I also post my connection between PIC and SD card:
I wrote the following codes;
Code: |
#include <18F452.h>
#fuses NOWDT, HS, NOPROTECT
#use delay(clock=20000000)
#use rs232(baud=9600, UART1, errors)
#include <stdlib.h> // for atoi32
//meda library, a compatable media library is required for FAT.
#use fast_io(c)
#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>
#include <input.c>
void main(void)
{
BYTE value, cmd;
int32 address;
printf("\r\n\nex_mmcsd.c\r\n\n");
if (mmcsd_init())
{
printf("Could not init the MMC/SD!!!!");
while(TRUE);
}
do {
do {
printf("\r\nRead or Write: ");
cmd=getc();
cmd=toupper(cmd);
putc(cmd);
} while ( (cmd!='R') && (cmd!='W') );
printf("\n\rLocation: ");
address = gethex();
address = (address<<8)+gethex();
if(cmd=='R')
{
mmcsd_read_byte(address, &value);
printf("\r\nValue: %X\r\n", value);
}
if(cmd=='W') {
printf("\r\nNew value: ");
value = gethex();
printf("\n\r");
mmcsd_write_byte(address, value);
mmcsd_flush_buffer();
}
} while (TRUE);
}
|
Thanks. |
|
|
Elysion
Joined: 03 Aug 2010 Posts: 26
|
|
Posted: Thu Dec 09, 2010 11:16 am |
|
|
Does this example program(ex_mmcsd.c) work only CCSC's development kit? |
|
|
andrewg
Joined: 17 Aug 2005 Posts: 316 Location: Perth, Western Australia
|
|
Posted: Thu Dec 09, 2010 9:36 pm |
|
|
First, you're going to need to buffer SPI-MISO. The SD card will output 3.3V as a logic high, but the PIC requires 0.7VDD (3.5V @ 5V VCC) minimum as a logic high - see the data sheet. I've always used 3.3V PICs. You'll need to add a 5V logic gate with a suitably low input threshold.
Second, the CCS supplied MMCSD and FAT drivers have some issues. I've posted some threads on the library forum that might be relevant:
CCS SD/MMC driver MBR support
CCS FAT driver bugfix! _________________ Andrew |
|
|
Elysion
Joined: 03 Aug 2010 Posts: 26
|
|
Posted: Fri Dec 10, 2010 1:18 am |
|
|
I couldn't see anyone who works with "ex_mmcsd.c" correctly. Everyone says another example or another way. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Dec 10, 2010 1:22 pm |
|
|
Quote: | I couldn't see anyone who works with "ex_mmcsd.c" correctly |
What is your compiler version ?
Are you testing this in hardware or in Proteus ? |
|
|
Elysion
Joined: 03 Aug 2010 Posts: 26
|
|
Posted: Sat Dec 11, 2010 12:27 am |
|
|
My compiler version is 4.108. And I tested this program in Proteus and hardware. But I couldn't get any results from both of them. |
|
|
Elysion
Joined: 03 Aug 2010 Posts: 26
|
|
Posted: Mon Dec 13, 2010 12:54 am |
|
|
Are my circuit and program true for this operation?If it is not,What should I do? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Dec 13, 2010 1:16 am |
|
|
I sent you a PM saying that I am still working on it. You should go to
your forum member 'Profile' page and enable this feature:
Quote: | Pop up window on new Private Message |
Assuming that your browser allows pop-up windows, then you will
see any new PMs. I don't actually want to help you in PMs. I'd rather
do it here. I sent you a status PM to be nice.
Just to say what was in the PM: I tested it with vs. 4.108 on Sunday
afternoon (today) and I could not initially make it work. I will try again
over the next few days. I am using a Microchip MMC/SD "Pictail" board
with a PNY 2GB SD card for testing. This is connected to a PicDem2-Plus
board.
With regard to your circuit, it assumes that you are using software SPI.
That's because you don't have a 3v to 5v level translator chip or circuit
on the Dout pin of the SD card. The hardware SPI module in the PIC
requires 5v CMOS input levels. The 3v CMOS levels coming out of the
SD card will not work.
However, in the mmcsd.c driver file, it has a #use spi() statement and it
doesn't specify FORCE_HW. I've looked at the .LST file and it is in fact
using software SPI. So your circuit should be OK.
I have to look at the problem some more. I don't know what the problem
is yet. |
|
|
|