Hi
I am trying to read the accelerometer register in the MPU-6050 with my xmc4700 via i2c. At this moment i managed to start communication but when i try to read the x-axis register of the accelerometer, i keep getting null readings (0x00), and i can't find out why.
You can see in my logic data analyzer, that everything goes smooth until i start receiving readings.
Any ideas? :)
#include <DAVE.h> //Declarations from DAVE Code Generation (includes SFR declaration)
#define MPU_6050_ADRESS 0xD0
#define REG_6B (0x6b)
#define REG_X_AXIS_ACCEL (0x3b)
void Configures_I2C(void){
uint8_t buffer0[5];
buffer0[0] = REG_6B ;
buffer0[1] = 0;
/*//Starts I2C
I2C_MASTER_Init(&I2C_MASTER_EEPROM);
delay5ms();*/
//Directs communication to register 0x6b from the MPU-6050
I2C_MASTER_Transmit(&I2C_MASTER_EEPROM, true, MPU_6050_ADRESS, buffer0, 1, false);
while(I2C_MASTER_IsTxBusy(&I2C_MASTER_EEPROM));
//Places MPU-6050 register at zeros (wake up) and gives STOP BIT
I2C_MASTER_Transmit(&I2C_MASTER_EEPROM, false, MPU_6050_ADRESS, &buffer0[1], 1, true);
while(I2C_MASTER_IsTxBusy(&I2C_MASTER_EEPROM));
}
void Read_MPU(void){
uint8_t buffer1[5];
buffer1[2] = REG_X_AXIS_ACCEL;
buffer1[3] = 0;
//Comunicates to MPU-6050 register 0x3b (X axis from accel)
I2C_MASTER_Transmit(&I2C_MASTER_EEPROM, true, MPU_6050_ADRESS, &buffer1[2], 1, false);
I2C_MASTER_IsTxBusy(&I2C_MASTER_EEPROM));
I2C_MASTER_Receive(&I2C_MASTER_EEPROM, true, MPU_6050_ADRESS, &buffer1[3], 1, true, false);
while(I2C_MASTER_IsRxBusy(&I2C_MASTER_EEPROM));
}
int main(void)
{
DAVE_STATUS_t init_status;
//I2C_MASTER_STATUS_t statusMaster;
init_status = DAVE_Init();
if(init_status == DAVE_STATUS_SUCCESS)
{
while(1)
{
Configures_I2C();
Read_MPU();
}
}
return 0;
}
Data analyzer:
Attachment 3187