SPI and I2C using same pins.

For general Flowcode discussion that does not belong in the other sections.
Post Reply
jay_dee
Posts: 198
http://meble-kuchenne.info.pl
Joined: Sun Dec 20, 2020 6:06 pm
Has thanked: 76 times
Been thanked: 54 times

SPI and I2C using same pins.

Post by jay_dee »

Hi,
Using a PIC18F2585.
The project is getting quite bust forthe little PIC, UART, CAN, i2C and SPI (MOSI only). Where possible i tend to use hardware periferals as I assume this is more robust/efficient for the PIC than bitbanging.

The i2C and SPI only share a common clock Pin. The SPI is to a display and currently only uses MOSI and not MISO. Which is good as the I2C Dat uses the pin shared with MISO.
I have 33ohm series resisistors and 3.5K pull-up on the i2C lines. Both i2C and SPI seem happy enough this this. The clock line at rest is pulled High. The display seems fine with this.

However I think I'm getting a clash somewhere, If I initialise the i2C anywhere in the flowcode the SPI display stops.
...I am toggle the SPI CS before and after the i2C. ! :)

Is there a straightforward way to get these two protocols to share the same pins or would it be simplier to just move one of them to Software bitbang version. If so which is best to move? Thanks, J.

jay_dee
Posts: 198
Joined: Sun Dec 20, 2020 6:06 pm
Has thanked: 76 times
Been thanked: 54 times

Re: SPI and I2C using same pins.

Post by jay_dee »

I just had a quick try with the I2C being bitbanged and repurposed a pin that was an unused LED. With this as Clock the i2C seems to work fine.
So maybe this is the easiest solution all round.

By retaining i2C dat on the MISO pin...is this likely to casue issues? Would it better all round to just move a software i2C out to two generic I/O pins?
One advantage is allowing a full MOSI MISO SPI but I doubt I will need that.
J.

Post Reply