|
|
View previous topic :: View next topic |
Author |
Message |
opvini
Joined: 27 Apr 2012 Posts: 50 Location: Brazil
|
SD card with FAT32 and FAT16 problem. |
Posted: Thu Sep 27, 2012 9:26 am |
|
|
Hi everyone.
I am trying to use one SD card with the libraries mmcsd.c and fat.c with the bug fixed, but I had problems. Well, when I use #define FAT32 the fat_init() returns 1 (not initialized), but when I use #define FAT16, returns 0 (initialized) but returns it even without card. I am using one developer kit (http://www.smartradio.com.br/loja-pic/?id=39), then I supposed that the hardware is OK. When I use #define FAT16 I got errors "Undefined Identified Root_Entries" one line 2593 on fat.c: "ec += mmcsd_read_data(17, 2, &Root_Entries);" , I don't understand.
I use the CCS 4.120
My code is very simple:
Code: |
#include <18F4550.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, UART1, errors)
#include "GLCD.c"
#include <string.h>
#include <stdlib.h>
#define MMCSD_PIN_SCL PIN_B1 //o clock
#define MMCSD_PIN_SDI PIN_C7 //i data input
#define MMCSD_PIN_SDO PIN_B0 //o data output
#define MMCSD_PIN_SELECT PIN_B2 //o CS
char msg[20]="Iniciando", dir[]="/";
#include <mmcsd.c>
#include "fat.c"
void main(void)
{
char dir[] = "/";
glcd_init(1);
if( fat_init() != GOODEC ) {
strcpy(msg, "Erro iniciar fat");
glcd_text57(10,10,msg,1,1);
}
else{
strcpy(msg, "Fat iniciado");
glcd_text57(10,10,msg,1,1);
delay_ms(1000);
disp_folder_contents(dir);
}
while(1){ }//while
}
|
and dis_folder_contents just show the contents on folder on My GLCD:
Code: | signed int disp_folder_contents(char foldername[])
{
char filename[MAX_FILE_NAME_LENGTH]; // a place to hold a file name
FILE stream; // the stream that we're going to be working with
char mode[] = "r";
if(fatopen(foldername, mode, &stream) != GOODEC)
return EOF;
// printf off a header
glcd_fillScreen(0);
sprintf(msg, "--%s--", foldername);
glcd_text57(10,10,msg,1,1);
delay_ms(2000);
printf("\r\n--%s--", foldername);
// start off at the root directory
stream.Entry_Addr = stream.Start_Addr;
while(get_next_file(&stream) != EOF)
{
// get the name of the file that we are at
if(get_file_name(stream.Entry_Addr, filename) != GOODEC)
return EOF;
// make cool little "tree" branches
glcd_fillScreen(0);
sprintf(msg, "%s", filename);
glcd_text57(10,10,msg,1,1);
delay_ms(2000);
printf("\r\n%s", filename);
if (stream.File_Type == Directory)
putc('/');
}
fatclose(&stream);
return GOODEC;
} |
Using FAT16 my GLCD shows "--/--" and on SD card I have one txt file: test.txt
Thank you a lot for attention and sorry my bad english, I am from Brazil. |
|
|
opvini
Joined: 27 Apr 2012 Posts: 50 Location: Brazil
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Thu Sep 27, 2012 10:59 am |
|
|
Problem is that on the 4550, the SPI, uses a pin that is shared with the UART. You have pin C7 setup as SDO, but it is also RX on the UART, which you have already selected in #use RS232....
Best Wishes |
|
|
opvini
Joined: 27 Apr 2012 Posts: 50 Location: Brazil
|
|
Posted: Fri Sep 28, 2012 6:14 am |
|
|
Thanks Ttelmah, you are correct!
I removed the line "#use rs232()" and comented lines with printf() and putc() on the library, but the problem keeps happening:
- with FAT16 the fat_init() returns OK even without the card
- with FAT32 the fat_init() returns FALSE
I formated the SD Card with windows XP, and on computer I can use tha card normally.
I tryed to use just mmcsd.c library to read the card with this simple code:
Code: |
#include <18f4550.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#include "GLCD.c"
#include <string.h>
#include <stdlib.h>
#use fast_io(c)
#use fast_io(b)
#define MMCSD_PIN_SCL PIN_B1 //o clock
#define MMCSD_PIN_SDI PIN_C7 //i data input
#define MMCSD_PIN_SDO PIN_B0 //o data output
#define MMCSD_PIN_SELECT PIN_B2 //o CS
#include <mmcsd.c>
void main(void)
{
char msg[50] = "iniciando cartao...";
char dado[32] = "salvo";
int i;
glcd_init(1);
if (mmcsd_init()) // returns OK
{
strcpy(msg,"falha ao iniciar");
glcd_text57(10,10,msg,1,1);
}
else{
glcd_fillScreen(0);
for(i=0; i<= 1024; i++){
glcd_fillScreen(0);
if( !mmcsd_read_data(i*32,32,&dado) ){ // returns OK
sprintf(msg,"Leu %d: %s", i, dado);
glcd_text57(10,10,msg,1,1);
}
mmcsd_flush_buffer();
delay_ms(1000);
}
}
while(1) {}
}
|
but the data that I read on the my grafic display is not the data on the card...
I really cant understand. I sent an email to the maker of the developer kit board asking if the pineout is correct, but I still dont receive the response, but on the eletric scheme manual, its correct...
thanks a lot!!! |
|
|
opvini
Joined: 27 Apr 2012 Posts: 50 Location: Brazil
|
|
Posted: Fri Sep 28, 2012 7:48 am |
|
|
I saw on the datasheet of the PIC 18F4550 that SDO is C7 and SDI is B0, but on the developer kit board manual, its using SDO on B0 and SDI at C7...
I rewrite the code to:
Code: |
#define MMCSD_PIN_SCL PIN_B1 //o clock
#define MMCSD_PIN_SDI PIN_B0 //i data input
#define MMCSD_PIN_SDO PIN_C7 //o data output
#define MMCSD_PIN_SELECT PIN_B2 //o CS
|
Now the dat_init(0 with FAT32 returns OK but don't read the files contents on root folder... |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Fri Sep 28, 2012 9:17 am |
|
|
Using the 'non hardware' pins, forces software SPI to be used.
Given that the board does not have level translation between the SD card and the PIC - relying on simple resistive dividers for the 'down' translation, and requiring a TTL input in the other direction, this is necessary - the hardware SPI has Schmitt input buffers.
Resistive converting like this only works at low data rates, and can be unreliable with many cards.
Bad design.
How big is the card?.
Are you sure it is SD, _not_ SDHC. Only the former will work.
Best Wishes |
|
|
opvini
Joined: 27 Apr 2012 Posts: 50 Location: Brazil
|
|
Posted: Mon Oct 01, 2012 8:37 am |
|
|
The card is small but I am using an adapter to a big SD. Then I think its tha micro SD, sandisk 2GB.
I tryed to use just mmcsd.c library to read data from the SD Card but I dont have success:
Code: |
#include <18f4550.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#include "GLCD.c"
#include <string.h>
#include <stdlib.h>
#use fast_io(c)
#use fast_io(b)
#define MMCSD_PIN_SCL PIN_B1 //o clock
#define MMCSD_PIN_SDI PIN_D7 //i data input
#define MMCSD_PIN_SDO PIN_B0 //o data output
#define MMCSD_PIN_SELECT PIN_B2 //o CS
char msg[50] = "iniciando cartao...";
#include <mmcsd.c>
void main(void)
{
char dado[32] = "salvo";
int i;
glcd_init(1);
glcd_text57(10,10,msg,1,1);
if (mmcsd_init())
{
glcd_fillScreen(0);
strcpy(msg,"falha ao iniciar");
glcd_text57(10,10,msg,1,1);
}
else{
glcd_fillScreen(0);
/*
strcpy(msg,"Escrevendo...");
glcd_text57(10,20,msg,1,1);
mmcsd_write_data(128, 32, dado);
*/
for(i=0; i<= 1024; i++){
glcd_fillScreen(0);
if( !mmcsd_read_data(i*32,32,&dado) ){
sprintf(msg,"Leu %d: %s", i, dado);
glcd_text57(10,10,msg,1,1);
}
else{
sprintf(msg,"Erro ao ler %d.", i);
glcd_text57(10,10,msg,1,1);
}
mmcsd_flush_buffer();
delay_ms(1000);
}
}
while(1) {}
}
|
The function mmcsd_init() returns true even without the card on slot and the mmcsd_read_data(i*32,32,&dado) saves on "dado" datas that I think it is from the PIC memory, becouse is the same with the card or without the card.
[/code] |
|
|
opvini
Joined: 27 Apr 2012 Posts: 50 Location: Brazil
|
|
Posted: Mon Oct 01, 2012 8:55 am |
|
|
I created a more simple sorce to test, and dont have success too:
Code: |
#include <18f4550.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#include "GLCD.c"
#include <string.h>
#include <stdlib.h>
#use fast_io(c)
#use fast_io(b)
#define MMCSD_PIN_SCL PIN_B1 //o clock
#define MMCSD_PIN_SDI PIN_D7 //i data input
#define MMCSD_PIN_SDO PIN_B0 //o data output
#define MMCSD_PIN_SELECT PIN_B2 //o CS
#include <mmcsd.c>
void main(void)
{
char c;
long int i;
glcd_init(1);
glcd_text57(10,10,msg,1,1);
if (mmcsd_init())
{
for(i=0; i<= 1024; i++){
mmcsd_read_byte(i,&c);
sprintf(msg,"Leu %ld: %c", i, c);
glcd_fillScreen(0);
glcd_text57(10,10,msg,1,1);
delay_ms(1000);
}
while(1) {}
}
|
|
|
|
opvini
Joined: 27 Apr 2012 Posts: 50 Location: Brazil
|
|
Posted: Mon Oct 01, 2012 8:57 am |
|
|
I edited the source code here and forgot the
|
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Mon Oct 01, 2012 3:44 pm |
|
|
Why don't you use the CCS supplied example programs instead of creating your own test program? For example ex_mmcsd.c is a very simple test program and when you look at that program it is immediately clear why your simple program fails.
On success mmcsd_init will return a zero. You have the test reversed.
In your earlier program the test is correct.
Quote: | The card is small but I am using an adapter to a big SD. Then I think its tha micro SD, sandisk 2GB. | This is really important, so you shouldn't 'think' but you should be 'sure'.
For Sandisk cards this should be not too difficult. Does it say SDHC like this picture or SD like this one?
The CCS driver only supports SD cards and _not_ SDHC. |
|
|
opvini
Joined: 27 Apr 2012 Posts: 50 Location: Brazil
|
|
Posted: Wed Oct 03, 2012 7:05 am |
|
|
Thanks a lot ckielstra.
My card is a SD card, now I am sure.
Well, I dont have a serial-USB cable, then I am trying to debug the example from the CCS on MPLAB, but I am having the follow error: "PK2 error 0028".
I never use the debugger and the terminal simulator...
I will continue testing...
Thanks a lot again!! |
|
|
opvini
Joined: 27 Apr 2012 Posts: 50 Location: Brazil
|
|
Posted: Wed Oct 03, 2012 7:07 am |
|
|
On my MPLAB, on Select Device, the ICE/ICD Headers is off (no headers)... Can you help to debug my program? |
|
|
lucasromeiro
Joined: 27 Mar 2010 Posts: 167
|
|
Posted: Tue Jan 29, 2013 4:52 pm |
|
|
opvini wrote: | On my MPLAB, on Select Device, the ICE/ICD Headers is off (no headers)... Can you help to debug my program? |
Olá amigo brasileiro!!
Conseguiu fazer seu projeto?
Estou precisando fazer um projeto que manipula arquivos usando fat 32 ou 16 num cartao sd, usando um pic 18f4550.
pode me dar essa forca?
Abraco
Translation:
Quote: |
Hello Brazilian friend!
Going to do your project?
I am needing to do a project that manipulates files using fat 32 or 16 in a sd card, using a pic 18F4550.
Can give me some help ?
Abraco |
|
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
|
lucasromeiro
Joined: 27 Mar 2010 Posts: 167
|
|
Posted: Wed Jan 30, 2013 8:38 am |
|
|
I'm wanting some help from a Brazilian who already tried to do something, I see no problem with asking for help here.
thank you |
|
|
|
|
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
|