Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

imu sensor mpu 6050 help

Status
Not open for further replies.

Disha Karnataki

Full Member level 5
Joined
Jul 20, 2013
Messages
249
Helped
9
Reputation
18
Reaction score
8
Trophy points
18
Location
india
Activity points
2,231
i have interfaced a mpu 6050 to my atmega 8 & have written a code using i2c header file.
the code is to see whether the device is accessible or not. and the function used is:
Code:
 unsigned char i2c_start(unsigned char address)
Issues a start condition and sends address and transfer direction.
return 0 = device accessible, 1= failed to access device
then i am printing the value got on lcd
ex:
Code:
#define Dev24C02 0X68   //sensor address
ret=i2c_start(Dev24C02);    //sending device address
  lcd_showvalue(ret);

so ret should either print 0 or 1.
but lcd remains blank (there is no print at all).
i have tested the lcd (it's working all fine with other programs).
I am unable to figure out what is the exact problem..:-(
 
Last edited:

Did you check in the MPU 6050 datasheet,before interfacing,that I2C is supported by it or not?
If it is not supported,then it explains why you are not getting anything on LCD(Still,you should be getting 0 on the LCD at best,nothing on the LCD..thats weird).Try using SPI or any other data communication protocol which is supported by the MPU 6050 as per its datasheet.That should work.If still you do not see anything on the LCD,In that case....upload the code.
 

Did you check in the MPU 6050 datasheet,before interfacing,that I2C is supported by it or not?
If it is not supported
obviously i did..
And you see mpu 6050 is a i2c device only mpu 6000 has spi ..
and you see this image here:
https://playground.arduino.cc/uploads/Main/mpu-6050.jpg
there are pins: SDA, SCL which itself suggest that they should be connected to SDA,SCL pins of the controller which are nothing but meant for i2c communication..
 

there are pins: SDA, SCL which itself suggest that they should be connected to SDA,SCL pins of the controller which are nothing but meant for i2c communication..
The device is I2C compatible and still not communicating with the microcontroller...that is weird.If possible,upload the code.That would give some clues about the problem..
 

Code:
#include<avr/io.h>		         //This is the header for AVR Microcontroller.
#define F_CPU 12000000UL
#include "i2cmaster.h"
#include<util/delay.h> 
#include"lcd118010.h"	
#define Dev24C02 0X68                   //address of the i2c device connected
int main(void)
{
unsigned char ret;
DDRC=0X00;
PORTC=0X00;

lcd_init();
i2c_init();             //initialise i2c communication
while(1)
{
lcd_string("hi");
 ret=i2c_start(Dev24C02);     // set device address & if device is accessible ret=0  if not ret=1
 lcd_showvalue(ret);
 _delay_ms(1000); 
lcd_clear();
}
}
observations:

lcd prints "hi" after that no operations take place that is lcd does not clears. but, if
Code:
 ret=i2c_start(Dev24C02);
line is commented then, lcd clears & the loop repeats again & again due to while loop.
 

I2C transactions should be always completed. Performing I2C_start without subsequent I2C_stop is just a bad idea. Code execution will possibly hang at the next I2C_start.

In other words, your test is meaningless and doesn't tell anything about I2C communication success or failure of the device.
 

I2C transactions should be always completed. Performing I2C_start without subsequent I2C_stop is just a bad idea. Code execution will possibly hang at the next I2C_start.

In other words, your test is meaningless and doesn't tell anything about I2C communication success or failure of the device.

well this is my first code i tried before going to the code that i pasted above:
Code:
#include<avr/io.h>		         //This is the header for AVR Microcontroller.
#define F_CPU 12000000UL
#include "i2cmaster.h"
#include<util/delay.h> 
#include"lcd118010.h"	
#define Dev24C02 0X68
int main(void)
{
unsigned char ret;
DDRC=0X00;
PORTC=0X00;

lcd_init();
i2c_init();           //initialise i2c communication
while(1)
{
lcd_string("hi");
 ret=i2c_start(Dev24C02);     // set device address and write mode
 i2c_write(0X6B);                //waking up the device
i2c_write(0X00);                 // ''      ''         ''    ''
 ret = i2c_readNak();  
 i2c_stop();               
 lcd_showvalue(ret);   
  _delay_ms(1000); 
lcd_clear();

}
}

but, the problem still persists.
 

I think, you are misunderstanding the address notation used by the i2c library. It's expecting the 7-bit addresed b1101000 left aligned, write address 0xd0 and read address 0xd1. So the code is unlikely to work.
 

do you mean:
Code:
i2c_write(0X6B);
address should be left aligned & so 0XD6 is the value?
so
Code:
  i2c_write(0Xd6);
have i got it correct?

but, u see that:
Code:
 ret=i2c_start(Dev24C02)
whenever this line is executed with a stop condition (as per the code) if my address is wrong then, device wont be detected & hence at least the ret function should return value "1" (that means device not accessible) & print it on lcd.. But lcd is just blank after printing "hi"
 

In this library, the address is supplied with i2c_start. Presently a wrong address.

whenever this line is executed with a stop condition (as per the code) if my address is wrong then, device wont be detected & hence at least the ret function should return value "1" (that means device not accessible) & print it on lcd.. But lcd is just blank after printing "hi"

The ret value from i2c_start is printed in the first (erroneous) code.

If lcd_showvalue(ret) is actually executed, but showing no value, how should the problem be caused by I2C? But in any case, there are many ways to debug the code.
 

If lcd_showvalue(ret) is actually executed, but showing no value, how should the problem be caused by I2C?
this is because when i commented all the i2c function lines then, the ret value was printed as some garbage value.
here is the modified code without any i2c functions used and ret value is getting printed (some garbage value) .
Code:
#include<avr/io.h>		         //This is the header for AVR Microcontroller.
#define F_CPU 12000000UL
#include "i2cmaster.h"
#include<util/delay.h> 
#include"lcd118010.h"	
#define Dev24C02 0X68
int main(void)
{
unsigned char ret;
DDRC=0X00;              //initializing as i/p port
PORTC=0X00;


lcd_init();
i2c_init();         //initialise i2c communication
while(1)
{

lcd_string("hi");
 ret=i2c_start(Dev24C02);     // set device address and write mode
                      // i2c_write(0X6B);              //commenting all i2c lines
                     //i2c_write(0X00);
                         //ret = i2c_readNak();  
                      //  i2c_stop();
  lcd_showvalue(ret);
  _delay_ms(1000); 
lcd_clear();

}
}
 

Presumed you see that the I2C functions are conflicting with LCD, does it tell anything about operation or non-operation of the I2C device?

You should debug your code more systematically. Use a simple indicator to signal success and failure of the I2C action, e.g. LEDs, possibly UART output. Verify that all parts of the code are executed at all.

There may be a resource conflict, the I2C routines are changing port or other internal registers that are expected in a specific state by the LCD.
 

Presumed you see that the I2C functions are conflicting with LCD, does it tell anything about operation or non-operation of the I2C device?
instead of lcd i have tried using leds so that whenever i2c communication is over leds should blink with some arbitrary delay indicating finish operation but, that also gave problem.
operation/ non operation of the device is given by the start function itself by sending value of ret as "1" or "0".
There may be a resource conflict, the I2C routines are changing port or other internal registers that are expected in a specific state by the LCD.
i will give the link of pleury libraries for i2c.
in the zip file: twimaster.c contains the required i2c functions & i2c_master.h is the header file.
 

Attachments

  • i2cmaster(4).zip
    23 KB · Views: 78

I'm not so familiar with AVR I2C operation. I can imagine that the bus isn't free (SCL not high) and i2c_start() waits forever.

Possible reasons are:
- missing I2C pull-up resistors
- wiring error
- slave device problems
 

I'm not so familiar with AVR I2C operation. I can imagine that the bus isn't free (SCL not high) and i2c_start() waits forever.
but
i checked the voltage levels at scl ,sda pins of the atmega 8 microcontroller i.e
they are 2.99v where in the sensor supply value is 3v.
i have used 4.7k pull up resistors.
 

Minimal high voltage at I2C pin is 0.7*Vcc according to the datasheet, so 3V slave isn't guaranteed to work with 5V processor supply.
 

Minimal high voltage at I2C pin is 0.7*Vcc according to the datasheet, so 3V slave isn't guaranteed to work with 5V processor supply.
but, the slave device max voltage to be given is 3.3v as per datasheet. So if i am giving 3v i will have to give 3.3v to my sensor board & try.
this is what is mentioned in the datasheet:

For power supply flexibility, the MPU-60X0 operates from VDD power supply voltage range of 2.375V-3.46V
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top