|
|
View previous topic :: View next topic |
Author |
Message |
Axxel
Joined: 20 Aug 2015 Posts: 5 Location: France
|
Problem with PIC 18F4550 and SDCARD and ex_fat.c modified CC |
Posted: Tue Sep 08, 2015 8:50 pm |
|
|
Hi everybody
I'm trying to get working the ex_fat.c example.
I'm using a PIC 18F4550.
The pic use a external crystal of 20Mhz.
I use a SD Card normal (No SDHC) of 256 Mb capacity.
I use the PIC Compiler 5.008
I program my pic with a PicKit 2 and the PicKit 2 Kit programmer software.
I made a shield with eagle to get correctly the 4 SPI pins MOSI MISO CLK and CS from the SD card.
The shield have a 10K pull up on the MISO/SDO pin (I can quit it with a jumper).
Here is the schematic : (The 2.2K are in reality of 1.8K).
I tested it successfully with Arduino sample and it worked R/W perfectly.
So my hardware is correct.
Now I connected the shield to the following pins of the pic:
B0 : MOSI
B1 : CLK
B2 : MISO
B4 : CS
C6/C7 : To the serial monitor terminal.
Now, when I'm running the program, on the monitor, I can see the message " ERROR INITILIAZING FAT "
After I try to enter the help command, and the terminal doesn't show me nothing. It only repeats me the sent command.
(COM Problem?)
I tried manually the commands in the while(TRUE)
- disp_folder_contents(dir);
- MakeFile(char *fileName)
Unfortunately without any sucess... :(
I will take me the permission to post the modified code it isn't the same as CCS, because I modified it.
If you think the modified code here will cause you problems with CCS, you can delete it.
Mmmmmm so I'm in this case? https://es.wikipedia.org/wiki/Copyleft (Sorry I'm an hardcore Arduino user )
Code: | #include <18F4550.h>
#device PASS_STRINGS = IN_RAM
#fuses HSPLL // Usamremos el PIC con un cristal externo
#fuses NOWDT // Descativamos el watchdog timer
#fuses PROTECT // El codigo esta protegido contra la copia y el hex dump
#fuses NOPUT // No hay tiempo de espera de estabilizacion de alimentacion
#fuses PLL5 // Multiplicador PLL 48Mhz por quartz de 20Mhz
#fuses CPUDIV1 // No System Clock Postscaler
#fuses USBDIV // Reloj de USB viene de la PLL / 2
#fuses VREGEN //USB voltage regulator enabled
#use delay(clock=48M)
#use rs232(baud=9600, UART1, errors)
//#use rs232(baud=9600,parity=N,xmit=PIN_C7,rcv=PIN_C6,bits=8, force_sw)
//#define RS232_DEBUG 1
#include <stdlib.h> // for atoi32
//media library, a compatable media library is required for FAT.
#use fast_io(c)
#define MMCSD_PIN_SCL PIN_B1 //o
#define MMCSD_PIN_SDI PIN_B0 //i
#define MMCSD_PIN_SDO PIN_B4 //o
#define MMCSD_PIN_SELECT PIN_B2 //o
#include <mmcsd.c>
//FAT library.
#include <fat.c>
//////////////////////
/// ///
/// Useful Defines ///
/// ///
//////////////////////
#define COMMAND_SIZE 10
#define NUM_COMMANDS 11
////////////////////////
/// ///
/// Global Variables ///
/// ///
////////////////////////
char g_CWD[200] = "/"; //current working directory
char commands[NUM_COMMANDS][COMMAND_SIZE]=
{
"del", //option1=filename. delete file.
"make", //option1=filename. create an empty file, give error if file already exists
"append", //option1=filename, option2=string. append string to end of file
"cd", //option1=new cwd. change working directory. / is root.
"dir", //show files in directory
"cat", //option1=filename. display full contents in ascii
"tail", //option1=filename. display the last 20 lines of file.
"mkdir", //option1=dir. create directory. see 'cd' for rules on dir
"rmdir", //option1=dir. remove directory. see 'cd' for rules on dir.
"format", // option1=media size in bytes. formats the media.
"help" // help!
};
////////////////////////////////
/// ///
/// Function Implementations ///
/// ///
////////////////////////////////
/*
Summary: Finds a command from the global list of commands.
Param: A pointer to the command string.
Returns: The command number if the command is found in the command list.
0xFF if the command isn't found
*/
int FindCommand(char *cmd)
{
char buf[COMMAND_SIZE];
int i;
for (i=0; i<NUM_COMMANDS; i++)
{
strcpy(buf, &commands[i][0]);
if (stricmp(buf, cmd)==0)
return(i);
}
return(0xFF);
}
/*
Summary: Displays the current working directory.
Param: None.
Returns: None.
*/
void DisplayPrompt(void)
{
printf("\r\n\n%s> ", g_CWD);
}
/*
Summary: Deletes a file.
Param: The full path of the file to delete.
Returns: None.
*/
void DeleteFile(char *fileName)
{
printf("\r\nDeleting '%s': ", fileName);
if(rm_file(fileName) != GOODEC)
{
printf("Error deleting file");
return;
}
printf("OK");
}
/*
Summary: Creates a file.
Param: The full path of the file to create.
Returns: None.
Example Usage: \> make "Log.txt"
*/
void MakeFile(char *fileName)
{
printf("\r\nMaking file '%s': ", fileName);
if(mk_file(fileName) != GOODEC)
{
printf("Error creating file");
return;
}
printf("OK");
}
/*
Summary: Append a string to a file.
Param: The full path of the file to append to.
Param: A pointer to a string to append to the file.
Returns: None.
Example Usage: \> append "Log.txt" "This will be appended to the end of Log.txt"
Note: A "\r\n" will be appended after the appendString.
*/
void AppendFile(char *fileName, char *appendString)
{
FILE stream;
printf("\r\nAppending '%s' to '%s': ", appendString, fileName);
if(fatopen(fileName, "a", &stream) != GOODEC)
{
printf("Error opening file");
return;
}
fatputs(appendString, &stream);
fatputs("\r\n", &stream);
if(fatclose(&stream) != GOODEC)
{
printf("Error closing file");
return;
}
printf("OK");
}
/*
Summary: Change the working directory.
Param: The new working directory to switch to.
Returns: None.
Example Usage: \> cd ftp/ -> /ftp/
\ftp\> cd files/ -> /ftp/files/
\ftp\files> cd.. -> /ftp/
\ftp\> cd .. -> /
\> cd /ftp/files/ -> /ftp/files/
Note: Changing the directory to .. will go up a directory.
*/
void ChangeDirectory(char *newCWD)
{
FILE stream;
//append a / to the end of the filename if it doesn't exist
//making an assumption here that newCWD can hold 1 more character
if (newCWD[strlen(newCWD)-1] != '/')
strcat(newCWD, "/");
if((strstr(newCWD, "../") != 0) && (strcmp(g_CWD, "/") != 0))
{
g_CWD[strlen(g_CWD) - 1] = '\0';
g_CWD[strrchr(g_CWD, '/') - g_CWD + 1] = '\0';
}
else
{
if(fatopen(newCWD, "r", &stream) != GOODEC)
{
printf("\r\nError changing directory");
return;
}
strcpy(g_CWD, newCWD);
}
}
/*
Summary: Display the contents of the working directory.
Param: The full path of the directory contents to display.
Returns: None.
Example Usage: /> dir
*/
void DisplayDirectory(char *dir)
{
disp_folder_contents(dir);
}
/*
Summary: Create a directory.
Param: The full path of the directory to create.
Returns: None.
Example Usage: /> mkdir "Backlog"
*/
void MakeDirectory(char *dir)
{
//append a / to the end of the filename if it doesn't exist
//making an assumption here that newCWD can hold 1 more character
if (dir[strlen(dir)-1] != '/')
strcat(dir, "/");
printf("\r\nMaking directory '%s': ", dir);
if(mk_dir(dir) != GOODEC)
{
printf("Error creating directory");
return;
}
printf("OK");
}
/*
Summary: Remove a directory.
Param: The full path of the directory to remove.
Returns: None.
Example Usage: /> rmdir "Backlog"
Note: The directory needs to be empty in order for this command to work.
*/
void RemoveDirectory(char *dir)
{
printf("\r\nRemoving directory '%s': ", dir);
//append a / to the end of the filename if it doesn't exist
//making an assumption here that newCWD can hold 1 more character
if (dir[strlen(dir)-1] != '/')
strcat(dir, "/");
if(rm_dir(dir) != GOODEC)
{
printf("Error removing directory");
return;
}
printf("OK");
}
#define CAT_FROM_START FALSE
#define CAT_FROM_END TRUE
/*
Summary: Prints either all of or the last 80 characters in a file.
Param: The full path of the file to print off.
Param: If true, this function will print off the last 80 characters in the file.
If false, this funciton will print off the entire file.
Returns: None.
Example Usage: /> cat "Logs.txt" (this will display the entire file)
Example Usage: /> tail "Logs.txt" (this will display the last 80 characters in the file)
*/
void PrintFile(char *fileName, int1 startFromEnd)
{
FILE stream;
if(fatopen(fileName, "r", &stream) != GOODEC)
{
printf("\r\nError opening file");
return;
}
printf("\r\n");
if(startFromEnd)
fatseek(&stream, 80, SEEK_END);
fatprintf(&stream);
fatclose(&stream);
}
/*
Summary: Formats the media to a specified size.
Param: The size of the media, in kB, in string form.
Returns: None.
Example Usage: /> format 524288 (format a 512MB card)
*/
void FormatMedia(char *mediaSize)
{
int32 size;
size = atoi32(mediaSize);
printf("\r\nFormatting media (size=%LU): ", size);
if(format(size) != GOODEC)
{
printf("Error formatting media");
return;
}
printf("OK");
}
/*
Summary: Shows a help prompt.
Param: None.
Returns: None.
Example Usage: /> help
*/
void ShowHelp()
{
printf("\r\nFAT Shell Help");
printf("\r\n del filename --- Deletes the file");
printf("\r\n make filename --- Creates an empty file");
printf("\r\n append filename string --- Appends string to the end of the file");
printf("\r\n cd dir --- Change the working directory");
printf("\r\n dir --- Shows the contents of the directory");
printf("\r\n cat filename --- Displays content of file");
printf("\r\n tail filename --- Displays the last 80 characters of file");
printf("\r\n mkdir dir --- Create a directory");
printf("\r\n rmdir dir --- Deletes the directory");
printf("\r\n format size --- Format card. (Example: 'format 5524288' formats a 512MB card)");
printf("\r\n help\tYou are here");
printf("\r\n\n Put a parameter in quotes if it has spaces");
}
char * GetCMD(char *in)
{
char tokens[]=" \r\n";
return(strtok(in,tokens));
}
char * GetOption(char *in)
{
char tokensSpace[]=" \r\n";
char tokensQuote[]="\"\r\n";
//trim leading spaces
while (*in==' ')
in++;
//if first char is a quote, then end token on a quote. ELSE end token on a space
if (*in == '\"')
return(strtok(in,tokensQuote));
else
return(strtok(in,tokensSpace));
}
void main(void)
{
char buffer[255];
char opt_buffer[255];
char *cmd, *option1, *option2;
int i; // pointer to the buffer
// initialize the FAT
// keep in mind that this will automagically initialize the media
i = fat_init();
if (i)
printf("\r\n\nERROR INITIALIZING FAT\r\n\n");
// main loop
while(TRUE)
{
i = 0;
DisplayPrompt();
do
{
buffer[i] = getch();
// check for a backspace
if(buffer[i] != 8)
{
printf("%c", buffer[i]);
i++;
}
else if(i > 0)
{
// delete the last character
i--;
putc(8);
putc(' ');
putc(8);
}
buffer[i] = '\0';
} while(buffer[i - 1] != '\r');
// parse the command and options
cmd = GetCMD(buffer);
option1 = GetOption(cmd + strlen(cmd) + 1);
option2 = GetOption(option1 + strlen(option1) + 1);
//if option1 starts with a '/', that means the file in the option includes
//the full path to the file. if the file doesn't start with a '/', the
//current working directory must be added.
if (option1 && (option1[0]=='/'))
{
//option1 is a full path
strcpy(opt_buffer, option1);
}
else if (option1)
{
// tack on the current working directory to option1
strcpy(opt_buffer, g_CWD);
strcat(opt_buffer, option1);
}
if (cmd)
{
switch(FindCommand(cmd))
{
case 0: //del
DeleteFile(opt_buffer);
break;
case 1: //make
MakeFile(opt_buffer);
break;
case 2: //append
AppendFile(opt_buffer, option2);
break;
case 3: //change directory
ChangeDirectory(opt_buffer);
break;
case 4: //show directory contents
DisplayDirectory(g_CWD);
break;
case 5: //cat, display file
PrintFile(opt_buffer, CAT_FROM_START);
break;
case 6: //tail, display last 80 charachters
PrintFile(opt_buffer, CAT_FROM_END);
break;
case 7: //mkdir, make a directory
MakeDirectory(opt_buffer);
break;
case 8: //rmdir, make a directory
RemoveDirectory(opt_buffer);
break;
case 9: //format, format the card
FormatMedia(option1);
break;
case 10: //help, display help
ShowHelp();
break;
default:
printf("\r\nUnkown Command '%s'", cmd);
break;
}
}
}
}
|
I don't know what happening here...
My doubts are about :
- The SPI pin used with the PIC?
- The configuration of the PIC (Software fuses, interrupts?)
- Something or a definition to add in the library?
Thanks for your help, best regards.
Axxel. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Tue Sep 08, 2015 11:36 pm |
|
|
How about searching the forum?...
Big problem you have is that the card _does not produce a high enough output voltage to directly drive the SPI input of a 5v PIC_.
An Arduino is not a PIC.....
You need a buffer on the input line between the SD card and the PIC.
Go to this page:
<http://www.brushelectronics.com/index.php?page=projects>
Select the Ethernet reference design for the PIC18F4620.
Look at the third page, which gives the basic circuit needed to connect the SD to a 5v PIC.
Note as well as the input buffers, you also need the pull-up resistors shown. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9246 Location: Greensville,Ontario
|
|
Posted: Wed Sep 09, 2015 5:19 am |
|
|
Classic 5V PIC 3V peripheral !
Another alternative to additional hardware is to simply use a 3V PIC.
Use the 18LF4550......NOT the 18F4550. The 'L' means it will run on 3 volts.
if this is not an option for you, then you MUST do as Mr. T. points out, add logic level shifting buffers to correctly translate the 3Volt '1's to 5V '1's.
Jay |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1635 Location: Perth, Australia
|
|
Posted: Wed Sep 09, 2015 10:00 pm |
|
|
temtronic wrote: | Classic 5V PIC 3V peripheral !
Another alternative to additional hardware is to simply use a 3V PIC.
Use the 18LF4550......NOT the 18F4550. The 'L' means it will run on 3 volts.
if this is not an option for you, then you MUST do as Mr. T. points out, add logic level shifting buffers to correctly translate the 3Volt '1's to 5V '1's.
Jay |
This one is worse than the classic problem because a pull up resistor to +5V has been connected on DO of the SD card. This is pin is open collector (open drain) only during the SPI initialization phase. After initialization t it is a totem pole output that can be damaged by pulling it up to 5 volts even if connected through a series resistor. _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
Axxel
Joined: 20 Aug 2015 Posts: 5 Location: France
|
|
Posted: Thu Sep 10, 2015 2:16 pm |
|
|
Hi there!
Thanks for your answers!
Yes, I think there is an hardware problem so I decided to build a SD CARD module based on the PDF mentioned by Ttelmah, in this case, this schematic exactly:
So I made a board with Eagle, and I built it:
Now I modified the original FAT EXAMPLE form CCS, to only do 2 things:
- Initialize the FAT
- Create a new file called TEST.TXT (Respecting 8.3 fat16 filename)
And follows with the same problem...
Code: | // Write test.txt file on the root of an FAT SD-CARD with PIC 18F4550
#include <18F4550.h>
#device PASS_STRINGS = IN_RAM
#fuses HSPLL // Usamremos el PIC con un cristal externo
#fuses NOWDT // Descativamos el watchdog timer
#fuses PROTECT // El codigo esta protegido contra la copia y el hex dump
#fuses NOPUT // No hay tiempo de espera de estabilizacion de alimentacion
#fuses PLL5 // Multiplicador PLL 48Mhz por quartz de 20Mhz
#fuses CPUDIV1 // No System Clock Postscaler
#fuses USBDIV // Reloj de USB viene de la PLL / 2
#fuses VREGEN //USB voltage regulator enabled
#use delay(clock=48M)
#use rs232(baud=9600, UART1, errors)
//#use rs232(baud=9600,parity=N,xmit=PIN_C7,rcv=PIN_C6,bits=8, force_sw)
//#define RS232_DEBUG 1
#include <stdlib.h> // for atoi32
//media library, a compatable media library is required for FAT.
#use fast_io(c)
#define MMCSD_PIN_SCL PIN_B1 //o
#define MMCSD_PIN_SDI PIN_B0 //i
#define MMCSD_PIN_SDO PIN_B4 //o
#define MMCSD_PIN_SELECT PIN_B2 //o
#include <mmcsd.c>
//FAT library.
#include <fat.c>
void main(void)
{
int i; // pointer to the buffer
// initialize the FAT
// keep in mind that this will automagically initialize the media
i = fat_init();
if (i)
printf("\r\n\nERROR INITIALIZING FAT\r\n\n");
printf("\r\nMaking file '%s': ", "/TEST.TXT");
if(mk_file("/TEST.TXT") != GOODEC)
{
printf("Error creating file");
return;
}
printf("OK");
// main loop
while(TRUE)
{
}
}
|
Case 1 : With SD Card
I obtain in the terminal:
Making file '/TEST.TXT':
And I don't get any answer, the PIC get stucked here...
Case 2 : Without SD Card
I obtain in the terminal:
Making file '/TEST.TXT': OK
This time the PIC doesn't look stucked but of course there isn't any SD Card.
Normally I have to get the error message of initializing error and nothing appears.
Here are pictures of the hardware:
About the hardware, I use an external crystal of 20Mhz.
The PIC training board is a TEKNOMOVO ENT-V4. (The B port have pull ups but I quited all of them.)
This is the connection:
B0 : MOSI/SDI
B1 : CLK/SCK
B2 : SS/CS
B4 : MISO/SDO
I believe it is a hardware problem or a connection problem...
What do you think? |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1635 Location: Perth, Australia
|
|
Posted: Thu Sep 10, 2015 5:52 pm |
|
|
I am impressed with your efforts :-)
I have done a lot of work with PICs and FAT file systems however I have never used the CCS FAT file system drivers so bear that in mind when you look at my comments.
You have not used the hardware SPI port to talk to the SD card. I do not know if the CCS FAT driver supports software SPI (it probably does) but even if it does, it is not a good idea. Why is that? there is a HUGE volume of traffic that must traverse the SPI bus when implementing the FAT file system. If you think about everything the file system must do, it must read the boot sector to find the pointers to the directory and file allocation tables. When you create a file it must search the directory for the next free entry, search the File Allocation Table for the necessary free sectors, create the directory entry, update both copies of the file allocation tables, read in the current content of the 512 byte block from the location on the media where the file is to be located into the files buffer in RAM, write out the file through the RAM buffer, acquiring more sectors if required (may require searching the FAT and updating both copies) with subsequent updating of directory entries. Then when you close the file, it must flush the file buffer to the media and update the directory. SD/MMC cards write in fixed length 512 byte blocks. Updating a FAT entry requires reading in the 512 block containing the sector into RAM, modifying the contents in RAM and then writing back the block. It must repeat this for 2nd copy of the FAT.
The PIC18F4550 is not a good choice for a PIC implementing a FAT file system. Why is that? Not enough RAM to maintain two file buffers (one for the file system and one for the open file (actually one for each open file) and then have enough memory left for the actually application that required a FAT file system in the first place. Similarly the FAT file system consumes a lot of program memory. The PIC18F4550 does not have a lot to start with leaving not a lot to implement the program that required a FAT file system in the first place. If you must stat with the PIC18F family, then a PIC18F4620 or one of the similar variants, is a much better choice with double the RAM and program memory.
I have done a lot of projects using the PIC18F and logging data to SD/MMC media however I would not start a new project today using this family instead my entry platform would be a PIC24 processor with significantly more RAM and program memory enabling multiple concurrent open files and enough RAM and program memory for supporting this class of application.
You did ask :-) _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
Axxel
Joined: 20 Aug 2015 Posts: 5 Location: France
|
|
Posted: Thu Sep 10, 2015 9:25 pm |
|
|
Thanks for your answer.
Now I explain you why I choose the 18F4550.
1 - The price.
2 - The DIP Package (I can't work very well with SMD's).
3 - The posibility to find it easily in a shop.
The aplication I want to do is making a capture of an analog signal and doing a datalogger on a SD-CARD. Each capture will be written on the SD-CARD each 10 seconds and it will be only few characters. So the speed of the SPI bus I think isn't a problem in my case.
I need 16 outputs because I will control other things and the RS232 TX RX bus.
The rest of my code is very light so I won't have any problem if the SD Card and FAT library use a good part of the PIC resources.
That's why I need to get it working on the 18F4550.
Now, regarding at the 18F4550 specs and the harware SPI i found this :
I think the following conexion of the SPI hardware on the 18F4550 is:
RB0 -> MOSI
RB1 -> CLK
RB3 -> CS
RC7 -> MISO
It is correct?
Now looking at the datasheet this will confirm:
Now for the CS pin this is arbitrary? I can put it where I want?
I will try it tomorrow and I give you informations
Last edited by Axxel on Thu Sep 10, 2015 9:33 pm; edited 2 times in total |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1635 Location: Perth, Australia
|
|
Posted: Thu Sep 10, 2015 9:32 pm |
|
|
You have the MISO - MOSI reversed.
RB0 -> MISO
RB1 -> CLK
RB3 -> CS
RC7 -> MOSI
The PIC18F4620 is as readily available as the PIC18F4550 at the same price point. The only reason to choose a PIC18F4550 over a PIC18F4620 is if you need USB support. And even then, the PIC18F4550 is only suitable for simple USB application because you lose half of the limited RAM to the USB peripheral. _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
Axxel
Joined: 20 Aug 2015 Posts: 5 Location: France
|
|
Posted: Thu Sep 10, 2015 9:34 pm |
|
|
The problem is the pin C7 is shared with the RS232 bus :( :( And I need it and I use USB too.
And the B0 B1 are shared with i2c. If I want to use one day an i2c sensor, it will be imposible to use it with the SD CARD? |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1635 Location: Perth, Australia
|
|
Posted: Thu Sep 10, 2015 9:50 pm |
|
|
Axxel wrote: | The problem is the pin C7 is shared with the RS232 bus :( :( And I need it and I use USB too. |
How are you going to use FAT and USB at the same time? The PIC does not have enough RAM.
There is far less work for the PIC to do if you implemented a software UART instead of software SPI.
Quote: |
And the B0 B1 are shared with i2c. If I want to use one day an i2c sensor, it will be imposible to use it with the SD CARD? |
I think most PIC18F PICs have the SPI and I2C peripherals sharing the same pin. In general, for a simple application, you would either the SPI or I2C. Where you need both then you really need a PIC with dual SPI/I2C peripherals. _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9246 Location: Greensville,Ontario
|
|
Posted: Fri Sep 11, 2015 5:05 am |
|
|
I too had a few 4550s when they came out as onboard USB sounded good..well too good....at the time it was, well, 'ok', but the USB took up a LOT of program memory(driver) and RAM. Then there's the connection....
A bit later I bought one of those USBTTL modules for $5, it worked fine(still does). Now they're down to $2 each. Having the USB 'off chip' is actually cheaper for me. It frees up a LOT of memory, has the connector(properly wired!), even has a couple LEDs as well.
Consider it an 'option' especially if you value your time ! You can buy a LOT of USBTTL modules for 1 hours R&D $$ !!
Jay |
|
|
Axxel
Joined: 20 Aug 2015 Posts: 5 Location: France
|
|
Posted: Fri Sep 11, 2015 12:46 pm |
|
|
Hi there!
I bought a 18F4620, checked the pinout and match with my experiment board!
Next, I connected EXACTLY the SD Card board to the 18F4620 as this schematic :
I use exactly the same hardware.
And it follows with ERROR INITIALIZE SD.
Here is the code:
Code: | // Write test.txt file on the root of an FAT SD-CARD with PIC 18F4550
#include <18F4620.h>
#device PASS_STRINGS = IN_RAM
#fuses HS // Usamremos el PIC con un cristal externo
#fuses NOWDT // Descativamos el watchdog timer
#fuses PROTECT // El codigo esta protegido contra la copia y el hex dump
#fuses NOPUT // No hay tiempo de espera de estabilizacion de alimentacion
#use delay(clock=20M)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,bits=8,stream=PORT1)
#include <stdlib.h> // for atoi32
//media 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_C0 //o
#include <mmcsd.c>
//FAT library.
#include <fat.c>
void main(void)
{
int i; // pointer to the buffer
// initialize the FAT
// keep in mind that this will automagically initialize the media
i = fat_init();
if (i)
printf("\r\n\nERROR INITIALIZING FAT\r\n\n");
printf("\r\nMaking file '%s': ", "/TEST.TXT");
if(mk_file("/TEST.TXT") != GOODEC)
{
printf("Error creating file");
return;
}
printf("OK");
// main loop
while(TRUE)
{
}
} |
The SDI pins configuration is correct?
I working with a 20Mhz quartz.
Fuses, PLL? |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1635 Location: Perth, Australia
|
|
Posted: Sat Sep 12, 2015 2:50 am |
|
|
Axxel wrote: | Hi there!
I bought a 18F4620, checked the pinout and match with my experiment board!
Next, I connected EXACTLY the SD Card board to the 18F4620 as this schematic :
I use exactly the same hardware.
And it follows with ERROR INITIALIZE SD.
Here is the code:
Code: | // Write test.txt file on the root of an FAT SD-CARD with PIC 18F4550
#include <18F4620.h>
#device PASS_STRINGS = IN_RAM
#fuses HS // Usamremos el PIC con un cristal externo
#fuses NOWDT // Descativamos el watchdog timer
#fuses PROTECT // El codigo esta protegido contra la copia y el hex dump
#fuses NOPUT // No hay tiempo de espera de estabilizacion de alimentacion
#use delay(clock=20M)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,bits=8,stream=PORT1)
#include <stdlib.h> // for atoi32
//media 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_C0 //o
#include <mmcsd.c>
//FAT library.
#include <fat.c>
void main(void)
{
int i; // pointer to the buffer
// initialize the FAT
// keep in mind that this will automagically initialize the media
i = fat_init();
if (i)
printf("\r\n\nERROR INITIALIZING FAT\r\n\n");
printf("\r\nMaking file '%s': ", "/TEST.TXT");
if(mk_file("/TEST.TXT") != GOODEC)
{
printf("Error creating file");
return;
}
printf("OK");
// main loop
while(TRUE)
{
}
} |
The SDI pins configuration is correct?
I working with a 20Mhz quartz.
Fuses, PLL? |
The fuses look fine. You do not need the PLL and you cannot use the PLL with a 20MHz crystal anyway.
As mentioned earlier, I cannot comment on the CCS driver.
You have used fast_IO (which is what I always do for SD Logger applications) however fast-IO says .. "don't let the compiler set the I/O direction automatically, let me set it."
Perhaps the CCS driver sets it for you (I do not know) but if it does not then your chip select line will be an input.
Is this the same card you were using when you have the DO pulled up to five volts? If so, have you checked to see if the card still works? _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
|
|
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
|