Atmel website | ARM Community | AVR freaks | Technical Support
Banner
 FAQ •  Search •  Register •  Login 

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Communicate with SD card via Fatfs AT91Sam9
PostPosted: Tue Sep 20, 2011 12:12 pm 
Offline

Joined: Tue Sep 20, 2011 11:34 am
Posts: 2
Hi all,
I've read the Hand-on Material for AT91SAM9RL64. It works well, means that I can read bitmap image in SDcard and display its on the LCD screen.
Now, I need to get familiar with SDcard communication.
I used code C:

====================================================================================

#include <board.h>
#include <board_memories.h>
#include <pio/pio.h>
#include <dbgu/dbgu.h>
#include <utility/assert.h>
#include <memories/MEDSdcard.h>
#include <fatfs/src/ff.h>
#include <fatfs/src/diskio.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

Media medias[1];


void main()
{
//FILINFO fileinfo;
// DIR dir;
//FIL file;


FATFS fs; // Work area (file system object) for logical drive
FIL fsrc, fdst; // file objects
BYTE buffer[4096]; // file copy buffer
FRESULT res; // FatFs function common result code
UINT br, bw; // File R/W count

// Initialize filesystem
MEDSdcard_Initialize(&medias[DRV_MMC]);
disk_initialize(DRV_MMC);
memset(&fs, 0, sizeof(fs));

ASSERT(!f_mount(DRV_MMC, &fs), "-F- Could not mount filesystem on SDCard\n\r");




// Register a work area for logical drive 0
// f_mount(0, &fs);

// Open source file
res = f_open(&fsrc, "ccc.txt", FA_OPEN_EXISTING | FA_READ);
//if (res) die(res);

// Create destination file
res = f_open(&fdst, "aaa.txt", FA_CREATE_ALWAYS | FA_WRITE);
//if (res) die(res);

// Copy source to destination
for (;;) {
res = f_read(&fsrc, buffer, sizeof(buffer), &br);
//if (res || br == 0) break; // error or eof
res = f_write(&fdst, buffer, br, &bw);
if (res || bw < br) break; // error or disk full
}
f_mkdir("sub1");
// Close all files
f_close(&fsrc);
f_close(&fdst);

// Unregister a work area before discard it
f_mount(DRV_MMC, NULL);
}
================================================================================
This code C have no errors while I Debug and Run in IAR, but unfortunately,
it's not work, means that there are no more new "(sub1) folder" when I check my SD card or the new "aaa.txt" file.

Thanks for help...
(references code from elm-chan).


Top
 Profile  
 
 Post subject: Re: Communicate with SD card via Fatfs AT91Sam9
PostPosted: Thu Sep 22, 2011 8:17 am 
Offline

Joined: Wed May 17, 2006 10:13 am
Posts: 5
As far as i can see so the source seems to be fine if all response are oke… Possibly you have a stack problem. The complete buffer 4096 byte’s and all the file system structures are local data that’s stored on the stack. Properly you have to increase your stack size or make that variables global.


Top
 Profile  
 
 Post subject: Re: Communicate with SD card via Fatfs AT91Sam9
PostPosted: Sat Sep 24, 2011 11:41 am 
Offline

Joined: Tue Sep 20, 2011 11:34 am
Posts: 2
I've asked Atmel technitian about my problem and received the answer:

"Hi,

It is because your code from elm-chan is not functional, please refer to our sample code from http://www.atmel.com/dyn/resources/prod ... 9rl-ek.zip.

Best Regards,
Allen Ke
Atmel Technical Support Team."

My purpose is to get data from image and convert it into matrix to process, aim to a higher image resolution using interpolation method. I also use "stdio.h" library in C, two function "fopen" and "fscanf". But it not work in AT91Sam9RL kit.
Example: I use geting-start-project to stimulate, change wait time by this code:
int tre(void) // this fuction work well in Turbo C
{
int i, j;
int arr [MAX][MAX];
FILE *fin, *fout;
fin=fopen("C:\\Documents and Settings\\NHC\\Desktop\\Workplace\\test.txt","r");
// there only an 4x4 matrix in file test.txt which arr[1][1]=2 just for testing
for(i=0;i<4;i++)
{

for(j=0;j<4;j++)
{
fscanf(fin,"%d \n",&arr[i][j]);
}
}
fclose(fin);

return arr[1][1]; // I use arr[1][1]=2 for a in main()
}

//------------------------------------------------------------------------------
// Exported functions
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
/// Application entry point. Configures the DBGU, PIT, TC0, LEDs and buttons
/// and makes LED\#1 blink in its infinite loop, using the Wait function.
/// \return Unused (ANSI-C compatibility).
//------------------------------------------------------------------------------
int main(void)
{
int a;
// DBGU configuration
TRACE_CONFIGURE(DBGU_STANDARD, 115200, BOARD_MCK);
printf("-- Getting Started Project %s --\n\r", SOFTPACK_VERSION);
printf("-- %s\n\r", BOARD_NAME);
printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__);

// Configuration
ConfigurePit();
ConfigureTc();
ConfigureButtons();
ConfigureLeds();
a= tre();
a=a*1000;
// Main loop
while (1) {

// Wait for LED to be active
while (!pLedStates[0]);

// Toggle LED state if active
if (pLedStates[0]) {

LED_Toggle(0);
printf("1 ");
}

// Wait for 500ms
Wait(a);
}
}
///////////////////////////////////////////////
It is have no errors, but not work on AT91SAM9RL kit,,,,?? I'm so confuse...


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 5 guests


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 post attachments in this forum

Search for:
Jump to: