/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / SD Card Read/Write without circle OS

Username:     
Password:     
             

Forum

# 1   2009-06-01 10:43:50 SD Card Read/Write without circle OS

rob1
New member
Registered: 2009-05-18
Posts: 3

SD Card Read/Write without circle OS

Hi there,
so first i better say that i´m very new to programming with C. so don´t expect too much wink

So the problem i have is, that i want to read and write data that i get from my sensors to an sd card. I use the Stm32 Primer 2 but witout Circle OS.  For that reason i included the sdcard class und header file from circle OS to my project. That far so well. Now i want to use the read and write methods from that class but don´t understand how that works.
I use an 16gb micro sd formated fat32 with 512 Byte blocksize.
Is it advisible to use fat 32? Also could read/write raw?! Maybe i don´t need any file system... one big file is enough wink

First i call up the init:
  SD_Init();

Then i try to write an block like that:
    char test[6];
    test[0]='h';
    test[1]='e';
    test[2]='l';
    test[3]='l';
    test[4]='o';
    test[5]=0;
    u16  blocksiz=512;
    u32 addr=(u32)&test;
    u32 startadr = ((u32)0x00000000);
    SD_WriteBlock(startadr, &addr, blocksiz);


After that i want to read the same data with that:

  u32 start=((u32)0x00000000);
    char antwort[4096];
    u32 buf=(u32)&antwort;
    SD_ReadBlock(start, &buf,blocksiz);
    antwort[6]=0;
    printf_screen(antwort);
       
        delayMS( 100 );

I get 6 chars on the screen but some signs i don´t understand. I get the same chars when i start reading at any other adress... So something i do very wrong wink

If anyone can help me, i would be very grateful.

Offline

 

# 2   2009-06-01 11:00:00 SD Card Read/Write without circle OS

repzak
Member
Registered: 2008-03-05
Posts: 170

Re: SD Card Read/Write without circle OS

Hello,

First think i se is you write the adress of addr to the file, not the content of addr..., you must remove the & in write block...

SD_WriteBlock(startadr, addr, blocksiz);

or i think

SD_WriteBlock(startadr, test, blocksiz);

It will proberly give a type warning..


For the read:
u32 start=((u32)0x00000000);
    char antwort[4096];
 
    SD_ReadBlock(start, antwort,blocksiz);
    antwort[6]=0;
    printf_screen(antwort);


When you have an array, the reference to the name (antwort) will give you automaticly the adress to the ram point, if you use antwort[0] it will give you the first data in the array

Hope that can help you a tlitle

Kasper

Offline

 

# 3   2009-06-01 11:21:48 SD Card Read/Write without circle OS

rob1
New member
Registered: 2009-05-18
Posts: 3

Re: SD Card Read/Write without circle OS

First thannks for the fast answer.
The printf_screen methos requires a String which is the same like an char[] in C. That works like i did. If i add the antwort[0]='t'; for example:
    u32 start=((u32)0x00000000);
    char antwort[4096];
    u32 buf=(u32)&antwort;
    SD_ReadBlock(start, &buf,blocksiz);
    antwort[0]='t';
    antwort[20]=0;
    printf_screen(antwort);

I get the "t" on the screen the sign after the t are unreadable...

If i leave the & or replace adr with test nothing really changes. Maybe the method description helps a little.

/*******************************************************************************
* Function Name  : SD_WriteBlock
* Description    : Allows to write one block starting from a specified address
*                  in a card.
* Input          : - addr: Address from where data are to be read.
*                  - writebuff: pointer to the buffer that contain the data to be
*                    transferred.
*                  - BlockSize: the SD card Data block size.
* Output         : None
* Return         : SD_Error: SD Card Error code.
*******************************************************************************/
SD_Error SD_WriteBlock(u32 addr, u32 *writebuff, u16 BlockSize)
{


/*******************************************************************************
* Function Name  : SD_ReadBlock
* Description    : Allows to read one block from a specified address in a card.
* Input          : - addr: Address from where data are to be read.
*                  - readbuff: pointer to the buffer that will contain the
*                    received data
*                  - blocksize: the SD card Data block size.
* Output         : None
* Return         : SD_Error: SD Card Error code.
*******************************************************************************/
SD_Error SD_ReadBlock(u32 addr, u32 *readbuff, u16 BlockSize)
{

so any other ideas?

Offline

 

# 4   2009-06-01 12:27:55 SD Card Read/Write without circle OS

repzak
Member
Registered: 2008-03-05
Posts: 170

Re: SD Card Read/Write without circle OS

Hello,

   char test[6];
    test[0]='h';
    test[1]='e';
    test[2]='l';
    test[3]='l';
    test[4]='o';
    test[5]=0;
    u16  blocksiz=512;
    u32 startadr = ((u32)0x00000000);
    SD_WriteBlock(startadr, &test[0], blocksiz);


------------------------------------------------------------

    u32 start=((u32)0x00000000);
    char antwort[4096];
    SD_ReadBlock(start, &antwort[0],blocksiz);
    antwort[6]=0;
    printf_screen(antwort);

I think that must work, you sure the card is initlized correctly, think you get a value back from init_sd()?

Kasper

Offline

 

# 5   2009-06-02 01:16:14 SD Card Read/Write without circle OS

rob1
New member
Registered: 2009-05-18
Posts: 3

Re: SD Card Read/Write without circle OS

Hello kasper,
thanks for the hint with the errors.
I catched them but init throws SD_OK but read and write not. They both throw an SD_CMD_RSP_TIMEOUT Error which means Comand response timeout. What can that mean?

I will try to localize the error more detailed...

but if anybody can help....

Offline

 

Board footer