# I2C-to-SPI bridge and SD card

I am using a PIC18F25k80 microprocessor, which is communicating by using I2C protocol with peripheral ICs. After collecting the data from the ICs I want to store them in an SD card. However for the SD card I need to transfer the data by using an SPI protocol, since it cannot operate with a low data transfer protocol. For that reason I put an I2c-to-SPI bridge (SC18IS602BIPW) on the bus. By writing the address of the interface bridge, followed by a 0 (control bit / write), on the I2C bus you can communicate with it. After the address a predefined function needs to follow (the functions are explained inside the datasheet) and then a series of data, which can be 0-200 bytes long. The data is stored in a buffer inside the interface bridge chip and then are automatically sent over SPI to a device. The predefined function determined the chip select bit and thus, the device with which the bridge is communicating.

I want to initialise a file system on the SD card, so that I can create files where my data is going to be stored. How can I use the function inside the FSIO.h in order to do that. Do I need to send the functions over the bus to the SD card and if yes how can I do that?

Interface Bridge datasheet: http://www.nxp.com/documents/data_sheet/SC18IS602B.pdf

You will struggle to make this system work. An SD card offers a block-structured file system, which requires writes of full blocks of at least 512 bytes. Your bridge only supports 200-byte blocks.

Also the slow speed of I²C will give you trouble. Transferring 512 bytes over the 400 kbit/s I²C link will take approximately 10 ms.

Finally, you will need to write a software driver layer to drive the SD card through the bridge. This will take a lot of effort.

I notice the PPC18F2580 has an SPI interface. You should use the SPI interface to talk to the SD card and use the I²C interface to talk to the sensors. There should not be a need for the bridge.

• So do you mean that I can re-use the line for data and clock for the SPI as well? – user2344158 Jun 19 '15 at 11:47
• I've shared pins between I2C and a UART on a PIC12F, so it could be possible for you to share between I2C & SPI. But it depends on your circuit & peripherals. – brhans Jun 19 '15 at 12:04
• Not possible with SD card SPI at reasonable speeds. You want some MHz there, e.g. for finding the next free block in the FAT. – Turbo J Jun 19 '15 at 17:37
• Note that the SPI master required to talk to an SD card is relativly simple to implement in software, so you don't need hardware SPI, only 4 GPIOs. – Turbo J Jun 19 '15 at 17:45
• What if I shared the clock and data lines between I2C and SPI and do the following: OpenI2C(parameters); . . . CloseI2C(); OpenSPI(parameters); . . . CloseSPI(); Is this still not going to work? – user2344158 Jun 20 '15 at 10:38