Take the 2-minute tour ×
Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering professionals, students, and enthusiasts. It's 100% free, no registration required.

Im new to Microchip microcontrollers and I'm looking for very low cost device with I2C and SPI. I want to connect one I2C (ADC) and one SPI device (LCD).

I found this very low cost device:

enter image description here

However it looks like I2C and SPI share same hardware.

Question: Can I use hardware I2C and SPI in one circuit?

share|improve this question

3 Answers 3

up vote 4 down vote accepted

I agree with @Olin's post. At the same time, there's another point of view on which I2C or SPI to implement in software and which in hardware.

I2C bus has a lower top speed than SPI. Typical I2C bus has a max data rate of 400 kbps **. Typical SPI can easily run at 4 Mbps. Some applications require high speed transfer over SPI. For example: SD cards, radio comms. A bit-banged SPI would be too slow. As a result, the SPI would have to be implemented with hardware MSSP, and the slower I2C would be implemented in software.

Sometimes the speed is not important. For example, a bus slave generates data slowly, so the bus speed is not the limiting factor.

** There are high speed versions of I2C, but they are note very common at the moment of writing.

share|improve this answer
    
I changed my accepted answer. I think bit banging SPI will take too much cpu time in my case - I have a lot of data to send over SPI (504 bytes at least few times per second), and little data rate on I2C (slow ADC) –  Kamil Apr 29 at 11:11

Yes, you can use this part to drive both a IIC bus and a SPI bus in the same circuit. However, you can't (reasonably) use the single MSSP module of this device to drive both busses.

My recommended solution is to use the MSSP to do IIC and do the SPI by firmware bit-banging of separate I/O pins. SPI is a very easy protocol to implement when you are the master, which it appears you are. Since the master owns the clock, there is no problem if your SPI code gets interrupted and arbitrary delays inserted thereby. Take a look at how SPI works. It really is very simple and easy to implement directly in firmware.

You could of course do the IIC in firmware and let the MSSP manage the SPI bus. I have written both, and SPI is easier to do in firmware than IIC, so I'd let the MSSP take care of IIC. IIC isn't hard, but it is a little more tricky to do robustly.

share|improve this answer

Although in the paragraph you emphasized, they use the word and:

The MSSP module can operate in one of two modes:

  • Serial Peripheral Interface (SPI)
  • Inter-Integrated Circuit (I2C™)

Datasheet, page 164.

But you can software implement the I2C protocol on other pins.

However:

You can normally mix I2C and SPI on the same pins. I2C only does something between START and STOP.

According to http://www.i2cchip.com/mix_spi_i2c.html

Also check this: I2C and SPI ,if they share same connection , is there confilict or not

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.