Communicating with SDcard via I2C

The Arduino SDcard library uses SPI. I actually prefer I2C because fewer pins are used. Is there a reason why SPI and not I2C is used by Arduino?

SD cards use SPI interface with clock, data-in, data-out, and chip select.
SD cards are not slow I2C interface devices.

CrossRoads:
SD cards use SPI interface with clock, data-in, data-out, and chip select.
SD cards are not slow I2C interface devices.

So, the reason SPI is used is that SPI is faster than I2C. No wonder it is so hard to find SDcard that uses i2c interface

SPI is used because the 4-pin interface is what is defined for an SD card standard.
SPI being fast is the best way to connect. One could also use shiftIn() & shiftOut() commands, would just be a lot slower.

I'm sure you could make an I2C to SPI adapter - monitor the bus for an address that corresponds to the card, switch the data line back & forth between input & output, drive the acknowledge bit, add open drain driver, etc.

Scroll down to Transfer Mode.

There is a one-bit bus mode, but it will be slower.

Hi!

I'm looking too for a solution to use SD Card with I2C not SPI, My SPI port is used by another device ::slight_smile:

axxel:
My SPI port is used by another device ::slight_smile:

I thought one could use more than one SPI device by using the SS?

The man page says:

SS (Slave Select) - the pin on each device that the master can use to enable and disable specific devices.
When a device's Slave Select pin is low, it communicates with the master. When it's high, it ignores the master. This allows you to have multiple SPI devices sharing the same MISO, MOSI, and CLK lines.

There is not a reasonable way to use an SD with I2C since SD cards are SPI devices and require direct access by the CPU.

Why can't you share the SPI bus? This is the best solution and many people use two or more devices on the SPI bus. For example, the Arduino Ethernet shield uses SPI for an SD and the Ethernet.

You can use other pins with Software SPI if it is impossible to share the SPI bus.

Here is an example SoftwareSPI

You can define these pins to be any unused pins.

// Pin numbers in templates must be constants.
const uint8_t SOFT_MISO_PIN = 12;
const uint8_t SOFT_MOSI_PIN = 11;
const uint8_t SOFT_SCK_PIN = 13;
//
// Chip select may be constant or RAM variable.
const uint8_t SD_CHIP_SELECT_PIN = 10;

I wonder if this ever took off: the announcement is 3 years old..... I2C microSD "disk drive".

There have been lots of projects like I2SD. Some use serial some I2C. Most, like I2SD use a 328 connected to the SD and communicate higher level file commands to the Arduino.

I2CSD just uses SD.h on the 328 board. Its API has a message to open a file, read bytes from a file, write bytes to a file, and seek to some position.

Lot of users have done the same thing with SdFat or SD.h and a second Arduino.

The I2SD code is here so you could buy something like a Pro Mini and a micro SD module and make your own. The code is very simple.

I2C on Arduino is very limited, the buffer in Wire is 32 bytes so I2SD has warnings like this:

Long reads happen most efficiently if the reads occur in blocks of size
I2C_BUFFER_LEN - 1: 31. If not, a seek is preformed to realign the SD
file back to what will be expected. This results in a loss of efficiency
for two reasons:

  1. a seek uses the bus
  2. data is always sent from I2SD_Slave in 32 byte chunks.
    (save one byte for I2SD_READ_MSG: 32 = 1 + 31)

i want to add an SDcard for data logging my application but i'm using all the digital pins for driving servos

is there any way around this problem? i see the SCcard reader takes 4 digital pins. i'm not really using any analog pins(except 4 and 5 for i2c), can they help?

i'm running on a Nano

also, why when i search on ebay for 'arduino micro sd card reader' i only see the giant full size card readers. does no one make a micro one? i have size and weight issues to deal with too.

thanks

Pins A0 - A5 may be used as normal digital pins.