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 CCS Technical Support

I2C Question?

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



Joined: 27 Jul 2005
Posts: 1

View user's profile Send private message

I2C Question?
PostPosted: Fri Aug 12, 2005 7:41 am     Reply with quote

Does anybody know the difference between programing I2C using hardware and software?

I saw the following source code in this forum from Mark. It seem to me that if we use hardware then PIC handles every appropriate signal for us and it make programing a lot easier.

Then, Why we program PIC using I2C software?


Code:
*************************************************/
// Define this to use the hardware MSSP I2C module
//#define USE_HARDWARE
.
.
.
static I2C_RESULTS I2C_Write(
int8 data) // byte sent over the I2C
{
#ifdef USE_HARDWARE
SSPBUF = (data);
while (SSPSTATbits.BF)
{
#asm
nop
#endasm
}
.
.
.
#else
I2C_RESULTS value; // Value to be returned
int8 i; // Index to counter
int8 loop_count; // Clock stretch loop counter

I2C_CLK_LATCH=0;
I2C_DATA_LATCH=0;
for (i=0; i<8; i++)
{
.
.
.
[/code]
Ttelmah
Guest







PostPosted: Fri Aug 12, 2005 8:07 am     Reply with quote

Hardware is only available on the chips/pins, that support it. The hardware interface when present, may already be being used for something else. For example, I have a couple of PICs that use SPI to talk 'between themselves', and one also handles an I2C RTC chip. The software routines allow this to still be done.

Best Wishes
kender



Joined: 09 Aug 2004
Posts: 768
Location: Silicon Valley

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

PostPosted: Fri Aug 12, 2005 11:38 am     Reply with quote

Another couple of differences:

- Hardware I2C can have a faster bit rate
- Hardware I2C allows PIC to be an I2C slave
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Fri Aug 12, 2005 12:42 pm     Reply with quote

kender wrote:
Another couple of differences:

- Hardware I2C can have a faster bit rate
- Hardware I2C allows PIC to be an I2C slave


The code that he is referring to always uses the hardware slave. The earlier 16C76's (what I started with) didn't have firmware controlled master mode.
Joshua Lai



Joined: 19 Jul 2004
Posts: 42
Location: Malaysia, PJ

View user's profile Send private message Send e-mail

PostPosted: Sun Sep 25, 2005 8:06 pm     Reply with quote

Which is more reliable (less error)? Hardware or software?
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