- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
}
}
}
}
- Labels:
-
PSoC 1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks very much for the fix, I had already given up on the SD-card but now its back in the game.