64MB MMC and PIC Micro Controller

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 10

64MB MMC and PIC Microcontroller

MMC memory card with PIC16F877 letter of a Multimedia Card (MMC) at each
PIC Mikrocontroller /Lesen over mirror-image interface (MMC 64MB and PIC
Microcontroller) a software related mirror-image interface makes possible the
connection. Connection diagram, theory about mirror-image interface, theory
about MMC, signal diagrams, program in C (CC5X).

+
MMC (Multimedia Card) here The PIC16F877 has:
64MB. - Mirror-image interface
- Enormous FLASH - memory. - RS232 interface
- Very fast. - of 8 entrances for the similar to/digital
-300000 write accesses. transducer (10Bit)
- Vintages without restriction.
- Connection to the SPADES with 4
lines.
Pin Contraction Function Pin Contraction Function
1 /CS Chip activating 18 RC2 Digitally OUT
2 DATA IN Data input 24 SDO MIRROR-IMAGE data
output
3 GND - - - -
4 Vdd Voltage supply - - -
5 CLK Clocking line 18 SCL MIRROR-IMAGE
Clock
6 GND - - - -
7 DATA OUT Data output 23 SDI MIRROR-IMAGE data
input

Circuit and connection diagram MMC need as voltage supply 2,7V 3,6V. We
must use an in any case voltage regulator for 3,3V, for example CS5203. PIC
processors can be operated with tensions between 2V and 5,5V. Thus one
could agree with the supply of both units on 3,3V. Then it is also possible to
connect MMC directly with the micro CONTROLLER. Due to considerations that
the AD transducer and serial communication with 5V functions more stably it is
operated, in this circuit of the PIC16F877 nevertheless with 5V. But the micro
CONTROLLER exits SDO, SCL, /CS get in each case a voltage divider, so that
the MMC entrances receive only 3,2V. The entrances of the microprocessor do
not need reinforcement of 3,3V on 5,0V, because the PIC understands 3,3V
anyway as logical "1"
.

How does MIRROR-IMAGE ONE actually function? MIRROR-IMAGE ONE is a


serial synchronous interface. It means synchronous that each bit is
received/sent during a clock pulse
In the picture we see a register, where a byte will receive sent and. There were
2 clock pulses to bit 7 and bit 6 is sent over OUT. And 2 bits (also 7, 6) from new
byte receive. After 8 clock pulses the byte which can be sent is completely
"raus" and the received byte complete in the register. If the PIC works as
master, then it produces the clock pulses, which a Slave equipment needs to be
able to receive in order to push in time its register and thus send correct bits/.
With PIC Microcontrollern it is sufficient to transfer into the SSPBUF register a
byte, thus it begins this byte to send and a new receive. One may select
however not too early (while it pushes data) SSPBUF. Therefore we examine
the BF flag, it are reset during the transmission procedure. MMC one may to
20MHz clocks (CLK).

The MIRROR-IMAGE interface of the PIC can be stopped maximally to 5MHz. If


one has however long lines between PIC and MMC, then one must stop the
clock frequency lower, otherwise the signal form gets broken and it to happen
the errors. (with me there is 15cm lines).

The

following diagram shows attitude possibilities for MIRROR-IMAGE interfaces


with PIC's

MMC initializing in mirror-image mode


0 tension 1 sending 80 clock pulses 2 /CS activating, /CS=0, (1 passively) 3
sending CMD0 4 confirmation byte = 0x01? if no ERROR if 5 sends 8 clock
pulses

to 6 sending CMD1 7 confirmation byte = 0x00?wenn no go to 6 if 8 send 8


clock pulses MMC initialization into mirror-image mode finally

Executable program, description of function

This function serves for spending messages. In


order to send an indication serially, these
SerString("Hallo Welt")
instructions are used. Function sends b over
MIRROR
while(!TXIF); //_ Prüfen ob This function serves for spending messages. In
Register TXREG leer ist order to send an indication serially, these
TXREG ='W'; // Buchstabe "W" instructions are used. Function sends b over
seriell senden MIRROR
This function serves for spending messages. In
order to send an indication serially, these
a=SPI(b);
instructions are used. Function sends b over
MIRROR
Command(0x49,0,512,0xFF ); This function serves for spending messages. In
order to send an indication serially, these
instructions are used. Function sends b over
MIRROR
This function serves for spending messages. In
order to send an indication serially, these
MMC_Init()
instructions are used. Function sends b over
MIRROR

#include <C:\cc5\16F877.H>
// Speicherschutz 12-13-4-5=aus, Debug 11=aus,ProgrammFlash 9=an,
EEpromRead 8=an, NiederVoltProgr 7=aus
// NiederVoltReset 6=an, EinschaltTimer 3=an, WachDogTimer 2=aus,
Oszilator 01=XC
#pragma config |= 0b.11.111101.11.00.10

#pragma bit CS @ PORTC.2 //Ausgang für Chip Select

#pragma origin 100 // Ab Adresse 100 im Programmspeicher


//********************************************************************
*

void InitUSART()
{
BRGH=1; // Hohe Geschwindigkeit für Datenübertragung
//SPBRG=129; // (9600 baud @ 20MHz input clock)
//SPBRG=64; // (19200 baud @ 20MHz input clock)
//SPBRG=32; // (38400 baud @ 20MHz input clock)
SPBRG=10; // (115200 baud @ 20MHz input clock)
SPEN = 1; // Set_Serial_Pins;
SYNC = 0; // Set_Async_Mode;
TX9 = 0; // Set_8bit_Tx;
RX9 = 0; // Set_8bit_Rx;
CREN = 1; // Enable_Rx;
TXEN = 1; // Enable_Tx;
RCIE=0; // Rx Interrupt aus
}
//********************************************************************
**

void SerString(const char *str) // String seriell senden


{
char ps;
ps = *str; // Pointer auf Start des Strings ins ps
while(ps>0) // Prüfen ob String zu Ende ist
{
str++; // Pointer auf nächstes Zeichen erhöhen
if (ps== 0) break; // Prüfen ob String zu Ende ist
while(!TXIF); // Prüfen ob Register TXREG leer ist
TXREG =ps ; // Datenbyte senden
ps = *str; // Inhalt des Pointers ins ps
}
}
//********************************************************************

char SPI(char d) // Über SPI-Schnittstelle senden


{ //
SSPBUF=d;
while (!BF); // Warten bis gesendet ist
return SSPBUF; // gleichzeitig empfangen
}
//********************************************************************
**

char Command(char befF,uns16 AdrH,uns16 AdrL,char befH )


{ // Einen Befehl zum MMC senden
char a;
SPI(0xFF);
SPI(befF);
SPI(AdrH.high8);
SPI(AdrH.low8);
SPI(AdrL.high8);
SPI(AdrL.low8);
SPI(befH);
SPI(0xFF);
return SPI(0xFF); // Response als Rückgabewert
}
//********************************************************************
******

bit MMC_Init()
{
// Init SPI
SMP=0; // Input ist gültig in der Mitte des Clock's
CKE=0; // Bei steigender Flanke Datenübernahme
CKP=1; // High ist passiver Zustand
SSPM1=1; // Geschwindigkeit f/64(312kHz), Master
//SSPM0=1; // Geschwindigkeit f/16(1,25MHz), Master
SSPEN=1; // SPI Ein

CS=1; // MMC-Disabled

char i; // Variablen

//MMC in SPI-Modus starten, Reset


for(i=0; i < 10; i++)SPI(0xFF); // 10*8=80 mal takten
CS=0; // MMC-Enabled

// CMD0
if (Command(0x40,0,0,0x95) !=1)goto Fehler ; // Reset

st: // Wenn MMC nicht da ist,


bleibt
// CMD1 // Programm hier stehen
if (Command(0x41,0,0,0xFF) !=0) goto st ; // CMD1 solange
wiederholen
/*
// CID auslesen
if (Command(0x4A,0,0,0xFF) !=0) goto Fehler; // Karten ID-Nummer
for(i=0; i < 20; i++)
{
while(!TXIF);
TXREG =SPI(0xFF);
}

// CSD auslesen // Kartenspezifische


Daten
if (Command(0x49,0,0,0xFF) !=0) goto Fehler;
for(i=0; i < 20; i++)
{
while(!TXIF);
TXREG =SPI(0xFF);
}
*/
// Set Lenge (Default ist 512 Byte)
//if (Command(0x50,0,16,0xFF) !=0) goto Fehler; // 16 Byte-Mode
für Lesen

return 1;
Fehler:
return 0;
}
//********************************************************************
******

void main(void)
{
INTCON=0; // Interrupts aus
ADCON1=0x6; // PortA Digital
TRISC=0b.1101.0011; // sck rc3-0, sdo rc5-0, CS rc2-
0.
TRISB=0b.0000.0010; // RB2>TX, RB1>RX
uns16 i; // Variable 0...65535
InitUSART(); // Serielle Datenübertragung
initialisieren
SerString("Ich bin ON "); // Startmeldung
if (MMC_Init()) SerString("MMC ON "); // MMC Initialisieren und
Meldung falls OK!
//********************************************************************
**********

// Lesen 512 Byte-Mode


if (Command(0x51,0,512,0xFF) !=0) SerString("Lese_resp_Fehler ");
while(SPI(0xFF) != 0xFE); // Warten auf 0xFE,
Anfang jeder Datenübertr.
for(i=0; i < 512; i++)
{
while(!TXIF); // Prüfen ob Register
TXREG leer ist
TXREG =SPI(0xFF); // Datenbyte senden
}
SPI(0xFF); // Am Ende 2 Byte's ohne
Bedeutung
SPI(0xFF);
//********************************************************************
****

// Schreiben 512 Byte-Mode


if (Command(0x58,0,512,0xFF) !=0) SerString("Schreib_resp_Fehler ");
SPI(0xFF);
SPI(0xFF);
SPI(0xFE);
for(i=0; i < 512; i++)
{
SPI('M');
}
SPI(255); // Am Ende 2 Byte's ohne
Bedeutung senden
SPI(255);
i=SPI(0xFF);
i &=0b.0001.1111;
if (i != 0b.0000.0101) SerString("Schreib_Fehler ");
while(SPI(0xFF) !=0xFF); // warten auf Ende des Busy
-Zustandes.

//********************************************************************
**
while(1); //hier bleibt Programm stehen
}
Program sequence

first those of haven are adjusted. Then the serial interface initialized with
115200 Baud, no parity bit, 1 stop bit and the message: "I am ON" spent.
Afterwards MMC one initializes; if that is successful, then the message
becomes: "MMC ON" spent. Next 512 byte is read in and sent serially to the
PC. Afterwards 512 byte with the indication ' M ' is described. One writes and
one reads starting from address 512. Starting from address 512 the reserved
range begins when formatting with FAT16, so that even the data and file system
on your MMC map remain. With errors the following messages can occur: -
"Lese_resp_Fehler" - no answer to instruction read, - "Schreib_resp_Fehler" -
no answer to instruction write, - "Schreib_Fehler" - after the recording procedure
no confirmation. With this program each address can be described and read.
One can stop the read block size at will. Here are signal diagrams of the
recording procedure and reading. To the Download: Connection diagram
+Quellkode +Hex file

Software related mirror-image interface

All PIC types does not have the mirror-image interface, therefore I wrote a
subroutine, which makes mirror-image communication possible with each PIC
Mikrocontroller. With the program one can select the pins for the mm approx.
conclusion freely. This selection happens on the beginning of the program:

#pragma bit CS @ PORTC.2 // Ausgang für Chip Select


#pragma bit SCK @ PORTC.3 // Ausgang Clock
#pragma bit SDO @ PORTC.5 // Ausgang Daten Output
#pragma bit SDI @ PORTC.4 // Eingang Daten Input

Nicht vergessen, die Ein- / Ausgänge entsprechend einzustellen !

TRISC=0b.1101.0011; // SCK rc3-0, SDO rc5-0, CS rc2-0

Sie können natürlich jeden anderen Port und Pins nehmen !

Funktion char SPI(char d) ersetzen gegen:

char SPI(char out) // SPI-Softwaremäßig Frequenz etwa 620


kHz
{
char in,i;
for (i=0;i<8;i++)
{
nop2();
SCK=0; // Abfallende Flanke des Clocks
nop();
SDO=out.7; // Daten vorbereiten
nop();
out=out<<1;
nop2(); // Zeit lassen für
Datenvorbereitung bei Slave
in=in<<1;
SCK=1; // Steigende Flanke des Clocks
nop();
in.0=SDI; // Daten Einlesen
}
return in;
}

At lower clock frequencies the program works, only also more slowly. MMC
starts itself to attach: PIC16F870, PIC16F871, PIC16F872, PIC16F873,
PIC16F874, PIC16F876, PIC16F877, PIC16F84, PIC12F675, PIC12F629. Here
is a program for tests the software related MIRROR-IMAGE interface with
MMC. It is adapted for the PIC16F877, because I did not want to change the
hardware. Open questions: - MMC byte takes to the letter only blocks of 512,
where am I buffers? - as I can use FAT - table, in order to pick from a MMC
Kartenreader stored file out? On these questions I look for straight answer. If to
me somewhat occurs place I in the context of my web page here in here.
Buffers? One does not need, because one can transfer each byte with arbitrary
speed to the MMC, even 1 byte per hour. It is only stored only after 512 byte.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy