CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

SPI or I2C

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Newbie
Guest







SPI or I2C
PostPosted: Tue Dec 23, 2003 4:54 pm     Reply with quote

Hi,
looking at starting a project but want to keep it as flexible as possible.

What has the widest flexibility I2C or SPI by flexibility I mean most compatible support IC's.

And why the difference? why don't they just settle on one standard and stop confusing newbie's!

Thanks
Snoopy
Guest







PostPosted: Tue Dec 23, 2003 5:15 pm     Reply with quote

Spi is better.
Newbie
Guest







Hmmm can you expand?
PostPosted: Tue Dec 23, 2003 7:58 pm     Reply with quote

Title says it all, also can you mix SPI + IC2 on one chip?
snoopy
Guest







PostPosted: Wed Dec 24, 2003 9:40 am     Reply with quote

Probably yes

I have never did it.

But SPI and I2C use several same pin.

I expect it would be complicated to use both.
Charlie U



Joined: 09 Sep 2003
Posts: 183
Location: Somewhere under water in the Great Lakes

View user's profile Send private message

I2C or SPI
PostPosted: Wed Dec 24, 2003 9:59 am     Reply with quote

SPI is more straight forward (imho), in that it just clocks the data in and out. It requires more pins for a full interface: clock, data out, data in and chip select. To add more devices on the bus, additional chip selects are required.

I2C is a bit more complicated, but requires fewer pins. You can communicate with multiple devices just by changing the address bits in the I2C message.

SPI can be faster since some I2C devices are limited to 400kHz data rates and there can be less overhead with SPI protocols.

CCS has built in functions to read and write I2C and SPI. The SPI functions always use the hardware interface, but you could create your own functions to bit bang the interface. The I2C functions can use either hardware if the specified pins are the hardware pins, or the compiler will create a software I2C interface if the specified pins are not the hardware pins.

As an example, I have a project where 2 PIC processors communicate via the hardware SPI interface. One of them also requires a Real Time Clock and external memory. Since both of these devices had the same I2C address, I just used separate buses to communicate with them. Then used the built in functions in the compiler to create the soft interfaces to the devices.
kda406



Joined: 17 Sep 2003
Posts: 97
Location: Atlanta, GA, USA

View user's profile Send private message

PostPosted: Wed Dec 24, 2003 10:07 am     Reply with quote

I2C is far more flexible than SPI, but that does not mean it is better. I2C only uses 2 IO lines no matter how many devices you connect to the bus. This means you can add devices to an I2C bus without changing any hardware on the uC. This allows you to use uCs with fewer IO pins with a dynamic and robust bus. You could theoretically even have plug in modules that interface with the uC on an I2C bus, but that is another subject.

SPI on the other hand is much faster but at a cost of more IO pins. For 1 SPI device, you must use 3 IO pins. For any number "n" of SPI devices > 1, you must use n+3 IO lines on your processor (CLK, SPI, SPO, plus a CS for each SPI device). This means that if you chose to connect 5 SPI devices to your PIC, you'd use 8 IO lines Shocked compared to just 2 for I2C.

What you really need to consider is speed (SPI) versus IO (I2C). If you only plan to connect a single device to your PIC and your needs are slow, either one will work fine, and both are easy to use thanks to CCS. If you need to go fast, use SPI. If you are IO limited or need flexibility, use I2C. Hope this helps.
Gerd



Joined: 15 Dec 2003
Posts: 6

View user's profile Send private message

PostPosted: Wed Dec 24, 2003 2:19 pm     Reply with quote

Hi,

most things are said already.

I used SPI and I2C on PIC16F876.
For SPI I used the Hardware interface, PIN C3 - C5, For I2C I used two port B pins, if I remember correctly.

I2C can only be a master, if you don't use the Hareware interface! Exclamation


Quote:
What has the widest flexibility I2C or SPI by flexibility I mean most compatible support IC's.



Difficult to say in generall. Realy depents, what you want to do, for IO expantion, D/A, small memory IC's and so on, I2C is more common.
Whenever there are lots of data involved or on more special IC's, SPI is used.

Hope this helps.
[/quote]
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

PostPosted: Wed Dec 24, 2003 5:05 pm     Reply with quote

SPI can be opticaly isolated without any trouble. I2C can also be isolated but its more complicated because data goes both ways on a single line. Raw laitency with I2C is greater due to addressing and generaly runs a slower clock speed than SPI. SPI can run a lot faster but requires more signal lines. With I2C you have two signal lines; Data and Clock. With SPI you have MOSI (master out slave in), MISO (master in slave out), Clock and a SS (slave select) for each device on the bus.
Guest








PostPosted: Tue Jun 15, 2004 2:50 pm     Reply with quote

Anyone have any info on using software i2c on pins other than c3/sda and c4/scl?
lucky



Joined: 12 Sep 2003
Posts: 46
Location: South Coast - England

View user's profile Send private message Visit poster's website

Soft I2C
PostPosted: Wed Jun 16, 2004 2:15 am     Reply with quote

The compiler takes care of it for you. Just define differnt pins in the #use I2C directive & code as if using the H/W. The compiler will sort out the code behind the sceenes to bit-bang the pins.
_________________
Lucky
www.mpic3.com - MPIC3 player project, Forum, Downloads, Online Shop
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group