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.
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.
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 ();
}
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: