View previous topic :: View next topic |
Author |
Message |
valex
Joined: 27 Jul 2005 Posts: 1
|
I2C Question? |
Posted: Fri Aug 12, 2005 7:41 am |
|
|
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
|
|
Posted: Fri Aug 12, 2005 8:07 am |
|
|
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
|
|
Posted: Fri Aug 12, 2005 11:38 am |
|
|
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
|
|
Posted: Fri Aug 12, 2005 12:42 pm |
|
|
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
|
|
Posted: Sun Sep 25, 2005 8:06 pm |
|
|
Which is more reliable (less error)? Hardware or software? |
|
|
|