I had no problems reading data from the IMU with the PIC but I cannot get the ARM to read the data.
This is the PIC code first, the device address is 0x28 but this is bit shifted left and the R/W bit appended, hence 0x50 and 0x51...
Code: Select all
void Read_Data(){
I2C2_Start();
I2C2_Wr(0x50);
I2C2_Wr(reg1);
I2C2_Repeated_Start();
I2C2_Wr(0x51);
GravByte = I2C2_Rd(0);
I2C2_Stop();
Gravity = (Gravity + GravByte);
Gravity = (Gravity << 8);
I2C2_Start();
I2C2_Wr(0x50);
I2C2_Wr(reg2);
I2C2_Repeated_Start();
I2C2_Wr(0x51);
GravByte = I2C2_Rd(0);
I2C2_Stop();
NewGrav = (Gravity | GravByte);
NewGrav = (NewGrav/16);
//OldHeading = NewHeading;
IntToStr(NewGrav, GravStr);
writebuff[0] = x; // Selects whether first byte will be H, R or P
//writebuff[1] = 0x3A;
for (y = 1; y < 8; y++){
writebuff[y] = GravStr[y + 1];
}
while((!HID_Write(writebuff,64));
}
Code: Select all
void Read_IMU_Data(){
I2C_Set_Active(&I2C2_Start, &I2C2_Read, &I2C2_Write); // Sets the I2C2 module active
// Read the first register byte...
I2C2_Start();
I2C2_Write(0x28, reg1, 1, END_MODE_RESTART);
I2C2_Read(0x28, I2CReadByte, 1, END_MODE_STOP);
MSAngle = (MSAngle + I2CReadByte);
MSAngle = (MSAngle << 8);
// Read the second register byte...
I2C2_Start();
I2C2_Write(0x28, reg2, 1, END_MODE_RESTART);
I2C2_Read(0x28, I2CReadByte, 1, END_MODE_STOP);
Angle = (MSAngle | I2CReadByte);
Angle = (Angle/16);
IntToStr(Angle, AngleStr);
writebuff[0] = x; // Selects whether first byte will be H, R or P
for (y = 1; y < 8; y++){
writebuff[y] = AngleStr[y + 1];
}
while(!HID_Write(writebuff,64));
}
Any ideas?
ST.