@@ -85,31 +85,31 @@ void IST8310::print_status()
85
85
86
86
int IST8310::probe ()
87
87
{
88
- uint8_t id = RegisterRead (Register::WAI);
89
-
90
- if (id != Device_ID) {
91
- DEVICE_DEBUG (" unexpected WAI 0x%02x" , id);
92
-
93
- // Apparently, the IST8310's WHOAMI register is writeable. Presumably,
94
- // this can get corrupted by bus noise. It is only reset if powered off
95
- // for 30s or by a reset.
96
- RegisterWrite (Register::CNTL2, CNTL2_BIT::SRST);
97
-
98
- auto start_time = hrt_absolute_time ();
99
-
100
- while (hrt_elapsed_time (&start_time) < 50_ms) {
101
- px4_usleep (10'000 );
102
- id = RegisterRead (Register::WAI);
88
+ // Reading the WAI register is not always reliable, it can return 0xff or
89
+ // other values if the sensor has been powered up in a certain way. In
90
+ // addition, the I2C address is not always correct, sometimes it boots with
91
+ // 0x0C rather than 0x0E.
92
+ const auto start_time = hrt_absolute_time ();
93
+
94
+ while (hrt_elapsed_time (&start_time) < 50_ms) {
95
+ set_device_address (I2C_ADDRESS_DEFAULT);
96
+ const int WAI = RegisterRead (Register::WAI);
97
+
98
+ if (WAI == Device_ID) {
99
+ // Device has the right I2C address and register content
100
+ return PX4_OK;
101
+ }
103
102
104
- if (id == Device_ID) {
105
- return PX4_OK;
106
- }
103
+ // send reset command to all four possible addresses
104
+ for (uint8_t addr = 0x0C ; addr <= 0x0F ; addr++) {
105
+ set_device_address (addr);
106
+ RegisterWrite (Register::CNTL2, CNTL2_BIT::SRST);
107
107
}
108
108
109
- return PX4_ERROR ;
109
+ px4_usleep ( 10'000 ) ;
110
110
}
111
111
112
- return PX4_OK ;
112
+ return PX4_ERROR ;
113
113
}
114
114
115
115
void IST8310::RunImpl ()
@@ -290,11 +290,14 @@ bool IST8310::RegisterCheck(const register_config_t ®_cfg)
290
290
return success;
291
291
}
292
292
293
- uint8_t IST8310::RegisterRead (Register reg)
293
+ int IST8310::RegisterRead (Register reg)
294
294
{
295
295
const uint8_t cmd = static_cast <uint8_t >(reg);
296
296
uint8_t buffer{};
297
- transfer (&cmd, 1 , &buffer, 1 );
297
+ const int ret = transfer (&cmd, 1 , &buffer, 1 );
298
+
299
+ if (ret != OK) { return -1 ; }
300
+
298
301
return buffer;
299
302
}
300
303
0 commit comments