cancel
Showing results for 
Search instead for 
Did you mean: 

How can i bit bang I2c and SPI?

Apill
Senior

I need to bit bang I2c and SPI, I have tried to look for application notes but couldnt find! could some one help me with this information or provide me some insights!

5 REPLIES 5
S.Ma
Principal

I've shared a non-clock stretching SW I2C Single Master implementation by GPIOs on this forum.

SPI for LCD displays too can be implemented by SW as long as the speed is non critical.

You're driving GPIO pins up an down, in a way that conforms with the waveforms described in the data sheet for the I2C/SPI part you're wanting to communicate with, and reading back data on other GPIO pins.

It's pretty basic stuff, not sure it necessitates a 12-step program

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
S.Ma
Principal

Well in this case, at list make it rugged: before generating the start bit, if SDA is low, blindly send 9 stop bits.

Try without it and inject glitch or get through a connector and feel the difference.

If you only followed the spec, you are not done yet with the real world.

UM10204 - 2C-bus specification and user manual

3.1.16 Bus clear

If the data line (SDA) is stuck LOW, the master should send nine clock pulses. The device that held the bus LOW should release it sometime within those nine clocks. If not, then use the HW reset or cycle power to clear the bus.

S.Ma
Principal

Implementing bus error recovery is a good practice:

If you only followed the spec, you are not done yet with the real world.

If you want to maximize profit, you need to keep customer returns to a minimum (except if it was a gift which it converted back to cash with gift receipt).

For this, you need to make sure (like a plug test) that your device works in real world with most implementation. Take USB. If your device is spec certified but there is a cheap popular crappy cable out there, you maybe compelled to try to be compatible with that non spec compliant cable, hence improving your device first hand experience with customer, which might boost your brand vs others.

It's the same with phones and carriers, all are 4G but what you want is best connectivity where you go.