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

receive i2c data from pic16f887 to pc by rs232
Goto page Previous  1, 2, 3
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
temtronic



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

View user's profile Send private message

PostPosted: Thu Mar 15, 2012 5:39 am     Reply with quote

Electronics101...

From your picture, it appears you've connected the resistors in 'series' NOT in 'parallel'.
Consult any I2C device's datasheet to see how the I2C bus 'pullup' resistors are connected.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Mar 15, 2012 9:35 am     Reply with quote

Go to this page and scroll down to the photo for "Arduino and two-wire
interface":
http://nearfuturelaboratory.com/tag/diy/
There you will see two photos with an X,Y,Z board. These photos show
how to install pull-up resistors.

Notice in each photo, two wires are connected between the X,Y,Z board
and another board. These are the SCL and SDA connection wires.

Also each photo shows two resistors going from SCL and SDA to the
Vcc power bus. Power is marked with a red stripe on the breadboard.
In your case, Vcc = +5 volts.

That's how you're supposed to do it. I showed you this in the schematic
that I posted earlier.
Jampe



Joined: 09 Mar 2012
Posts: 27

View user's profile Send private message

PostPosted: Thu Mar 15, 2012 10:08 am     Reply with quote

Thank you all! it works!
temtronic, thanks for your explanation.
PCM programmer, your code is working! Thank you all for your help.
Thank you for your patience and rapidly responses!
The SRF08 sensor works!

I tried to change this code to my ADXL345 sensor I don't see anything..
It connected as "9 Degrees of Freedom - Sensor Stick" so I didn't use pull-up resistors (built-in).

http://www.sparkfun.com/products/10724

Code:

#include <i2c4.h>
#use i2c(Master, sda=PIN_C4, scl=PIN_C3)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

#define WRT_ADDR  0xA6
#define RD_ADDR   0xA7

int16 adxl345_get_data(void);

//=======================
void main()
{
int16 result;
while(1)
  {
   result = adxl345_get_data();
   printf("data = %lu\n\r", result);
   delay_ms(1000);
  }

}

//========================

int16 adxl345_get_data(void)
{
int8 lsb;
int8 msb;
int16 data;

i2c_start();
i2c_write(WRT_ADDR);
i2c_write(0);       
i2c_write(0x32);  // X-axis
i2c_stop();         

delay_ms(100);    // Waiting 100ms   

// Finally get the data from the ADXL345
i2c_start();
i2c_write(WRT_ADDR);
i2c_write(2);
i2c_start();   
i2c_write(RD_ADDR);
msb = i2c_read();   
lsb = i2c_read(0);
i2c_stop();

data = make16(msb, lsb);
return(data);
}


Thanks ,
Jampe.
jcal54321



Joined: 06 Mar 2009
Posts: 10
Location: Salinas, CA

View user's profile Send private message

I2C tester code from PCM Programmer works great!
PostPosted: Sat Jun 09, 2012 6:39 pm     Reply with quote

I just wanted to add that the I2C tester program posted here works great. I am using a PIC18F2520 and communicating with all three sensors on Sparkfun's 9DOF Stick (P/N SEN-10724).

Since my PIC is working with 5 VDC and the 9DOF Stick is working from 3.3 VDC, I had to use a TI P82B96 Dual Bidirectional Bus Buffer in between the two components. I connected the IC per Figure 2 of the P82B96 datasheet. Pins 1 and 7 connected directly to SDA and SCL of the 9DOF Stick. Pins 2 and 3, which are tied together as shown in Figure 2, are pulled up to 5 VDC through a 2.6K resistor and connected to SDA on the PIC. A similar configuration for pins 5 and 6 to SCL on the PIC.

Anyway, just wanted to post this, in case anyone will find it useful. The I2C tester code is a great place to start. Here is the output from the program received by Hyperterminal:

Code:
Start:
ACK addr: 3C
ACK addr: A6
ACK addr: D0

Number of i2c chips found: 3
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2, 3
Page 3 of 3

 
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