Skip to content

Commit

Permalink
Merge pull request #3546 from iNavFlight/de_ist8310_fix
Browse files Browse the repository at this point in the history
Fix datasheet incompliance for IST8310 compass chip
  • Loading branch information
fiam authored Jul 9, 2018
2 parents c3296d5 + c4401db commit 579bd5c
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/main/drivers/compass/compass_ist8310.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
#define IST8310_REG_CNTRL1 0x0A
#define IST8310_REG_CNTRL2 0x0B
#define IST8310_REG_AVERAGE 0x41
#define IST8310_REG_PDCNTL 0x42

// Parameter
// ODR = Output Data Rate, we use single measure mode for getting more data.
Expand All @@ -103,7 +104,8 @@

// Device ID (ist8310 -> 0x10)
#define IST8310_CHIP_ID 0x10
#define IST8310_AVG_16 0x24
#define IST8310_AVG_16 0x24
#define IST8310_PULSE_DURATION_NORMAL 0xC0

#define IST8310_CNTRL2_RESET 0x01
#define IST8310_CNTRL2_DRPOL 0x04
Expand All @@ -117,6 +119,9 @@ static bool ist8310Init(magDev_t * mag)
busWrite(mag->busDev, IST8310_REG_AVERAGE, IST8310_AVG_16);
delay(5);

busWrite(mag->busDev, IST8310_REG_PDCNTL, IST8310_PULSE_DURATION_NORMAL);
delay(5);

return true;
}

Expand All @@ -135,10 +140,10 @@ static bool ist8310Read(magDev_t * mag)
return false;
}

// need to modify when confirming the pcb direction
mag->magADCRaw[X] = (int16_t)(buf[1] << 8 | buf[0]) * LSB2FSV;
mag->magADCRaw[Y] = (int16_t)(buf[3] << 8 | buf[2]) * LSB2FSV;
mag->magADCRaw[Z] = (int16_t)(buf[5] << 8 | buf[4]) * LSB2FSV;
// Looks like datasheet is incorrect and we need to invert Y axis to conform to right hand rule
mag->magADCRaw[X] = (int16_t)(buf[1] << 8 | buf[0]) * LSB2FSV;
mag->magADCRaw[Y] = -(int16_t)(buf[3] << 8 | buf[2]) * LSB2FSV;
mag->magADCRaw[Z] = (int16_t)(buf[5] << 8 | buf[4]) * LSB2FSV;

return true;
}
Expand Down

0 comments on commit 579bd5c

Please sign in to comment.