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 support@ccsinfo.com

MMC/SD AND PIC16F876
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ALCION



Joined: 31 May 2007
Posts: 16

View user's profile Send private message

MMC/SD AND PIC16F876
PostPosted: Thu May 31, 2007 7:08 pm     Reply with quote

Hi, I know there are many post about it, but I dont know why it dont work. I use the mmc_spi.c driver but I have alot of erros. I have pcm ver 3.222 is a problem this? somebody have an example. thanks alot.
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Thu May 31, 2007 9:46 pm     Reply with quote

If you want to write to the SD/MMC card with this PIC then you need to be aware that you must write in 512 byte blocks. These is very challenging when using a PIC that has only 384 bytes of RAM. If you want to write to the card then a PIC18F series controller, such as a PIC18F2620 (virtually pin compatible with the PIC16F876), with 3900 bytes of RAM is a better choice.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
ALCION



Joined: 31 May 2007
Posts: 16

View user's profile Send private message

PostPosted: Thu May 31, 2007 9:51 pm     Reply with quote

Ok, Thanks asmallri

I will check that.
Guest








PostPosted: Wed Jul 25, 2007 8:44 am     Reply with quote

if i may i would like to ask if i wanted nevertheless use the 16f pic is it possible to do so? can i use the EEPROM memory? or the only solution is to change to a 18f pic?

Thank you
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Wed Jul 25, 2007 10:29 am     Reply with quote

Well the restriction imposed by the card is that you must write 512 bytes each and every time you write. Now this often is interpreted as needing 512 bytes of ram. This comes from the fact that if a sector (512 bytes) is to be updated then it must be read in and then modified before writing out. So 512 bytes of storage are needed to prevent loss of data. Now if you are writing a new sector or erasing and re-writing an existing sector all that matters is that you write 512 bytes. If you chose to write "x" to every byte then you wouldn't need the RAM but it would be of little practical use. The 512 byte restriction doesn't apply to a read reads have a modifiable block size. MMC SD cards work well with the PIC small pin count , built in SPI but the nice thing is the controller on the card automatically keeps track of bad sectors so physical bad sector differences between cards are hidden by the cards controller and the PIC programmer can ignore them. Something to wish for would have been for the cards controller to have added embedded logic for a file system. That way we wouldn't need Microsoft patent permission as we do with FAT when placing FAT code on a PIC and it would free up code space on the PIC.
ckielstra



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

View user's profile Send private message

PostPosted: Wed Jul 25, 2007 4:34 pm     Reply with quote

Anonymous wrote:
if i may i would like to ask if i wanted nevertheless use the 16f pic is it possible to do so? can i use the EEPROM memory? or the only solution is to change to a 18f pic?
No, you can't use the EEPROM as this will 'wear out' over time and corrupt your data.

As Douglas already hinted to there is a possible tweak to work around the 512 byte restriction. Writes to the MMC have to happen in 512 byte chunks but you could decide to only use let's say the first 100 bytes and fill the rest of the block with fixed zero values. On reading the data you have to take care only to read the first 100 bytes of every block.
This is a terrible waste of MMC memory capacity, but who cares anyway with the low MMC prices nowadays?
Guest








PostPosted: Fri Jul 27, 2007 10:15 am     Reply with quote

thanks for your answer but i have another one

I want to write some data from the pic to the sd card using SPI but i want the written data to be acessible from a card reader. to do this i must write a fat32 code and a spi transfer code or if i just write the spi transfer code to write in each 512 bytes of the sd card this will be readable in the card reader? don't know if i made myself clear?

thanks
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Fri Jul 27, 2007 10:52 am     Reply with quote

Data is data so if you write it to the card it will be on the card. Now having it read and understood by a card reader depends on the software attached to the card reader. This software is often called a driver. It's purpose is to relieve some higher level operating system from gaining too much knowledge about hardware. In the case of Microsoft and the FAT file system usually the Microsoft OS sends primitives ( like open close read write erase format) to the driver and driver in turn deals with the firmware/hardware ( MMC card and controller). If the card reader uses FAT drivers the card will need a FAT format. Now you could format the card using a PC operating system and place a single very large file on it.
You could write with a PIC (using very stripped down PIC code) to that file. You still have to read the FAT cluster tables to get the physical address for the sectors within this large file. You could develop your own file system always keeping it wrapped by your single large file. Your PC would using your own c code open the file and access your file system.
Remember Microsoft has a patent and you should not see this post in anyway as encouraging you to violate this lawful patent.
ckielstra



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

View user's profile Send private message

PostPosted: Sat Jul 28, 2007 6:59 am     Reply with quote

Anonymous wrote:
I want to write some data from the pic to the sd card using SPI but i want the written data to be acessible from a card reader. to do this i must write a fat32 code and a spi transfer code or if i just write the spi transfer code to write in each 512 bytes of the sd card this will be readable in the card reader? don't know if i made myself clear?
This same problem was discussed in http://www.ccsinfo.com/forum/viewtopic.php?t=27295&postdays=0&postorder=asc&start=15

I like Libor's suggestion of having the PC create one large file on the MMC card. This way all the FAT related stuff is left to the PC. In your PIC you only have to write some code to find the start address of the file and than you can start writing.
radiocode



Joined: 26 Jun 2007
Posts: 4
Location: Chippenham, England, UK

View user's profile Send private message

PostPosted: Tue Jul 31, 2007 8:45 am     Reply with quote

I have started work on a GPS datalogger at home - one solution I have been toying with is to hook a Ramtrom Ferrite RAM to the PIC 16F and use that to cache the 512 byte blocks prior to writing it to the SD/MMC.

The FRAM devices are cheap and reasonably fast - they don't suffer the write delay problems of FLASH EEPROM either. They are a lot slower than using external RAM, but at least I can use a 16F device and not have to upgrade my compiler Smile

Having the FRAM on the board might have a positive impact on power consumption too - cache several blocks then write them to the SD/MMC in one hit.... Hmmm, something to try.

Lee

So little time... so many hobbies!
ckielstra



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

View user's profile Send private message

PostPosted: Tue Jul 31, 2007 9:04 am     Reply with quote

Quote:
They are a lot slower than using external RAM
True, but FRAM is faster than a 40MHz clocked PIC can write the data over SPI so this is not an issue.
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Tue Jul 31, 2007 9:16 am     Reply with quote

radiocode wrote:
I have started work on a GPS datalogger at home - one solution I have been toying with is to hook a Ramtrom Ferrite RAM to the PIC 16F and use that to cache the 512 byte blocks prior to writing it to the SD/MMC.


Why would you do this when you could plus a 2620 in your existing hardware cheaper than you can add the RAM and end up with a better solution?
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
radiocode



Joined: 26 Jun 2007
Posts: 4
Location: Chippenham, England, UK

View user's profile Send private message

PostPosted: Tue Jul 31, 2007 3:01 pm     Reply with quote

asmallri wrote:
Why would you do this when you could plus a 2620 in your existing hardware cheaper than you can add the RAM and end up with a better solution?


I like the intellectual challenge! (Plus I have the PCM compiler which doesn't do the 18F parts!)

I'd agree that the 18F part would be a far nicer implementation though. I'd better start saving my pennies for an upgrade.

Lee
radiocode



Joined: 26 Jun 2007
Posts: 4
Location: Chippenham, England, UK

View user's profile Send private message

PostPosted: Tue Jul 31, 2007 3:07 pm     Reply with quote

asmallri wrote:
Why would you do this when you could plus a 2620 in your existing hardware cheaper than you can add the RAM and end up with a better solution?


I like the intellectual challenge! (Plus I have the PCM compiler which doesn't do the 18F parts!)

I'd agree that the 18F part would be a far nicer implementation though. I'd better start saving my pennies for an upgrade.

Lee
ckielstra



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

View user's profile Send private message

PostPosted: Tue Jul 31, 2007 3:18 pm     Reply with quote

Quote:
I have started work on a GPS datalogger at home - one solution I have been toying with is to hook a Ramtrom Ferrite RAM to the PIC 16F and use that to cache the 512 byte blocks prior to writing it to the SD/MMC.
Just wondering, how are you going to copy from the FRAM to the MMC card? You can't put them both on the same SPI bus because when you start the block write on the MMC card you are not allowed to de-activate the chip select line until the block is finished. Do you have the FRAM on a second SPI bus or on I2C?

I found this out the hard way. Crying or Very sad
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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