View previous topic :: View next topic |
Author |
Message |
andys
Joined: 23 Oct 2006 Posts: 175
|
mpu6050 problems |
Posted: Sun Dec 30, 2012 6:47 pm |
|
|
I tried to use the mpu6050 module.
I am able to read a value from the sensor
with this line (i read the x access of the module )
xacc=i2c_read(0);
but my question is how to read the others values (for the others axes)?? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Mon Dec 31, 2012 9:03 am |
|
|
I don't have that module or the datasheet, however quick answer is to read the datasheet and see what registers on the device are the y and z axis data.
If you look at the DS1307 RTC driver(or some similar I2C device ...), it'll show you the 'layout' and how to access registers within an I2C device.
hth
jay |
|
|
deperkin
Joined: 04 Feb 2009 Posts: 83 Location: PA
|
|
Posted: Mon Dec 31, 2012 9:27 am |
|
|
On pages 6-8 of the datasheet you have the register maps.
the accelerations, temps, and gyro data are on addresses 0x3B through 0x48.
You can also do burst FIFO with this.. it all depends on which mode you are in.
I would just suggest to read the datasheet carefully... then re-read it... then read it again. |
|
|
andys
Joined: 23 Oct 2006 Posts: 175
|
mpu6050 problems |
Posted: Tue Jan 01, 2013 11:50 am |
|
|
i tried the following code without success , how to modify it ?
Code: |
while(1)
{
///////////////////////////////////////////////////////
i2c_start();
i2c_write(0xd0);
i2c_write(0x3b);
i2c_start();
i2c_write(0xd1);
xacc=i2c_read(0);
printf("xacc:%fl:\n",xacc);
delay_ms(300);
//output_high(PIN_A0);
i2c_stop();
i2c_stop();
/////////////////////////////////////////////////////////////////
i2c_start();
i2c_write(0x0E);
i2c_write(0x3d);
i2c_start();
i2c_write(0xd1);
yacc=i2c_read(0);
printf("yacc:%fl:\n",yacc);
delay_ms(300);
//output_high(PIN_A0);
i2c_stop();
i2c_stop();
}
|
|
|
|
andys
Joined: 23 Oct 2006 Posts: 175
|
mpu6050 problems |
Posted: Tue Jan 01, 2013 8:45 pm |
|
|
IS there someone who can help me?????? |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Wed Jan 02, 2013 7:25 am |
|
|
Hi andys,
Well, as always you should tell us which PIC you are using, and what
compiler version you have. Don't assume we know these things
automatically.
Now, can you tell us how you have the MPU6050 connected to the PIC? What
I2C pull-up resistors are you using, and what are the supply voltages of the
components? Also, what is the AD0 pin connected to?
Finally, before you start to read any of the accel/gyro/temp registers, you
should read register 117h (Who Am I register) to be sure that your I2C
COMMS are working correctly.
As a previous poster mentioned, read the datasheet!
John
PS I see at least one glaring error in your code, but try to read address
117h first to see if you can actually communicate with the chip! |
|
|
andys
Joined: 23 Oct 2006 Posts: 175
|
mpu6050 problems |
Posted: Wed Jan 02, 2013 9:33 am |
|
|
I use dspic33fj128mc802 microcontroller
mpu6050 connections:
mpu -- PIC
VDD --> i connect with 3.3v (from microcontroller supply)
GND --> gnd from microcntroller
SCL --> connect to microcntroller pin 17
SDA --> connect to microcntroller pin 18
XDA
XCL
ADO--> gnd from microcontroller
INT
Where (and which value) pull-up resistor is needed ?
Can you give me an example how to read a 117h register???? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19511
|
|
Posted: Wed Jan 02, 2013 9:58 am |
|
|
On the two I2C lines. One on each. For a 3.3v device, 2K2 typically as a safe starting point assuming the wires are not too long.
Best Wishes |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Wed Jan 02, 2013 10:06 am |
|
|
wait a minute...
in your original post you say you can read the x axis data....so you must have the hardware right...
everyone here is assuming this real hardware and NOT a Proteus project.
whose 'module' did you buy, send a link to it....
also you're running the PIC at 3 volt as well ? |
|
|
andys
Joined: 23 Oct 2006 Posts: 175
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Wed Jan 02, 2013 2:28 pm |
|
|
Appears to be the classic 'all ones' response...
I'd suggest downloading the 'I2C diagnostic' program from this forum and running it. It's a 'must have' test program when using I2C devices.
'all ones' generally means the PIC is NOT communicating with the device.
You've also got 3 unconnected pins and without the datasheet from the ebay vendor/mfr NOT the mpu6050 datasheet, we don't know where they should go....
hth
jay |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Wed Jan 02, 2013 2:38 pm |
|
|
Hi andys,
Well, you haven't really followed all our suggestions, have you? It appears
that you just want a "canned solution" rather than any learning or
understanding? That will allow you to solve this problem, but the next one,
and the next one.....???
I already know your next post is going to be "where do I find I2C diagnostic
program? Plsssss....", so here is the link:
http://www.ccsinfo.com/forum/viewtopic.php?t=47707&start=21
John |
|
|
andys
Joined: 23 Oct 2006 Posts: 175
|
mpu6050 problems |
Posted: Thu Jan 03, 2013 5:44 pm |
|
|
I have already use this program (before posting) that’s why I used the address: D0
When i used the program I get two address : D0 and 00 so the sensor address is at D0. (Why 00 is appear ?????)
ACK addr:D0
ACK addr:00
I put some comments to the code as follow (I expect it your comments - I find at the web i2c_write(0xd1); but I don’t understand what is this and without this the code is not working ):
Code: |
i2c_start();
i2c_write(0xd0);/// sensor slave address
i2c_write(0x6b);///device reset
i2c_write(0x00);
i2c_stop();
delay_ms(10);
while(1)
{
//Xacce
i2c_start();
i2c_write(0xd0); /// sensor address
i2c_write(0x3b); ///ACCEL_XOUT_H
i2c_start();
i2c_write(0xd1); //THIS I found it but I don’t know why ??????
xacc=i2c_read(0);
printf("xacc:%fl:\n",xacc);
i2c_stop();
i2c_stop();
//Yacce
i2c_start();
i2c_write(0xd0); /// sensor address
i2c_write(0x3d); ///ACCEL_YOUT_H
i2c_start();
i2c_write(0xd1); //THIS I found it but I don’t know why ??????
Yacc=i2c_read(0);
printf("Yacc:%fl:\n",Yacc);
i2c_stop();
i2c_stop();
} |
how to correct my code???? I need your help |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Thu Jan 03, 2013 6:37 pm |
|
|
Hi andys,
It would be easy to hand you a working program, but you would learn
nothing, so instead we are trying to help YOU solve this problem!
You never addressed the issue of the pull-up resistors on the SDA and SCL
lines. Have you added them? Until you do, neither your code nor the
diagnostic code will work correctly! I suspect you are still missing these
resistors?
What does the datasheet indicate the address for the device should be based
on the way you have wired it? Is the diagnostic program in agreement with
the datasheet? If not, does that trouble you?
John |
|
|
andys
Joined: 23 Oct 2006 Posts: 175
|
mpu6050 problems |
Posted: Thu Jan 03, 2013 7:06 pm |
|
|
Dear ezflyr,
The pull-up resistors are included at the pcb which i include.
I try to learn I2C communication and not only to solve this issue!!
For the other questions i will read it again. Can you make it more clear ??? |
|
|
|