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

Need help about using MMC/SD card drivers of CCS

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



Joined: 05 Mar 2010
Posts: 5

View user's profile Send private message

Need help about using MMC/SD card drivers of CCS
PostPosted: Mon Mar 29, 2010 1:21 pm     Reply with quote

Hi
I'm trying to make a project about calculating some values and record them to a MMC/SD card (but it can be a different memory module). I managed to gather up all programing work but I got stuck writing to card thing. I searched the forum about MMC cards and checked the example codes in CCS directories but could not find proper commands to do my job. All I need to create a .txt file or something else that can be read from a pc, write the informations (5 different values names and numbers) to SD module when invoked in program. My sub program about writing to SD section is:
Code:

void memory_10sn(void)
{
if(ten_sec)
   return;
else
lcd_putc("\f 10 s recorded\n");
value = frequency,hour,min,sec;
         mmcsd_write_byte(address, value);
ten_sec = tensec_ticks;
delay_ms(500);
}

I tried writing commands as you can see but I'm using Proteus to test and .img file for sd card is empty (but sd card is initialized!). This subprogram is called every 10 seconds and it displays ""10 s recorded"" message but I want to write the value variable to sd card too.
By the way is it the easiest way to storage data from 18f452 ? As you can see i don't want much properties, just writing periodically by low-level sd card implement.
I'm using PCWHD 4.104 and mmcsd.c driver with modifying C2 to C1 pin. C2 pin is used by CCP module, and I can study mmc_spi driver if it is enough for my task. I guess it is better than mmcsd.c. I need this information badly because I've been working for this task for a month and all I need to implement a recording algorithm to finish. Your help will be greatly appreciated. Thank you.
ckielstra



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

View user's profile Send private message

PostPosted: Mon Mar 29, 2010 4:00 pm     Reply with quote

Code:
value = frequency,hour,min,sec;
Study your C-language books again, the comma operator is not doing what you want it to do: 'value' contains only the frequency data, the other three variables are ignored.
My advice is to never use the comma operator, it often creates difficult to understand code which in turn is a cause of bugs.

Code:
mmcsd_write_byte(address, value);
You'll have to increase the address after every write or you'll be overwriting the old data.

The reason for your image file to stay empty is most likely because the driver routines contain an optimization algorithm. SD cards have to be written in blocks of 512 bytes, in order to improve speed the driver buffers all written data until a 512 byte address border is crossed. You can force a write by calling the flush function.

Code:
void memory_10sn(void)
{
  if (ten_sec)
    return;

  lcd_putc("\f 10 s recorded\n");
  mmcsd_write_byte(address++, frequency);
  mmcsd_write_byte(address++, hour);
  mmcsd_write_byte(address++, min);
  mmcsd_write_byte(address++, sec);
  mmcsd_flush_buffer();

  ten_sec = tensec_ticks;
}


The code above will only write raw data to the SD card. If you want to write to a text file you need to make the PIC aware of a file system. See the example program ex_fat.c for how to do this.
I've never tried the CCS supplied FAT driver and don't know the current status, but in the past several problems were reported. Best is to have the card formatted on a PC and not use the CCS supplied format function.
Scythe



Joined: 05 Mar 2010
Posts: 5

View user's profile Send private message

PostPosted: Tue Mar 30, 2010 7:52 am     Reply with quote

Thanks for advice. I changed code,
ckielstra wrote:
You can force a write by calling the flush function.

I tried using that flush_buffer function before but program stucks when that flush_buffer is used. It displays constantly 10s recorded and clk pin of MMC card keeps flashing(blue-red-blue-red) and it doesn't return main program. I guess it can't write anything to address so it is not returning 0 value and to main. Maybe I'm doing something wrong because I use only mmcsd_init() function to initialize mmc and nothing else ?
By the way, you mentioned a raw data, is it something like not encoded data ? Or it can be readed by PC with using some tricks?
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