cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 5, 3 & 1 MCU

Anonymous
Not applicable
        I have problems with the example "Hello Word" wich comes with the example projects. I have an ICE so I can debug the project.   
   
If I build the original code, the SD card loos its format. So I create a new one from the beginning, but this new cant write (create) the archive. Appears that the fp = SDCard_fopen(helloFile, "a") and the SDCard_fputcs("HelloWorld", fp) are not working.   
   
My C code is the next   
   
//----------------------------------------------------------------------------   
// C main line   
//----------------------------------------------------------------------------   
   
//----------------------------------------------------------------------------   
// Hello World Sample Project   
//   
// Description:   
// This is a simple example of what it take to write a string to a SD Card File.   
//   
// Program Flow:   
// 1) Wait for card to be inserted.   
// 2) Initializes card interface.   
// 3) Opens file "hello.txt" for writing. If not there it creates the file.   
// 4) Writes the string "Hello World" with a CR and LF.   
// 5) Closes the file. Then goes back to step '1' and waits for card to   
// be inserted.   
   
#include <m8c.h> // part specific constants and macros   
#include "PSoCAPI.h" // PSoC API definitions for all User Modules   
   
#define CARD_PRESENT 1   
#define CARD_NOT_PRESENT 0   
   
char helloFile[] = "hello.txt";   
   
void main()   
{   
char cardInfo; // Card information   
char fp; // File Pointer   
BYTE CardState, oldCardState; // Card inserted state variables   
   
BusyLED_Off(); // Make sure LED is Off   
oldCardState = CARD_NOT_PRESENT; // Initialize card insertion state   
SDCard_Start( ); // initalize hardware and SDCard_lib buffers   
   
while(1)   
{   
CardState = SDCard_Present(); // Get current card insertion state   
if(CardState != oldCardState) // Check for a change   
{   
oldCardState = CardState; // Save last state   
if(CardState == CARD_PRESENT) // Card inserted   
{   
BusyLED_On(); // About to talk to card, turn on busy LED   
SDCard_Select(SDCard_ENABLE); // Select card   
cardInfo = 0;   
while ( ! cardInfo ) // Wait for card to communicate   
{   
// initialize card, determine card type and file system type   
cardInfo = SDCard_InitCard();   
}   
   
fp = SDCard_fopen(helloFile, "a"); // Open file to append data   
SDCard_fputcs("HelloWorld", fp); // Write string   
SDCard_fclose(fp); // Close file   
SDCard_Select(SDCard_DISABLE); // Deselect card   
BusyLED_Off(); // Turn off busy LED   
}   
}   
}   
}   
0 Likes
Reply
4 Replies
Anonymous
Not applicable

I fix the problem, was whit the SD card, I formatted whit

http://www.sdcard.org/consumers/formatter/sdfv2000.exe

and the problem was solved. Don't use windows format program. The SD need to be recognized as a Hard Disk, so it need to have a Master Boot Record (MBR). If you read the archive SDCard_fs.c on the SDCard_InitCard function this fact is call. So if you dont have a MBR on your SD the SDCard_InitCard function return a cero value, so the SD will never be initialized.

0 Likes
Reply
Anonymous
Not applicable
0 Likes
Reply
Anonymous
Not applicable

 hello, i'm working with psoc1 and now i didnt found the project with the sd card that was online ones. could you send me back this tutorial with the example project please

   

thanks

0 Likes
Reply
Anonymous
Not applicable

Thanks very much for the fix, I had already given up on the SD-card but now its back in the game.

0 Likes
Reply