CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

MMC problem

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Guest








MMC problem
PostPosted: Sun Jul 06, 2008 12:37 pm     Reply with quote

I use mmcsd.c . I have problem with change blocks. first I use mmcsd_write_byte(i, j). and when
i = 512 by mmcsd_write_single_block(X) I change the blocks. I want know is it correct? In this way I can't read the
all blocks. Is there a better way for write 5000 characters and read them? please help....
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

Re: MMC problem
PostPosted: Sun Jul 06, 2008 3:28 pm     Reply with quote

Anonymous wrote:
I use mmcsd.c . I have problem with change blocks. first I use mmcsd_write_byte(i, j). and when
i = 512 by mmcsd_write_single_block(X) I change the blocks. I want know is it correct?
This is not correct. mmcsd_write_single_block() is an internal function and you are not supposed to use it (that's why it is not documented in the file header).

Using mmcsd_write_byte() or mmcsd_write_data() you don't have to worry about the block boundaries. Just call these functions and they will use an internal buffer to speed up card handling and flush the internal buffer on crossing a card's block boundary.

Writing single bytes:
Code:
int8 Data=123;
int32 Addr;

for (Addr=0; Addr<5000; Addr++)
{
  mmcsd_write_byte(Addr, Data);
}
mmcsd_flush_buffer();  // flush any remaining buffered characters.

Or if you want to write the contents of a buffer:
Code:
int8 Data[]={1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int32 Addr=0x00000050;

mmcsd_write_data(Addr, sizeof(Data), Data);
.
. do other things
.
mmcsd_flush_buffer();  // flush any remaining buffered characters.
Guest








PostPosted: Sun Jul 06, 2008 10:24 pm     Reply with quote

thanks but I use mmcsd_flush_buffer() but I couldn't get result.
Code:

  while (j <'z')
  {
    j=getc();
    putc(j);
    mmcsd_write_byte(i++, j);
  }

for example I want get data from serial port and put one by one characters
in MMC. In this code when the address pointer become 512 I cant keep one the write. in other word I can't write in next block. so what's the way?
ROBOTICAR



Joined: 28 Aug 2007
Posts: 45

View user's profile Send private message

PostPosted: Mon Jul 07, 2008 2:33 am     Reply with quote

I have the same problem. and dear "ckielstra" this program doesn't work.
I tested it. can you say better way to write 3 blocks(means 3*512 bytes) then read them? I couldn't understand the usage of mmcsd_flush_buffer().
may you explain? and I have another problem. I read and write in one block. but when I reset the circuit the information in the MMC are cleaned.
where is the problem?
thanks
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon Jul 07, 2008 3:29 pm     Reply with quote

Anonymous wrote:
thanks but I use mmcsd_flush_buffer() but I couldn't get result.
Code:

  while (j <'z')
  {
    j=getc();
    putc(j);
    mmcsd_write_byte(i++, j);
  }

for example I want get data from serial port and put one by one characters
in MMC. In this code when the address pointer become 512 I cant keep one the write. in other word I can't write in next block. so what's the way?
- The program is incomplete. How is 'i' defined?
- What is the size of your MMC/SD card?
- What is the version number of your compiler?
- How do you test the write succeeded? Can you post this routine?
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon Jul 07, 2008 3:48 pm     Reply with quote

ROBOTICAR wrote:
I have the same problem. and dear "ckielstra" this program doesn't work.
I tested it.
For you the same questions:
- What is the size of your MMC/SD card?
- What is your compiler version number?
- How did you test?

ROBOTICAR wrote:
can you say better way to write 3 blocks(means 3*512 bytes) then read them?
'Better' depends on your application, but how about mmcsd_write_block() and mmcsd_read_block()?

ROBOTICAR wrote:
I couldn't understand the usage of mmcsd_flush_buffer().
may you explain? and I have another problem. I read and write in one block. but when I reset the circuit the information in the MMC are cleaned.
where is the problem?
Both questions are related to the same answer.
In MMC/SD cards the data can only be programmed in blocks of 512 bytes. To modify a single byte you have to read all 512 bytes, modify the single byte and then write all 512 back to the card. This is a huge performance loss and will wear out the card very fast. As an optimization the CCS driver uses an internal buffer. On first access the 512 byte block will be read once and then all modifications are only performed on the buffer. When the address you specify moves out of the current block range the whole buffer is written to the memory card (data is flushed) and the next block will be read.
If you switch off the PIC the last modified data will still be in the RAM buffer and is lost. To prevent this you have to call mmcsd_flush_buffer() before power down.

I recommend you read the text at the top of the file mmcsd.c, a description of all functions is given here.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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