Information Technology Reference
In-Depth Information
data_response token, or the host has sent a Stop Tran data token instead of a
data block.
The host can check the result of a write operation by sending CMD13
(SEND_STATUS). The card returns a response that contains the status
information.
Application Example
The example that follows uses the Microchip PIC18F4550 microcontroller
circuit introduced in Chapter 4. The code shows how to detect a MultiMe-
diaCard, initialize communications, and read and write data in the card's
storage media.
Detecting and Selecting a Card
As the circuit in Chapter 4 showed, firmware can use spare port bits to con-
trol a MultiMediaCard's CS input and monitor a card connector's
card-detect (CD) and write-protect (WP) pins. The host brings CS low to
enable communications in SPI mode. The card-detect and write-protect
pins connect to switches in the card connector, with one switch terminal
connected to the ground pin and the other terminal brought out to the CD
or WP connector pin. The card-detect switch is open when no card is
present and closed when a card is present. The write-protect switch is open
if the card's write-protect tab is in the write-protect position or the card isn't
present. The switch is closed if the tab is in the write-enable position or the
card doesn't have a write-protect tab. Only full-size SD Cards have
write-protect tabs, though full-size adapters with tabs enable other card
types to provide a write-protect signal.
Hirose DM1 series sockets are an example of SD-Card/MultiMediaCard
sockets that have card-detect and write-protect switches. To monitor the
state of a switch, connect it to a port pin with a pull up. The port pin is high
when the switch is open and low when the switch is closed.
On the PIC18F4550, each I/O port has three registers. A TRIS register sets
the direction of the port's bits (0 = output, 1 = input). Firmware can use the
Port and LAT registers to read and write to the port. Reading the Port regis-
ter returns the current state of the port's pins. Firmware can write to the port
Search WWH ::




Custom Search