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 or RS232

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







I2C or RS232
PostPosted: Thu Jul 23, 2009 5:15 pm     Reply with quote

Hello,
I need to send a float from a PIC16F88 to a PIC16F876 as fast as possible. I’m using CCS IDE. Do someone knows if it is better to use I2C or RS232. I have never used any of those two before, but I’ve read that with RS232 protocol we can send packages of 8 bits and I need to send a float, so 16 bits.
I will appreciate if someone can help me with this subject.
Francisco
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jul 23, 2009 5:29 pm     Reply with quote

Quote:
I need to send a float, so 16 bits.

A floating point number is 4 bytes:
http://www.ccsinfo.com/forum/viewtopic.php?t=23886&start=25
Ttelmah
Guest







PostPosted: Fri Jul 24, 2009 2:32 am     Reply with quote

Beyond the comment about the number of bytes, the answer 'depends'.
What is the distance between the chips?.
What is the environment?.

So (for example),the answer will differ for a situation where the chips are on separate boards, a few feet apart, on separate boards in the same enclosure, on separate boards many feet apart, or on the same board.

The fastest is SPI. Really only useable on the same board, or where the boards are close together, with you able to closely define the impedance of the lines between the pns, and shield/terminate these properly.

Then I2C, for slightly longer distances, but with a little more 'relaxed' signalling specs. You can add high voltage buffers to give longer distances, and better noise immunity.

Between these, comes RS485 - not RS232. Speed up with SPI, and with careful line design, and termination, long distances. Speed will drop for longer links. Downside of this, is that you have to add buffers at both ends. This gives speed up with SPI, with good noise immunity. I have a system using this at 1Mbps, with 400feet of cable length. The 'rule of thumb', for this, is line length (in feet), times data rate (bps), should be less that 10^7, and with good design, even this can be 'pushed'.

RS232, is relatively slow, with allowable speeds falling fast with distance, but has quite good noise immunity, and works over a variety of cabling.

If your two chips are on the same board, go SPI. If they are in separate boxes, and you want speed, go RS485.

It'll take you longer to actually read the data, and put the bytes back together, than the links will take to transfer it. With SPI, between two chips on the same board, both running at 25MHz, you can send the four bytes, in just over 5uSec, but the code around this, will probably add a factor of at least 20* to this....

Best Wishes
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Fri Jul 24, 2009 8:54 am     Reply with quote

Ttelmah wrote:
Beyond the comment about the number of bytes, the answer 'depends'.
What is the distance between the chips?.
What is the environment?.

So (for example),the answer will differ for a situation where the chips are on separate boards, a few feet apart, on separate boards in the same enclosure, on separate boards many feet apart, or on the same board.

The fastest is SPI. Really only useable on the same board, or where the boards are close together, with you able to closely define the impedance of the lines between the pns, and shield/terminate these properly.

Then I2C, for slightly longer distances, but with a little more 'relaxed' signalling specs. You can add high voltage buffers to give longer distances, and better noise immunity.

Between these, comes RS485 - not RS232. Speed up with SPI, and with careful line design, and termination, long distances. Speed will drop for longer links. Downside of this, is that you have to add buffers at both ends. This gives speed up with SPI, with good noise immunity. I have a system using this at 1Mbps, with 400feet of cable length. The 'rule of thumb', for this, is line length (in feet), times data rate (bps), should be less that 10^7, and with good design, even this can be 'pushed'.

RS232, is relatively slow, with allowable speeds falling fast with distance, but has quite good noise immunity, and works over a variety of cabling.

If your two chips are on the same board, go SPI. If they are in separate boxes, and you want speed, go RS485.

It'll take you longer to actually read the data, and put the bytes back together, than the links will take to transfer it. With SPI, between two chips on the same board, both running at 25MHz, you can send the four bytes, in just over 5uSec, but the code around this, will probably add a factor of at least 20* to this....


Actually, if you used fiber-optic transmission with the fun products from
http://www.i-fiberoptics.com/Fiber_optic_led_photodetectors.php and the easy to handle cut-with-a-knife 1000uM plastic fiber, you could easily make SPI go a lot further... and SPI'd unidirection signals lend easier to doing this than I2C (although I2C has advantages of addressing in the protocol).

Although, I did make an adapter that would let I2C work with the i-fiber products too.

Just thought I would mention it --- but SPI is definitely the fastest with I2C coming in next followed by the rest as described above.

-Ben

p.s. You should really read up on RS232 and I2C (and SPI for that matter) to really understand the differences... it's the only way you'll truly understand which is best to use outside relying on us nutbuckets to tell you. ;)
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
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