View previous topic :: View next topic |
Author |
Message |
msa
Joined: 07 Apr 2010 Posts: 15
|
FORCE_HW & FORCE_SW |
Posted: Tue Apr 13, 2010 7:06 am |
|
|
Hi all
What difference between FORCE_HW and FORCE_SW when use #USE I2C.
thanks |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Apr 13, 2010 12:51 pm |
|
|
The CCS manual says:
Quote: |
#USE I2C
FORCE_HW Use hardware I2C functions.
FORCE_SW Use software I2C functions.
|
Hardware i2c is only available on specific pins on the PIC chip.
These pins are labeled SDA and SCL in the PIC data sheet.
The PIC must have an SSP (slave only) or MSSP module (master
and slave) to do hardware i2c. CCS does hardware i2c by talking
to the hardware i2c module registers in the PIC. The hardware
module handles controlling the i2c bus.
Software i2c is available on most i/o pins on the PIC.
CCS does software i2c by "bit banging" the i/o pins with code.
CCS controls the i2c bus directly with code. |
|
|
msa
Joined: 07 Apr 2010 Posts: 15
|
|
Posted: Tue Apr 13, 2010 1:13 pm |
|
|
Thank you for your answer.
with regards |
|
|
tim_sid
Joined: 11 Apr 2014 Posts: 16
|
|
Posted: Fri Apr 11, 2014 2:14 am |
|
|
so, for software I2C is simple ccs I2C_read() and I2c_write functions are enough or I need to use some library performing some bit banging? can I have some simple code or clue, Please? |
|
|
oxo
Joined: 13 Nov 2012 Posts: 219 Location: France
|
|
Posted: Fri Apr 11, 2014 5:01 am |
|
|
tim_sid wrote: | so, for software I2C is simple ccs I2C_read() and I2c_write functions are enough.....? |
Yes, you use i2c_read and i2c_write. Look in the help file |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Fri Apr 11, 2014 5:20 am |
|
|
Just one additional note: You didn't mention if you want to use it on a master or on a slave device. Software I2C on a master works great but don't try to use it on a slave. |
|
|
tim_sid
Joined: 11 Apr 2014 Posts: 16
|
|
Posted: Fri Apr 11, 2014 5:49 am |
|
|
Thank you so much for quick replies.
Ckielstra, I just need my PIC working in Master mode for writing to slave device. |
|
|
RoGuE_StreaK
Joined: 02 Feb 2010 Posts: 73
|
|
Posted: Mon Apr 14, 2014 7:37 pm |
|
|
Is it correct to say that hardware i2c (and PWM, and SPI etc) works independent of your other code, that once the command is given the hardware itself performs the task, freeing up the processor to do other things? Kind of like delegating a job to someone else, you can continue with more important tasks whilst they do the tedious repetitious stuff? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Tue Apr 15, 2014 12:27 am |
|
|
Yes.
However for I2C the difference is normally tiny. At 100KHz, it only takes 80uSec to send a byte. Using software I2C won't normally reach this rate (except on a fast PIC), but the actual time to send a byte is still small.
Different from RS232 where byte times are often several mSec.
Best Wishes |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1354
|
|
Posted: Tue Apr 15, 2014 8:50 am |
|
|
Note that however, while hardware does work independently of software in general, you still have to consider driver and built in function implementations. Some of those will loop infinitely waiting for a hardware flag to set before moving on. For example, if you use putc or printf to print to a hardware UART, it will wait until the buffer has room before adding the next character to the outgoing buffer. Using getc will wait until there is a character before moving on.
You can get around these limitations in various ways:
1. Some peripherals have built in support functions or parameters for avoiding those delays
2. Some peripherals can be implemented using interrupts to get around this (usually with extra code from you)
3. You can write your own drivers or peripheral functions to use instead. |
|
|
|