|
|
View previous topic :: View next topic |
Author |
Message |
Andreino
Joined: 06 Dec 2011 Posts: 5
|
mmcsd fat.c |
Posted: Tue Dec 06, 2011 8:08 am |
|
|
Hello boys, I'm new to the forum.
I can not get the pic to read the files residing in SD (San Disk 2GB) and use the library mmcsd fat.c fatopen in particular, but can neither read nor nn to create files to format it. my version of ccs and '4,121 and 18f4620 microcontroller and 8527. please help me. English is not 'my mother tongue sorry imperfections |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Tue Dec 06, 2011 10:34 am |
|
|
The obvious question is "how are you doing the voltage translation between the PIC and the SD card"?. The 18F4620, runs at 4.2v _minimum_ the SD card runs at 3.3v.
Best Wishes |
|
|
Andreino
Joined: 06 Dec 2011 Posts: 5
|
|
Posted: Tue Dec 06, 2011 11:25 am |
|
|
Ttelmah Thanks for the reply.
I know it use resistors 2k2 ohm but 'the problem is to read the files using the sd fat.c but without results. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Tue Dec 06, 2011 3:52 pm |
|
|
No.
You have two separate translations needed:
From the high voltage lines on the PIC to the SD card - for these resistors can be used, but _will_ give problems with faster cards. For faster SPI rates translators are needed here.
From the low voltage SD card lines up to the voltage needed by the PIC input. Hardware SPI on the PIC, _requires_ the signals to go up to 4v (on a PIC running at 5v). A 3.3v SD card _cannot_ do this without hardware level translators.
It is sometimes possible to perform software SPI without translators, depending on the input gates involved on the PIC inputs you have chosen.
You almost certainly need level translator chips between the PIC and the SD card....
Best Wishes |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9225 Location: Greensville,Ontario
|
|
Posted: Tue Dec 06, 2011 4:10 pm |
|
|
The only other alternative is to use a PIC designed for 3.3V use,say 18Lf4620, if one exists.
That way NO interface chips are required as both PIC and SD card are 3.3 volts. |
|
|
Andreino
Joined: 06 Dec 2011 Posts: 5
|
|
Posted: Wed Dec 07, 2011 4:24 am |
|
|
I use the chip to "convert the signals" is the 74lvc1t45. I attach the code so you can see where the mistake. Thanks so much.
Code: |
#include <Display_touch_v1.h>
#include <stdlib.h> // for atoi32
#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_C0 //o
#include <mmcsd.c>
#include <fat.c>
#include "t6963c.c"
void main()
{
int i;
char b[130];
char pc[130];
char file_name[20];
char buffer[255];
FILE stream;
#use spi(MASTER, DI=MMCSD_PIN_SDI, DO=MMCSD_PIN_SDO, CLK=MMCSD_PIN_SCL, BITS=8, MSB_FIRST, MODE=0, stream=mmcsd_spi)
glcd_init(); //inizializza il display touch
fat_init();
while(TRUE){
glcd_rect(0,0,239,127,0,1);
sprintf(b,"Software per la lettura e scrittura");
glcd_text57(10,4,b,1,1);
sprintf(b,"Di schede SD/MMC");
glcd_text57(65,20,b,1,1);
glcd_line(5,35,230,35,1);
strcpy(file_name,"/img_1.jpg");
delay_ms(1000);
sprintf(b,"INIT: ");
glcd_text57(5,45,b,1,1);
i = fat_init();
if (i) {
sprintf(pc,"ERROR INIT FAT");
glcd_text57(150,45,pc,1,1);
}else
sprintf(pc,"INIT OK");
glcd_text57(155,45,pc,1,1);
delay_ms(1000);
sprintf(pc,"CREAZIONE %s:", file_name);
glcd_text57(5,60,pc,1,1);
if(mk_file(file_name) != GOODEC){ //??????????????
sprintf(pc,"ERRORE CREAT");
glcd_text57(155,60,pc,1,1);
}else
sprintf(pc,"FILE CREATO");
glcd_text57(155,60,pc,1,1);
delay_ms(1000);
sprintf(pc,"APRO FILE %s:"file_name);
glcd_text57(5,78,pc,1,1);
if(fatopen(file_name, Read, &stream) != GOODEC){
sprintf(pc,"ERRORE OPEN");
glcd_text57(155,78,pc,1,1);
}else
sprintf(pc,"FILE APERTO!");
glcd_text57(155,78,pc,1,1);
}
}
|
.h
Code: |
#include <18F8527.h>
#device adc=16
#device PASS_STRINGS = IN_RAM
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES BBSIZ1K //1K words Boot Block size
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=PORT1) |
|
|
|
andrewg
Joined: 17 Aug 2005 Posts: 316 Location: Perth, Western Australia
|
|
Posted: Thu Dec 08, 2011 9:35 pm |
|
|
MMC/SD cards use SPI mode 3, not 0. _________________ Andrew |
|
|
Andreino
Joined: 06 Dec 2011 Posts: 5
|
|
Posted: Fri Dec 09, 2011 3:39 am |
|
|
grazie andrew per la risposta, ho impostato la SPI modalita 3 come ha detto lei ma non funziona. cosa devo fare per farla funzionare?
#use spi(MASTER, DI=MMCSD_PIN_SDI, DO=MMCSD_PIN_SDO, CLK=MMCSD_PIN_SCL, BITS=8, MSB_FIRST, MODE=3, stream=mmcsd_spi) |
|
|
andrewg
Joined: 17 Aug 2005 Posts: 316 Location: Perth, Western Australia
|
|
Posted: Sat Dec 10, 2011 1:47 am |
|
|
Quote: | thanks andrew for the answer, I have set up the SPI modality 3 as it has said but she does not work. what I must make in order to make to work it? |
I can't see anything obviously wrong.
The way I would proceed would be to add some LED outputs to fat.c and mmcsd.c to determine what problem they are detecting. In your case, mk_file returns EOF under several different circumstances. I would light an LED for each one in turn to see which is the problem.
You may need to continue this process into functions that are called by mk_file until you get to the underlying problem.
You could also try formatting the card in a variety of different devices - your PC, a camera, a MP3 player, recorder. Different devices may format in slightly different ways, one of which might work.
HTH.
Edit: PS, you're calling fat_init twice. Once at the beginning should be enough. _________________ Andrew |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Sat Dec 10, 2011 3:45 am |
|
|
There is one obvious possible major problem.
You do realise that SDO on the PIC, needs to go to SDI on the MMC card, and SDI to SDO?.
The definitions you show here make it look like you are connecting SDO to SDO and SDI to SDI......
#use spi(MASTER, DI=MMCSD_PIN_SDI, DO=MMCSD_PIN_SDO, CLK=MMCSD_PIN_SCL, BITS=8, MSB_FIRST, MODE=3, stream=mmcsd_spi)
Best Wishes |
|
|
|
|
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
|