Fixed the QMC5883 identification,add check ID

This commit is contained in:
ljwang 2017-07-25 18:33:26 +08:00 committed by Andrew Tridgell
parent 4865aef9e4
commit 648871a388
2 changed files with 17 additions and 5 deletions

View File

@ -96,10 +96,7 @@ bool AP_Compass_QMC5883L::init()
_dev->set_retries(10);
uint8_t whoami;
if (!_dev->read_registers(QMC5883L_REG_ID, &whoami,1)||
whoami != QMC5883_ID_VAL){
// not an QMC5883L
if(!_check_whoami()){
goto fail;
}
@ -143,6 +140,20 @@ bool AP_Compass_QMC5883L::init()
_dev->get_semaphore()->give();
return false;
}
bool AP_Compass_QMC5883L::_check_whoami()
{
uint8_t whoami;
//After power on 0x21 == 0x03
if (!_dev->read_registers(0x21, &whoami,1)||
whoami != 0x03){
return false;
}
if (!_dev->read_registers(QMC5883L_REG_ID, &whoami,1)||
whoami != QMC5883_ID_VAL){
return false;
}
return true;
}
void AP_Compass_QMC5883L::timer()
{

View File

@ -46,6 +46,7 @@ private:
bool force_external,
enum Rotation rotation);
bool _check_whoami();
void timer();
bool init();