Home
People
Publications
Events
Teaching
Projects
Resources
Contact
Community
Blog






Work in Progress
Completed Work

:: Research Group Embedded Interaction :: Media Informatics :: Ludwig-Maximilians-University Munich


Particle MMC Card Reader

Please see our Particle How-To page and our Particle Software page as well.

Software SPI

The MultiMediaCard (MMC) is connected to the particle via a breakout board which makes every line of the conan inter-board connector accessible.

The MMC supports two different modes of data transmission:

  • SPI - Mode (used here)
  • MMC - Mode

The SPI (Serial Peripheral Interface) is an interfacespecfiction for synchron data transmission and reception simultaneously. In most cases three or four lines are needed (controller view):

  • Serial Data Out (SDO)
  • Serial Data In (SDI)
  • Serial Clock (SCK)
  • Slave Select (SS) or Chip Select (CS)

Despite the PIC18LF6720 controller on the Particle has such an interface built-in and there exist various convenient functions in the library of the CCS C-Compiler dealing with this issue, it is unfortunately not possible to use these amenities. The reason for this is the fact that the Hardware-SPI of the controller is one possible mode of the Master Synchronous Serial Port (MSSP) Module of the PIC. The other mode is I2C. These two modes are exclusively usable because they use the same pins and the MSSP can only operate in exactly one mode. On the particle, the MSSP is configured as an I2C-Interface due to the need of communicating with an external serial memory.
So the SPI-Mode has to be emulated by software and you are free to use any unused digital I/O-Ports of the controller. If you additionally want to connect a display to the same particle, it is necessary to use pin B1 to pin B4 of the controller.

ATTENTION!! If you use a display AND the MMC on the same particle, it is possible to connect ONLY ONE display, because the data lines of the other five displays are used as the SPI-connection to the MMC.

Voltage level need not to be adapted, because the MMC is driven at the same voltage as the particle computer.

Pinassigments (BB = Breakout-board)
Pin BB Fkt MMC Pin MMC Fkt PIC Pin PIC
1 VCC 4 -- --
2 GND 3 -- --
3 /CS 1 /CS B1
4 Data In 2 SDO B2
5 CLK 5 CLK B3
6 Data Out 7 SDI B4

Having connected the MMC correctly, you only have to call

mmc_init() to reset (not the data, the interface ;-)) and init the MMC correctly. You are now able to read and write blocks of 512 Bytes calling
mmc_read_block()

and

mmc_write_block().
(jump to top)

Software SPI - Measurements

Here are some printed oscilloscope screens of measurements taken during the reset and init as well as the startsequence of read and write. Following Measurements show the communication of the particle and the MMC using sofware-emulated SPI. The line "Data" corresponds to SDO of the PIC.
A commandsequence of the MMC in SPI-Mode used here consists of 6 Bytes:

  • 1st byte is the command
  • 2nd to 5th byte is additional data, e.g. addresses
  • 6th byte is a checksumbyte

Then the card needs normally one complete cycle (8 clocks) to process the command. It answers in the next clockcycle. Data on the lines SDO/SDI is accepted by the card/PIC with rising edge of the clock on the CLK-line.

  • Reset

    Here you can see the controller sending 0x40h (CMD0) followed by 4 bytes of 0x00h and finally 0x95h as checksumbyte. This is the only command which sends a correct checksum. After this command, the card does not check this last byte any more, so we will always send 0xFF as "checksum".
    The MMC acknowledges the command with response 0x01h.
    Reset is sent during mmc_init().

  • Init

    Controller sends 0x41h (CMD1) followed again by 4 bytes of 0x00h. The last byte is now the dummy checksum 0xFFh.
    The MMC answers positive with 0x00h.
    Init is sent during mmc_init().

  • Read

    Controller sends command 0x51h and 4 bytes of 0x00h. In these bytes the address is placed. It has to be a multiple of 512 (here, the first block an the card is addressed). The MMC acknowledges again with 0x00h.
    Now the particle has to wait for the beginning of the data the card will send back. For this purpose the controller has to keep on sending clocks until the Startbyte 0xFE and 512 bytes (the desired data) following it are received. You can see the startsequence of reading in the next picture:

  • Write

    Controller sends command 0x58h and 4 bytes 0x00h as the address. Here again, the address has to be a multiple of 512 and the card confirms with 0x00h.
    Now the controller starts putting 0xFEh and the following 512 byteblock on the serial line.

If you encounter problems concerning the communication, just take a single PIC with SPI and try to get the communication working with the built-in hardware-SPI of the controller. We have taken a few screenshots of the communication via the built-in interface which you can find here. You will also have to take a look at this document, if you want to examine the timing of the signals on the four lines more precisely.

(jump to top)

Software SPI - Files - Code and Headers

The Code for the communication will be placed here soon. We just have to make some modifications.

(jump to top)

Hardware SPI

The MultiMediaCard (MMC) is connencted to the PIC via four lines of the SPI described here You just have to look up in the datasheet the corresponding pins for your PIC. Before you can use the hardware interface, you have to configure the SPI of your PIC. You can use the function

setup_spi()

which is delivered with the CCSC-Compiler, but you additionally have to set two bits of the control registers SSPSTAT and SSPCON1 of your PIC. Look in the file mmc.c and there in mmc_init() to get the idea of managing this. Then you are able to communicate simply with the two functions spi_write() and spi_read().
If you use our code, you do not need to configure all this, you just have to set SPI_MODE to 0. Looking then like this:

#define SPI_MODE 0

Be careful with the voltage level!! If you supply your circuit with 5V you have to adapt the voltage, because MMCs like only 3,3V.

Having connected the MMC correctly, you only have to call

mmc_init() to reset (not the data, the interface ;-)) and init the MMC correctly. You are now able to read and write blocks of 512 Bytes calling
mmc_read_block()

and

mmc_write_block().
(jump to top)

Hardware SPI - Measurements

Here are some printed oscilloscope screens of measurements taken during the reset and init as well as the startsequence of read and write. Following measurements show the communication of a PIC and the MMC using the built-in SPI. The line "Data" corresponds to SDO of the PIC.
A commandsequence of the MMC in SPI-Mode used here consists of 6 Bytes:

  • 1st byte is the command
  • 2nd to 5th byte is additional data, e.g. addresses
  • 6th byte is a checksumbyte

Then the card needs normally one complete cycle (8 clocks) to process the command. It answers in the next clockcycle. Data on the lines SDO/SDI is accepted by the card/PIC with rising edge of the clock on the CLK-line made clear with the dashed line on the first picture.

  • Reset

    Here you can see the controller sending 0x40h (CMD0). This command is followed by 4 bytes of 0x00h (not shown here, but in the big version),

    and finally 0x95h as checksumbyte. This is the only command which sends a correct checksum. After this command, the card does not check this last byte any more, so we will always send 0xFF as "checksum".

    The MMC acknowledges the command with response 0x01h.
    Reset is sent during mmc_init().

  • Init

    Controller sends 0x41h (CMD1) followed again by 4 bytes of 0x00h.

    The last byte is now the dummy checksum 0xFFh.

    The MMC answers positive with 0x00h.
    Init is sent during mmc_init().

  • Write

    In order to get an idea how writing works just have a look at the big version of the measurement print.

If your problems are still not solved, or you have found a mistake or other hints you want to tell us, just contact us.

(jump to top)

Hardware SPI - Files - Code and Headers

The Code for the communication will be placed here soon. We just have to make some modifications.

(jump to top)

Files

References