AnsweredAssumed Answered

Need help interfacing MPU6050 with LPC1769

Question asked by Tabouri Fouzi on Mar 18, 2017
Latest reply on Mar 22, 2017 by Kerry Zhou

Hi everyone !

well to start, I'm a beginner in programming LPC1769, and i need some help regarding how to use the i2c protocole to read data from the MPU6050. been trying for almost a month now and i tried different libraries (lpcopen and cmsis) aswell as trying to modify the examples present in those libraries but in vain. couldnt even get to read the WHO_AM_I register data of the MPU6050 and I'm stuck :/

If someone can explain in detail what do i need to do to be able to read and write to the mpu6050 using i2c it would be perfect.

here's the final version of the code i've tried to make work but it didnt


#include <cr_section_macros.h>
#include <NXP/crp.h>

__CRP const unsigned int CRP_WORD = CRP_NO_CRP ;

#include "lpc17xx.h"
#include "type.h"
#include "i2c.h"
#include <stdio.h>
extern volatile uint8_t I2CMasterBuffer[I2C_PORT_NUM][BUFSIZE];
extern volatile uint8_t I2CSlaveBuffer[I2C_PORT_NUM][BUFSIZE];
extern volatile uint32_t I2CReadLength[I2C_PORT_NUM];
extern volatile uint32_t I2CWriteLength[I2C_PORT_NUM];

#define PORT_USED 2


int main (void)
{
uint32_t i;


SystemClockUpdate();

I2C2Init( ); /* initialize I2c2 */

 

for ( i = 0; i < BUFSIZE; i++ )
{
I2CSlaveBuffer[PORT_USED][i] = 0x00;
}

I2CWriteLength[PORT_USED] = 2;
I2CReadLength[PORT_USED] = 1;
I2CMasterBuffer[PORT_USED][0] = 0x68; /* MPU6050 adress */
I2CMasterBuffer[PORT_USED][1] = 0x75; /* who am i reg adress _ it should contain the 0x68 */
I2CEngine( PORT_USED );

printf("%X \n",I2CSlaveBuffer[PORT_USED][0]);
while ( 1 );

}

Outcomes