HMC5883: Fix I2C operation

This commit is contained in:
Lorenz Meier
2015-01-03 17:54:48 +01:00
parent f3e3565d1b
commit 268cf7efc5
2 changed files with 24 additions and 10 deletions
+23 -9
View File
@@ -1330,16 +1330,28 @@ start(int external_bus, enum Rotation rotation)
/* create the driver, only attempt I2C for the external bus */
if (interface == nullptr && (HMC5883_I2C_interface != nullptr)) {
interface = HMC5883_I2C_interface(PX4_I2C_BUS_EXPANSION);
if (interface->init() != OK) {
delete interface;
interface = nullptr;
warnx("no device on I2C bus #%u", PX4_I2C_BUS_EXPANSION);
}
}
if (interface == nullptr) {
warnx("failed to allocate an interface");
}
#ifdef PX4_I2C_BUS_ONBOARD
if (interface == nullptr && (HMC5883_I2C_interface != nullptr)) {
interface = HMC5883_I2C_interface(PX4_I2C_BUS_ONBOARD);
if (interface->init() != OK) {
delete interface;
warnx("interface init failed");
} else {
if (interface->init() != OK) {
delete interface;
interface = nullptr;
warnx("no device on I2C bus #%u", PX4_I2C_BUS_ONBOARD);
}
}
#endif
/* interface will be null if init failed */
if (interface != nullptr) {
g_dev_ext = new HMC5883(interface, HMC5883L_DEVICE_PATH_EXT, rotation);
if (g_dev_ext != nullptr && OK != g_dev_ext->init()) {
@@ -1367,17 +1379,19 @@ start(int external_bus, enum Rotation rotation)
#endif
#ifdef PX4_I2C_BUS_ONBOARD
/* this device is already connected as external if present above */
if (interface == nullptr && (HMC5883_I2C_interface != nullptr)) {
interface = HMC5883_I2C_interface(PX4_I2C_BUS_ONBOARD);
}
#endif
if (interface == nullptr) {
warnx("failed to allocate an interface");
warnx("no internal bus scanned");
goto fail;
}
if (interface->init() != OK) {
delete interface;
warnx("interface init failed");
warnx("no device on internal bus");
} else {
g_dev_int = new HMC5883(interface, HMC5883L_DEVICE_PATH_INT, rotation);
+1 -1
View File
@@ -88,7 +88,7 @@ HMC5883_I2C_interface(int bus)
}
HMC5883_I2C::HMC5883_I2C(int bus) :
I2C("HMC5883_I2C", nullptr, bus, 0, 400000)
I2C("HMC5883_I2C", nullptr, bus, HMC5883L_ADDRESS, 400000)
{
}