|
|
View previous topic :: View next topic |
Author |
Message |
temtronic
Joined: 01 Jul 2010 Posts: 9224 Location: Greensville,Ontario
|
|
Posted: Thu Mar 15, 2012 5:39 am |
|
|
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
|
|
Posted: Thu Mar 15, 2012 9:35 am |
|
|
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
|
|
Posted: Thu Mar 15, 2012 10:08 am |
|
|
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
|
I2C tester code from PCM Programmer works great! |
Posted: Sat Jun 09, 2012 6:39 pm |
|
|
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 |
|
|
|
|
|
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
|