I2C vs. SPI
Philldapill
Posts: 1,283
I've got an accelerometer that can be used with an I2C interface, or and SPI interface. I am using a driver that was written by someone else(Tim Moore), and it uses I2C. It's very reliable, but boy is it slow... I can only get about 11 samples per second out of it. I need more like 100. So, naturally, I started looking through the code, trying to see if I could speed it up somehow. I went to the datasheet to look at the maximum clock freq, and it's only 100kHz??? From that, it looks like this is the standard freq. for I2C devices...
I then looked at the SPI clock protocal and did some research on SPI. It seems that I2C uses a bi-directional data stream on a single pin, while SPI uses dedicated MISO and MOSI pins for sending/recieving, so in theory, SPI should be twice as fast(so far). In addition to the dedicated lines, the clock speed for SPI on my accelerometer chip is 8MHz! Clearly, SPI seems to be the way to go.
Is there anything I'm missing in all of this? Is SPI more complicated? I understand that with I2C, you can "address" certain devices, al on the same SDA line, while with SPI you need a dedicated chip select line for each device. In my application, this really wouldn't be a problem using extra lines.
So, what should I use?
I then looked at the SPI clock protocal and did some research on SPI. It seems that I2C uses a bi-directional data stream on a single pin, while SPI uses dedicated MISO and MOSI pins for sending/recieving, so in theory, SPI should be twice as fast(so far). In addition to the dedicated lines, the clock speed for SPI on my accelerometer chip is 8MHz! Clearly, SPI seems to be the way to go.
Is there anything I'm missing in all of this? Is SPI more complicated? I understand that with I2C, you can "address" certain devices, al on the same SDA line, while with SPI you need a dedicated chip select line for each device. In my application, this really wouldn't be a problem using extra lines.
So, what should I use?
Comments
I find that SPI is just as easy to implement as I2C. I actually find it is easier, for the lack of device address.
I would go with SPI. It really is not hard to make a SPI driver for a chip. I'm not good with pasm, so I stick with Spin. I really need to learn pasm.
James L
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
James L
Partner/Designer
Lil Brother SMT Assembly Services
Leon
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Amateur radio callsign: G1HSM
Suzuki SV1000S motorcycle
If anyone wants to make an SPI driver for this accelerometer, I'll send you a couple to play with [noparse]:)[/noparse]
Normally I would take you up on the offer, but we are too busy to have any programming time. I don't know if SPI object in Spin would be a huge speed increase any how.
The economy has evidently caused a wave of people to flock to us for SMT assembly work.
James L
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
James L
Partner/Designer
Lil Brother SMT Assembly Services
We have had about 11 customers for the last year (truly active customers), funny that is all we could find. Now we have the previous eleven ordering like crazy and new customers signing on pretty frequently.
We aren't really paying for our equipment yet (so I wouldn't define it as thriving), but it does give us something to do. We are working on some of our own products to do in the thin times.
I actually just read (last day or so) a thread where you were talking about using a solder pot. We have considered through hole assembly a lot, but couldn't justify a wave. We could probably justify a solder pot. I appreciate the idea.
I just wish I could get one customers boards right. It is 80% 0402's and fine pitch QFN's (about 308 parts per board). The boards are some kind of transmitter, so they are very thermally stable (lots of thermal vias to copper pours). They are very difficult to get reflowed (contains a crystal which is very temperature sensitive). We are actually building a vapor phase system to conquer the issues with his boards. It will be a nice addition to our equipment as well (yes, it will be controlled with a Propeller). We are currently on try four with his assembly. He does understand the difficulty with the assembly, which makes for a good customer to do work for.
James L
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
James L
Partner/Designer
Lil Brother SMT Assembly Services