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

i2c Problem

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



Joined: 08 Jun 2010
Posts: 9

View user's profile Send private message

i2c Problem
PostPosted: Sat Oct 16, 2010 6:48 pm     Reply with quote

Hi Folks.. Smile
I'm working on a project that uses an accelerometer with i2c communication.
The Accelerometer works well with a 1,5meters cable (rs482 multifillar cable).
Recently I bought an 4meter IDC cable to substitute the old one. I can't communicate with accelerometer with the new one!
Any suggestions/tips to increase communication distance on i2c ?
I have tried increase and decrease the pull up resistance and used fast/standard without sauces!

Regards,
José
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Oct 16, 2010 9:22 pm     Reply with quote

Use stronger pull-ups (1.6K for a +5v system). Slow down the baud rate.
Try using less than a 50 KHz baud rate. Try using software i2c (no
"Force_hw" parameter in #use i2c).
zeronix



Joined: 08 Jun 2010
Posts: 9

View user's profile Send private message

PostPosted: Sat Oct 16, 2010 9:48 pm     Reply with quote

PCM programmer wrote:
Use stronger pull-ups (1.6K for a +5v system). Slow down the baud rate.
Try using less than a 50 KHz baud rate. Try using software i2c (no
"Force_hw" parameter in #use i2c).

Hi thks for response.
I already try 1k, 2.2k , 8.x k , 20.xk and with 0k :=) with no result!
I will try tomorrow slow down like you said Smile
Where in the #use i2c i change the speed of communication?

My code :
Code:
#include <18f2550.h>
 
#fuses HSPLL,NOWDT,NOBROWNOUT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN,MCLR,NOPBADEN,WRTB,CPB

#use delay(clock=48000000)


#define Device_SDA PIN_B0 // Pin defines i2c serial data e serial clock
#define Device_SCL PIN_B1
 
#use i2c( master,fast, sda=PIN_B0, scl=PIN_B1)  // Configure Device as Master i2c fast mode

Regards,
zeronix



Joined: 08 Jun 2010
Posts: 9

View user's profile Send private message

PostPosted: Sun Oct 17, 2010 9:38 pm     Reply with quote

PCM programmer wrote:
Use stronger pull-ups (1.6K for a +5v system). Slow down the baud rate.
Try using less than a 50 KHz baud rate. Try using software i2c (no
"Force_hw" parameter in #use i2c).


Hi again,
I tried all day to put the i2c cable to work but without success.
I use the parameter that you recommend but without success.
Close the board works perfectly but with my 4m idc cable don't work at all :( (Probably I have to buy a better cable, I didn´t know of that this limitation on cable length in i2c) Smile

I use that code:
Code:
#use i2c( master,sda=PIN_B0, scl=PIN_B1,slow, FORCE_HW) 

It is possible to slow I2C baudrate giving for example in slow a parameter like slow= 10000?
Sorry to bother you.
Regards,
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Oct 17, 2010 10:10 pm     Reply with quote

Use software i2c and slow it down. Example:
Code:

#use i2c(master, sda=PIN_B0, scl=PIN_B1, slow=40000) 
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Mon Oct 18, 2010 8:59 am     Reply with quote

I had a similar problem with a long distance and I needed to abandon using the built in functions and had to bit-bang the I2C bus. It took a bit of work controlling the tris so I didn't get erroneous spikes on the bus but I have one working at 32 feet.

Ronald
bkamen



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

View user's profile Send private message

PostPosted: Mon Oct 18, 2010 9:38 am     Reply with quote

Make sure you have the I2C Specs (if I haven't mentioned it already) -- I have a copy (albeit old, but I think current) here: http://www.benjammin.net/~bkamen/pdf/i2c-specification-v2.1-jan2000.pdf

While there isn't a max length spec, longer cables/lines will lead to changes in transmission characteristics that alter timing -- and that is critical (and mentioned in the PDF).

Cheers,

-Ben
_________________
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