Hi, All!
I can not read data from the compass! Data all the time zero!
I use the following procedure to initialize the compass:
int MPU9150_Compass_Init (void)
{
MPU9150_Set_Bypass (1);
CH = I2C_Read (CFG.COMPASS_ADDR, AKM_REG_WHOAMI);
if (CH != 0x48) return ERROR;
Delay(1);
I2C_Write (CFG.COMPASS_ADDR, AKM_REG_CNTL, AKM_POWER_DOWN);
Delay(1);
I2C_Write (CFG.COMPASS_ADDR, AKM_REG_CNTL, AKM_FUSE_ROM_ACCESS);
Delay(1);
/* Get sensitivity adjustment BUFF from fuse ROM. */
for (i=0;i<3;i++)
BUFF = I2C_Read (CFG.COMPASS_ADDR, AKM_REG_ASAX+i);
CFG.MAG_SENS_ADJ[0] = (long)BUFF[0] + 128;
CFG.MAG_SENS_ADJ[1] = (long)BUFF[1] + 128;
CFG.MAG_SENS_ADJ[2] = (long)BUFF[2] + 128;
I2C_Write (CFG.COMPASS_ADDR, AKM_REG_CNTL, AKM_POWER_DOWN);
Delay(1);
MPU9150_Set_Bypass (0);
I2C_Write (CFG.SENSOR_ADDR, REG_I2C_MST, 0x40); /* Set up master mode, master clock, and ES bit. */
I2C_Write (CFG.SENSOR_ADDR, REG_S0_ADDR, (BIT_I2C_Read | CFG.COMPASS_ADDR));/* Slave 0 reads from AKM BUFF registers. */
I2C_Write (CFG.SENSOR_ADDR, REG_S1_REG, AKM_REG_ST1); /* Compass reads start at this register. */
I2C_Write (CFG.SENSOR_ADDR, REG_S0_CTRL, (BIT_SLAVE_EN | 8)); /* Enable slave 0, 8-byte reads. */
I2C_Write (CFG.SENSOR_ADDR, REG_S1_ADDR, CFG.COMPASS_ADDR); /* Slave 1 changes AKM measurement mode. */
I2C_Write (CFG.SENSOR_ADDR, REG_S1_REG, AKM_REG_CNTL); /* AKM measurement mode register. */
I2C_Write (CFG.SENSOR_ADDR, REG_S1_CTRL, (BIT_SLAVE_EN | 1)); /* Enable slave 1, 1-byte writes. */
I2C_Write (CFG.SENSOR_ADDR, REG_S1_DO, AKM_SINGLE_MEASUREMENT); /* Set slave 1 BUFF. */
I2C_Write (CFG.SENSOR_ADDR, REG_I2C_DELAY_CTRL, 0x03); /* Trigger slave 0 and slave 1 actions at each sample. */
I2C_Write (CFG.SENSOR_ADDR, REG_YG_OFFS_TC, BIT_I2C_MST_VDDIO); /* For the MPU9150, the auxiliary I2C bus needs to be set to VDD. */
MPU9150_Set_Compass_Sample_Rate (10);
return OK;
}
Like all corresponds to the example of CA-SDK...
Accelerometer and gyroscope are read normally.
Trying to read in a loop compass:
int MPU9150_Get_Dump_Compass (void)
{
register byte i;
register byte CH;
if (!(CFG.SENSORS & INV_XYZ_COMPASS)) return ERROR;
MPU9150_Set_Bypass (1);
I2C_Write (CFG.COMPASS_ADDR, AKM_REG_CNTL,
AKM_SINGLE_MEASUREMENT);
Delay (30);
memset (DUMP_BUFF,0xFF,sizeof(DUMP_BUFF));
for (i=0;i<10;i++)
DUMP_BUFF = I2C_Read (CFG.COMPASS_ADDR, AKM_REG_WHOAMI+i);
MPU9150_Set_Bypass (0);
}
Always read the same dump, in the first byte code 0x48, 0x09 in the second byte, the rest - the zeros!
DUMP_BUFF[0] = 0x48
DUMP_BUFF[1] = 0x09
DUMP_BUFF[2] = 0x00
...
DUMP_BUFF[9] = 0x00
I.e. compass ready bit - is never set!
Also tried to read the register dump (10 - bytes) from EXT_SENS_DATA (0x69).
Read continuous zeros!
I can not understand what is happening!
Please help to get the data from the compass!
Regards,
Oleg Nicolaiciuc