' Program: MMC3V.BAS written using PicBasicPro ver 2.40' PicBasic Pro program to interface with a Sandisk' MMC module using the SPI protocol.'' BETA CODE' ************* NOT FOR COMMERCIAL USE *************************' Ver. 0.1.31 Nov, 2001'' Proprietory Owner: COMPsys, Copyright 2001'' Project Reference: MMC3V-F876' MCU: Microchip PIC16F876' Software: Compiler PBP V.2.40, IDE MBLAB Ver 5' PIC Programmer: EPIC used to load the bootloader, ' Custom PCB with a serial interface' for ISP and terminal output'' Initial Date: OCT 28, 2001' Projected Completion Date: Unknown'' Author: Ranjit Diol' rsdiol@compsys1.com' http://www.compsys1.com/workbench''---------------------------------------------------------------' (c) COMPSys, 2001' All Rights Reserved'***************************************************************' DISCLAIMER: This file is being released as non-commericial' freeware. It is being provided "AS IS", neither the author, ' nor COMPSys shall be held liable for any damages caused directly' or indirectly by its use. '***************************************************************'Brief: The MMC is a 3volt part therefore all data lines' must be conditioned if interfacing with a 5v mcu.'' MMC pins in SPI mode:' Pin1:ChipSelect(SS),Pin2:MMC input(MOSI),Pin3:GND,Pin4:3V+,' Pin5:Clock(SCK), Pin6:GND, Pin7:MMC output(MISO)' PIC pins:' Portd.7 SS,Portd.6 SCK,Portd.5 MOSI, Portd.4 MISO'' For voltage translation: ' An LM317 or LM2937-3.3 can be used to provide 3.3 volts' for the MMC and four 2N3904 transistors with resistors' can be used forfor MMC power and data line conditioning' See the SanDisk website for more details' http://www.sandisk.com'=============================================================='' I M P O R T A N T' PLEASE NOTES' ************** This code is written for a PIC16F876 operating on 3.3volts **************@ device pic16F876, xt_osc, wdt_on, pwrt_off, bod_off, lvp_off, cpd_off, wrt_off, protect_off' ****************************************************************************************'' This application uses a external 3.3v FRAM FM24CL64 for temporary storage' which does not require a wait state after a write and it does not have' any limit on the number of lifetime writes!'' IF YOU USE a standard I2C EEprom you will have to insert a 5 or 10 ms pause' after each write statement depending on the eeprom used.''******************************************************************************************

'====================== END OF MMC GENERAL ROUTINES =========================

'Subroutine used by this applicationdisp:serout2 out_pin,ser_baud,["Data from MMC",10,13] 'Display on terminal'Display data to terminal, assumes eaddr1,eaddr2 are given for e_addr = eaddr1 to eaddr2 I2CREAD sda,scl,ctl,e_addr,[dat] serout2 out_pin,ser_baud,[dat] 'Display on terminal next e_addrreturn

'Load the eeprom with some data to simulate this we'write 512 bytes to the eeprom Dat = "A" for e_addr = eaddr1 to eaddr2 I2CWRITE sda,scl,ctl,e_addr,[dat] next e_addr

'Set some MMC address 0 - to the end. (However, it must remain within sector boundaries)'Since we are reading/writing 512 bytes at a time just make sure that the address is a integer'multiple of 512 bytes. Such as: 0, $0200,$0400...$0A00...$00010A00 etc

addr_H = $0001 addr_L = $0000 'Multiple of 512 bytes

'Now transfer the data from the eeprom to the MMC gosub mwrite

'For debuggingserout2 out_pin,ser_baud,["Data Written to MMC",10,13] 'Display on terminal

'Next, we read the data back from the MMC and load it into the eeprom'using the same addresses as above gosub mread

'Now, read it back from the eeprom and display itgosub disp

'If you want to erase the data you need to set the start and end addresses'But, they must not cross block boundaries

'*** Note*****'If the program hangs at the erase command'Sandisk documentation states that the erase command in SPI mode can'sometimes not work correctly. Depends on the version of the card.'However,it works fine on the Viking MMC's