View previous topic :: View next topic |
Author |
Message |
id31
Joined: 19 Dec 2014 Posts: 16
|
baud rate i2c software |
Posted: Fri Dec 19, 2014 4:45 am |
|
|
hi all
i would like to ask a question please. sorry about my english by the way...
i use pic16 (16MHz CLK) at my final project and i config the i2c with #use i2c.... FAST=400000. when i check the i2c SCL line (2.2Kohm pull up resistors) i see at the scope ~122Khz instead of 400KHz.
when i looked at your forum and others i saw the force hw section.. so i read and tried it ant it actually works!!
so please mates i am sorry about my questions, but i will appreciate if somebody who know will answer:
1. i would to understand the difference between hw and sw
2. WHY i cannot use 400KHz at software and what i should do to be able use 400Khz without force HW
*i read topics and no place say what i should do to get 400k at hw..
THANK YOU FRIENDS |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Fri Dec 19, 2014 6:14 am |
|
|
I think it's because the hardware I2C can go fast (400Khz) but software I2C requires a LOT of code to 'emulate' the features/functions of a hardware I2C device so the PIC has a lot to do and must be slower.
If possible it's always better to use the internal I2C hardware, even if you use 'slow' devices.
others may give a better reply...
hth
jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19498
|
|
Posted: Fri Dec 19, 2014 8:28 am |
|
|
Temtronic is spot on.
At 16MHz, your chip is executing just 4MIPS. For a 400KHz signal, each half cycle is just 1.2uSec long. Software I2C, requires shifting each bit in turn out of the byte, outputting this on the pin and repeating this for each bit in the byte. It takes about 15 or 16 machine instructions for each bit half cycle.
That's the whole reason the hardware is there. The code using it takes less space, and is faster.
The reason the software I2C is there, is for chips that don't have hardware, or to allow multiple I2C ports to be done where a lot of devices are needed. Otherwise always use the hardware.
The software can't be made faster. |
|
|
id31
Joined: 19 Dec 2014 Posts: 16
|
|
Posted: Fri Dec 19, 2014 9:24 am |
|
|
thank you all! |
|
|
|