Skip to content

Commit a397004

Browse files
dagarLorenzMeier
authored andcommitted
adis16448: add additional delay after transfer in case of back to back transcations
- add verified register read method
1 parent 0033c0f commit a397004

File tree

3 files changed

+29
-11
lines changed

3 files changed

+29
-11
lines changed

src/drivers/imu/analog_devices/adis16448/ADIS16448.cpp

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,12 @@ int ADIS16448::probe()
164164
}
165165

166166
for (int attempt = 0; attempt < 3; attempt++) {
167-
const uint16_t PROD_ID = RegisterRead(Register::PROD_ID);
167+
const uint16_t PROD_ID = RegisterReadVerified(Register::PROD_ID);
168168

169169
if (PROD_ID == Product_identification) {
170-
const uint16_t SERIAL_NUM = RegisterRead(Register::SERIAL_NUM);
171-
const uint16_t LOT_ID1 = RegisterRead(Register::LOT_ID1);
172-
const uint16_t LOT_ID2 = RegisterRead(Register::LOT_ID2);
170+
const uint16_t SERIAL_NUM = RegisterReadVerified(Register::SERIAL_NUM);
171+
const uint16_t LOT_ID1 = RegisterReadVerified(Register::LOT_ID1);
172+
const uint16_t LOT_ID2 = RegisterReadVerified(Register::LOT_ID2);
173173

174174
PX4_INFO("Serial Number: 0x%02x, Lot ID1: 0x%02x ID2: 0x%02x", SERIAL_NUM, LOT_ID1, LOT_ID2);
175175

@@ -201,7 +201,7 @@ void ADIS16448::RunImpl()
201201
case STATE::WAIT_FOR_RESET:
202202

203203
if (_self_test_passed) {
204-
if ((RegisterRead(Register::PROD_ID) == Product_identification)) {
204+
if ((RegisterReadVerified(Register::PROD_ID) == Product_identification)) {
205205
// if reset succeeded then configure
206206
_state = STATE::CONFIGURE;
207207
ScheduleNow();
@@ -228,7 +228,7 @@ void ADIS16448::RunImpl()
228228
break;
229229

230230
case STATE::SELF_TEST_CHECK: {
231-
const uint16_t MSC_CTRL = RegisterRead(Register::MSC_CTRL);
231+
const uint16_t MSC_CTRL = RegisterReadVerified(Register::MSC_CTRL);
232232

233233
if (MSC_CTRL & MSC_CTRL_BIT::Internal_self_test) {
234234
// self test not finished, check again
@@ -248,7 +248,7 @@ void ADIS16448::RunImpl()
248248

249249
bool test_passed = true;
250250

251-
const uint16_t DIAG_STAT = RegisterRead(Register::DIAG_STAT);
251+
const uint16_t DIAG_STAT = RegisterReadVerified(Register::DIAG_STAT);
252252

253253
if (DIAG_STAT & DIAG_STAT_BIT::Self_test_diagnostic_error_flag) {
254254
PX4_ERR("self test failed");
@@ -493,7 +493,7 @@ void ADIS16448::RunImpl()
493493

494494
bool ADIS16448::Configure()
495495
{
496-
const uint16_t LOT_ID1 = RegisterRead(Register::LOT_ID1);
496+
const uint16_t LOT_ID1 = RegisterReadVerified(Register::LOT_ID1);
497497

498498
// Only enable CRC-16 for verified lots (HACK to support older ADIS16448AMLZ with no explicit detection)
499499
if (LOT_ID1 == 0x1824) {
@@ -619,7 +619,7 @@ bool ADIS16448::RegisterCheck(const register_config_t &reg_cfg)
619619
{
620620
bool success = true;
621621

622-
const uint16_t reg_value = RegisterRead(reg_cfg.reg);
622+
const uint16_t reg_value = RegisterReadVerified(reg_cfg.reg);
623623

624624
if (reg_cfg.set_bits && ((reg_value & reg_cfg.set_bits) != reg_cfg.set_bits)) {
625625
PX4_DEBUG("0x%02hhX: 0x%02hhX (0x%02hhX not set)", (uint8_t)reg_cfg.reg, reg_value, reg_cfg.set_bits);
@@ -644,10 +644,26 @@ uint16_t ADIS16448::RegisterRead(Register reg)
644644
transferhword(cmd, nullptr, 1);
645645
px4_udelay(SPI_STALL_PERIOD);
646646
transferhword(nullptr, cmd, 1);
647+
px4_udelay(SPI_STALL_PERIOD);
647648

648649
return cmd[0];
649650
}
650651

652+
uint16_t ADIS16448::RegisterReadVerified(Register reg, int retries)
653+
{
654+
for (int attempt = 0; attempt < retries; attempt++) {
655+
uint16_t read1 = RegisterRead(reg);
656+
uint16_t read2 = RegisterRead(reg);
657+
658+
if (read1 == read2) {
659+
return read1;
660+
}
661+
}
662+
663+
// failed
664+
return 0;
665+
}
666+
651667
void ADIS16448::RegisterWrite(Register reg, uint16_t value)
652668
{
653669
set_frequency(SPI_SPEED);
@@ -659,11 +675,12 @@ void ADIS16448::RegisterWrite(Register reg, uint16_t value)
659675
transferhword(cmd, nullptr, 1);
660676
px4_udelay(SPI_STALL_PERIOD);
661677
transferhword(cmd + 1, nullptr, 1);
678+
px4_udelay(SPI_STALL_PERIOD);
662679
}
663680

664681
void ADIS16448::RegisterSetAndClearBits(Register reg, uint16_t setbits, uint16_t clearbits)
665682
{
666-
const uint16_t orig_val = RegisterRead(reg);
683+
const uint16_t orig_val = RegisterReadVerified(reg);
667684

668685
uint16_t val = (orig_val & ~clearbits) | setbits;
669686

src/drivers/imu/analog_devices/adis16448/ADIS16448.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ class ADIS16448 : public device::SPI, public I2CSPIDriver<ADIS16448>
9191
bool RegisterCheck(const register_config_t &reg_cfg);
9292

9393
uint16_t RegisterRead(Register reg);
94+
uint16_t RegisterReadVerified(Register reg, int retries = 1);
9495
void RegisterWrite(Register reg, uint16_t value);
9596
void RegisterSetAndClearBits(Register reg, uint16_t setbits, uint16_t clearbits);
9697

src/drivers/imu/analog_devices/adis16448/Analog_Devices_ADIS16448_registers.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ namespace Analog_Devices_ADIS16448
6565
static constexpr uint32_t SPI_SPEED = 2 * 1000 * 1000; // 2 MHz SPI serial interface
6666
static constexpr uint32_t SPI_SPEED_BURST = 1 * 1000 * 1000; // 1 MHz SPI serial interface for burst read
6767

68-
static constexpr uint32_t SPI_STALL_PERIOD = 10; // 9 us Stall period between data
68+
static constexpr uint32_t SPI_STALL_PERIOD = 11; // 9 us Stall period between data
6969

7070
static constexpr uint16_t DIR_WRITE = 0x80;
7171

0 commit comments

Comments
 (0)