| View previous topic :: View next topic | 
	
	
		| Author | Message | 
	
		| zeronix 
 
 
 Joined: 08 Jun 2010
 Posts: 9
 
 
 
			    
 
 | 
			
				| i2c Problem |  
				|  Posted: Sat Oct 16, 2010 6:48 pm |   |  
				| 
 |  
				| Hi Folks..   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
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Sat Oct 16, 2010 9:22 pm |   |  
				| 
 |  
				| 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
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Sat Oct 16, 2010 9:48 pm |   |  
				| 
 |  
				|  	  | 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
   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
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Sun Oct 17, 2010 9:38 pm |   |  
				| 
 |  
				|  	  | 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)
   
 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
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Sun Oct 17, 2010 10:10 pm |   |  
				| 
 |  
				| 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
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Mon Oct 18, 2010 8:59 am |   |  
				| 
 |  
				| 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: 1617
 Location: Central Illinois, USA
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Mon Oct 18, 2010 9:38 am |   |  
				| 
 |  
				| 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
 |  | 
	
		|  | 
	
		|  |