Captain's Universe Home
Captain's Universe Home
Cosmic Ray Muon DetectorTeleGarden Pages
Time on MarsBryophyllum Plants
Jupiter Radio AstronomyAncient Pages
Salzburg Tourist GuideEarth Magnetometer
  H O M E     AJAX & MORE     LINUX & MORE     RTAI     XENOMAI     ADEOS IPIPE      
    JAVA & BROWSERS     *NIX     ELECTRONICS     REVIEWS     ARTEMIA     FAIRY SHRIMP      



PIC - MMC (Multi Media Card) Flash Memory Extension

It is easy to interface a MMC (MultiMediaCard) with a MicroChip PIC via the SPI (Serial Port Interface). This is a very handy data logging circuit with lots of memory for data storage. I2C RAM's or EEPROM's are hardly available at sizes bigger than 256kb, but this solution with a 64MB Flash MMC is not to beat in both cost effectiveness and storage volume!
Also see: Atmel ATmega - MMC (Multi Media Card) Flash Memory Extension.



Hardware:
PIC - MMC Schematic
Click on the schematic for a large view (opens in a new window)


This version utilizes a PIC16F876, but it's easy to port the schematic and software to other PIC's.
The MMC is connected to the SPI pins of the PIC via simple resistor voltage dividers to transform the +5V high levels to about 3.3V used by the MMC. The supply voltage for the MMC (2.7V - 3.6V) comes from a LD1086V33 voltage regulator (3.3V) or equivalent. It is possible to run the PIC at 3.3V, but then the AD converters are not as stable as at 5V. The data-out pin from the MMC goes directly to the PIC, because 3.3V is high for the PIC anyway.

Software:
BUGFIX 30-NOV-2004: Added serialterminate() to mmc.c for reliable termination of the sent string over the serial port.

UPDATE 02-DEC-2004: Version 2 of serterm (serterm2) released

UPDATE 05-NOV-2005: The ser example got it's own page

UPDATE 09-DEC-2005: Check the Atmel-MMC page for an update of the MMC code (regarding the while-loop)

Compile the PIC program's with the CC5X compiler (free version available - runs on Linux with "dosemu")



mmc.c:
This C-prg. writes ASCII characters into the RAM of the PIC. Then the content of the RAM is written to the MMC. In order to verify the successful data transmission to the MMC, 512 bytes are read back and sent directly to the Linux box via the serial port (RS232) and are displayed by "serterm".
Furthermore the PIC returns any character received (via interrupt service routine) via the serial port back to the Linux machine. Use "ser" to send 3 characters and receive them.

sercom.c:
This example only sends back any character received by the PIC (via interrupt service routine) via the serial port. Use "ser" to send 3 characters and receive them.

serterm2:
Linux software to receive serial data from the MMC example. NOTE: It uses ttyS1

Another way for reading the serial port on Linux is this very handy bash script :
#!/bin/bash
while true
do
	read LINE < /dev/ttyS0
	echo $LINE
done

Third way for reading the serial port is the Debian Packge "ttylog":
# ttylog -b 9600 -d /dev/ttyS0

ser:
Linux program to send characters to the PIC and print out the returned characters. NOTE: It uses ttyS0

Writing to the MMC can be at any speed (i.e. 1byte per hour), but the "sector" is only saved if 512bytes were transmitted.



Software SPI-Interface

Not all PIC's have a SPI-Interface or if you want to use the I2C bus, you'll have to use other pins for the communication with the MMC. Michael Dworkin has written a very handy sub routine, which will replace the function char SPI(char d) in the mmc.c example.
You can choose any free port pins for use as SPI interface.
#pragma bit CS @ PORTC.2	// output for chip select CS
#pragma bit SCK @ PORTC.3	// clock output
#pragma bit SDO @ PORTC.5	// data output (PIC)
#pragma bit SDI @ PORTC.4	// data input (PIC)
Don't forget to set the TRIS register!
TRISC=0b.1101.0011;	// SCK rc3-0, SDO rc5-0, CS rc2-0        
The new SPI function:
char SPI(char out)  // software SPI function at about 620 kHz for a 20MHZ crystal
{
	char in,i;
	for (i = 0; i < 8; i++)
	{
		nop2();
		SCK = 0;          // falling edge of clock
		nop();
		SDO = out.7;      // prepare data
		nop();
		out = out<<1;     // shift output byte for next loop
		nop2();
		in = in<<1;       // shift input data for next loop
		SCK = 1;          // rising edge of clock
		nop();
		in.0 = SDI;       // read input data
	}
	return in;
}


Credit: Thanks to Michael Dworkin for his MMC tutorial.

Last-Modified: Fri, 09 Dec 2005 17:28:54 GMT

Google
 
Web www.captain.at
go to top
© 1996-2010 . All rights reserved.
No reproduction, distribution, publishing or transmission of the copyrighted materials at this site is permitted. Policy
go to top