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
unsigned char i2c_start(unsigned char address)
#define Dev24C02 0X68 //sensor address
ret=i2c_start(Dev24C02); //sending device address
lcd_showvalue(ret);
obviously i did..Did you check in the MPU 6050 datasheet,before interfacing,that I2C is supported by it or not?
If it is not supported
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..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..
#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();
}
}
ret=i2c_start(Dev24C02);
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.
#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();
}
}
i2c_write(0X6B);
i2c_write(0Xd6);
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"
this is because when i commented all the i2c function lines then, the ret value was printed as some garbage value.If lcd_showvalue(ret) is actually executed, but showing no value, how should the problem be caused by I2C?
#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();
}
}
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.Presumed you see that the I2C functions are conflicting with LCD, does it tell anything about operation or non-operation of the I2C device?
i will give the link of pleury libraries for i2c.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.
butI'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, 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.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.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?