PIC/MPU 6050 I2C communication

Thread Starter

rwallace

Joined Jan 16, 2013
3
PIC 18f4520
MPU 6050
I2C Pull Up: 1.8k

MPlabX with C18 compiler

I have been trying to communicate with the MPU through an I2C bus for quite a while and can't seem to get an acknowledgement from the MPU. I am fairly new to the PIC and MPU so it could be an obvious problem but I have searched every forum and tried everything I could think of but still no communication.

Rich (BB code):
#include <stdio.h>
#include <stdlib.h>
#include <p18f4520.h>
#include <i2c.h>

//Configuration bits
#pragma config WDT = OFF
#pragma config OSC = INTIO67
//#pragma config PWRT + ON
#pragma config LVP = OFF
#pragma config MCLRE = ON
#pragma config BOREN = ON
//=============================================================
void main(void) {
    unsigned char data=0;
    OSCCON = 0b01100000;   //set to 4Mhz Internal clock
    while(OSCCONbits.IOFS != 1);    //wait for oscillator to stabilize
    TRISC = 0x00;
    PORTC = 0x00;
    SSPADD=0x09;         //Sets Baud Rate to 100kHz after equation//

    OpenI2C (MASTER,SLEW_OFF);
    if (PIR1bits.SSPIF == 0)    //Test I2C master mode initiated//
    {LATDbits.LATD2=1;}
    
   StartI2C ();
   IdleI2C();
   WriteI2C (0xD0);
   IdleI2C();
   WriteI2C (0x75);
   IdleI2C ();
   WriteI2C (0b00000000);
   IdleI2C ();
   StopI2C ();
   
   StartI2C();
   IdleI2C ();
   WriteI2C (0xD0);
    IdleI2C ();
   WriteI2C (0x75);
   IdleI2C ();
   StartI2C ();
   WriteI2C (0xD1);
   IdleI2C ();
   data = ReadI2C();
   IdleI2C ();
   StopI2C ();
}
As shown I was trying to "wake" it up through the power management register and also reading from the who_am_i register.

I have also posted a picture of my setup:
http://i.imgur.com/nnPVj.jpg

Any help would be greatly appreciated.
 
Last edited by a moderator:

ErnieM

Joined Apr 24, 2011
8,415
That is always the first thing to check with I2C: get that ACK from the slave.

One thing that never seems standard is the addresses! If 0xD0 is the write address then 0xD1 should be the read address. See if the data sheet confirms this.
 
Top