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

baud rate i2c software

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



Joined: 19 Dec 2014
Posts: 16

View user's profile Send private message

baud rate i2c software
PostPosted: Fri Dec 19, 2014 4:45 am     Reply with quote

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 Smile
temtronic



Joined: 01 Jul 2010
Posts: 9163
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Dec 19, 2014 6:14 am     Reply with quote

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: 19339

View user's profile Send private message

PostPosted: Fri Dec 19, 2014 8:28 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Dec 19, 2014 9:24 am     Reply with quote

thank you all! Smile
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