Efteruddannelse Embedded C Modul 5 (Fredag den 15/1-2010)
Modul 1 1)SPI protokollen 2)SD Card 1)Korttyper 2)Features 3)Interface 4)Opbygning og interne registre 5)Kommunikationsprotokol 3)Funktioner med variabelt antal parametre 4)Afrunding og evaluering
SPI kommunikation
Master og slave
Puls plan
SPI kontrol register i PIC
Kontrolregister til SPI modul i PIC
SD Card
SD Card typer SD Card mini SD micro SD SDHC mini SDHC micro SDHC SDXC
SDCard kapacitet og spænding TypeKapacitetSpænding SD0 – 2GB2,7 - 3,6V SDHC4GB – 32GB2,7 – 3,6V SDXC32GB – 2 TB2,7 – 3,6V
SDIO enheder
SDCARD Features •Targeted for portable and stationary applications • Memory capacity: Standard Capacity SD Memory Card: Up to and including 2 GB High Capacity SD Memory Card: More than 2GB (This version of specification limits capacity up to and including 32GB) •Voltage range: High Voltage SD Memory Card – Operating voltage range: V Dual Voltage SD Memory Card – Operating voltage range: Low Voltage Range (T.B.D) and V •Designed for read-only and read/write cards. •Default mode: Variable clock rate MHz, up to 12.5 MB/sec interface speed (using 4 parallel data lines) •High-Speed mode: Variable clock rate MHz, up to 25 MB/sec interface speed (using 4 parallel data lines)
SDCard Features •Correction of memory field errors •Card removal during read operation will never harm the content •Content Protection Mechanism - Complies with highest security of SDMI standard. •Password Protection of cards (CMD42 - LOCK_UNLOCK) •Write Protect feature using mechanical switch •Built-in write protection features (permanent and temporary) •Card Detection (Insertion/Removal) •Application specific commands •Comfortable erase mechanism
SDCARD Feautures • Protocol attributes of the communication channel: • SD Memory Card Communication Channel Six-wire communication channel (clock, command, 4 data lines) Error-protected data transfer Single or Multiple block oriented data transfer • SD Memory Card Form-factor •Standard Size SD Memory Card: Specified in this specification (See Chapter 6 and 8) • miniSD Memory Card: Specified in “miniSD Memory Card Specification” • microSD Memory Card: Specified in “microSD Memory Card Specification” •Standard Size SD Memory Card thickness is defined as both 2.1 mm (normal) and 1.4 mm (Thin SD Memory Card).
Compabilitet SD vs SDHC
SPEED Class •Four Speed Classes are defined and indicate minimum performance of the cards •Class 0 - These class cards do not specify performance. It includes all the legacy cards prior to this specification, regardless of its performance •Class 2 - Are more than or equal to 2 MB/sec performance. •Class 4 - Are more than or equal to 4 MB/sec performance. •Class 6 - Are more than or equal to 6 MB/sec performance. •High Capacity SD Memory Cards shall support Speed Class Specification and have performance more than or equal to Class 2. •Note that the unit of performance [MB/sec] indicates 1000x1000 [Byte/sec] while the unit of data size [MB] indicates 1024x1024 [Byte]. This is because the maximum SD Bus speed is specified by the maximum SD clock frequency (25 [MB/sec] = [Byte/sec] at 50 MHz) and data size is based on memory boundary (power of 2).
Speed Class
Overordnet Blokdiagram
SD card Arkitektur
Interface
Pinout i SD Bus mode
Pinout i SPI bus mode
Opkobling på udviklings board
Interne SD card registre
OCR (Operating Conditions Register)
OCR’Struktur
Card Identification Register (CID)
Card Specific Data
CSD
SD Card Configuration Register
Kommando’er •Der er forskel på om man tilgår SD card i SD mode eller i SPI mode som det kan ses i specifikationen er der en del kommendor der ikke findes i SPI mode. •Se i filen :..\..\Datasheet\ProdManualSDCardv1.9.pdf
SD Bus kommunikations mode
SPI mode
Multi block read
SPI mode
Multi block write mode
SPI mode
Command tokens Sendes på den 1 bits commando linie, derfor start og stop bit. Eller
Format af response token Der findes 4 forskellige type R1, R3, R6 og R2. Der findes 2 forskellige størrelser 48 bits – R1, R3 og R6 136 bits – R2
Format af commandoer
Formater for datapakker
Datapakke format
Card state
Card Indefication mode
Setup i SD mode
Data Transfer mode
Øvelse 1)Gennemgå funktionen MDD_SDSPI_MediaInitialize i eksemplet : USB-MSD-SPCard reader Tegn et diagram i stil med ”Setup i SD mode” der viser, hvordan kortet er sat op. 2) (extra opgave) Modificer koden i USB-MSD-SPCard reader, så data fra accerometer gemmes i en fil på kortet.
Funktioner i C med ”variabelt” antal parametre •I nogen situationer er det smart, at kunne kalde en funktion med forskellige antal parametre tænk f.ek på printf, i de objekt orienterede sprog klares dette via overloadning, men det er også muligt i c, blot er det lidt mere besværlig. •I C er det muligt at definere en funktion, som vist nedenfor: int minFunktion(…) { …. Det betyder at man kan have variabelt antal input
Eksempel
Opsummering 1)Opsummering 2)Evaluering 3)Tak for denne gang