Need help interfacing MPU6050 with LPC1769

cancel
Showing results for 
Search instead for 
Did you mean: 

Need help interfacing MPU6050 with LPC1769

832 Views
tabourifouzi
Contributor I

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 :smileycry:


#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 );

}

Labels (4)
0 Kudos
1 Reply

328 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Tabouri Fouzi,

     Please don't worry about it, when we meet the problem, we need more patient to find the root problem!

     I don't have the MPU6050 on my side, but as a I2C slave, the test method is the same.

    If you want to read the data from the MPU6050, you must send the data which is the MPC6050 needed.

   1. Check the MPU6050, what the command, I2C clock , slave address the MPU6050 needed?

   2. In LPC, configure the I2C module, yes, you can refer to lpcopen or cmsis driver, configure the I2C baudrate, the send data which your slave need.

   3. Use the oscilloscope to check the I2C wave which is send from the LPC.This is very important, check byte by byte.

      Clock baud rate, slave address, the command, is it the slave needed?

 Please follow my step to check it, check wave and the data in the I2C bus is very important.

Any updated question, just let me know!


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos