ADXL345数字加速度计中的寄存器地址
Register address in ADXL345 digital accelerometer
我对 ADXL345 数字加速度计中存在的寄存器感到困惑。
让我感到困惑的第一件事是我必须在哪里写入数据以设置 +/-2g 的分辨率。我没有在数据表中找到任何提及此寄存器的内容。
其次,有两个寄存器存储了X轴的测量值。我如何从两个寄存器中读取该数据?是需要同时发送寄存器的地址,还是什么?
The first thing which confuses me is where I have to write the data to set resolution for +/-2g. I didn't find any mention of this register in the datasheet.
您可以在 the data sheet 的第 26 页找到此信息(至少在数据 sheet 的 Rev. E 中)。该范围由寄存器 0x31 (DATA_FORMAT
) 中的位 0 和 1 控制。
Register 0x31—DATA_FORMAT (Read/Write)
The DATA_FORMAT register controls the presentation of data
to Register 0x32 through Register 0x37. All data, except that for
the ±16 g range, must be clipped to avoid rollover.
SELF_TEST Bit
A setting of 1 in the SELF_TEST bit applies a self-test force to
the sensor, causing a shift in the output data. A value of 0 disables
the self-test force.
SPI Bit
A value of 1 in the SPI bit sets the device to 3-wire SPI mode,
and a value of 0 sets the device to 4-wire SPI mode.
INT_INVERT Bit
A value of 0 in the INT_INVERT bit sets the interrupts to active
high, and a value of 1 sets the interrupts to active low.
FULL_RES Bit
When this bit is set to a value of 1, the device is in full resolution
mode, where the output resolution increases with the g range
set by the range bits to maintain a 4 mg/LSB scale factor. When
the FULL_RES bit is set to 0, the device is in 10-bit mode, and
the range bits determine the maximum g range and scale factor.
Justify Bit
A setting of 1 in the justify bit selects left-justified (MSB) mode,
and a setting of 0 selects right-justified mode with sign extension.
Range Bits
These bits set the g range as described in Table 21.
Table 21. g Range Setting
╔═════════╦══════════╗
║ Setting ║ ║
╠════╦════╣ g Range ║
║ D1 ║ D0 ║ ║
╠════╬════╬══════════╣
║ 0 ║ 0 ║ +/- 2 g ║
╠════╬════╬══════════╣
║ 0 ║ 1 ║ +/- 4 g ║
╠════╬════╬══════════╣
║ 1 ║ 0 ║ +/- 8 g ║
╠════╬════╬══════════╣
║ 1 ║ 1 ║ +/- 16 g ║
╚════╩════╩══════════╝
所以,你要做的是读取寄存器 0x31 的当前值,屏蔽位 0 和 1,设置你想要的值(根据 Table 21),然后写入注册 0x31 的新值。
Secondly, there are two registers in which the measurement value for the X axis is stored. How do I read that data from both registers? Do I need to send the address of the register at the same time, or what?
不,你依次读取每个寄存器。
寄存器0x32保存x轴值的最低有效位,寄存器0x33保存x[=34的最高有效位=]-轴值。它们一起组合成 x 轴读数,精度为 13(最大)位,采用二进制补码格式。如果你只需要 8 位精度,你可以只从寄存器 0x33 读取 MSB,这会比读取两个寄存器稍微快一些。
数据sheet确实提出了一个你应该注意的额外建议:
It is recommended that a multiple-byte read of all registers be performed to prevent a change in data between reads of sequential registers.
多字节读取的具体方式会有所不同,具体取决于您使用的是 SPI 还是 I2C 总线,但无论哪种方式,都在数据 sheet 中进行了描述。对于 SPI:
To read or write multiple bytes in a single transmission, the
multiple-byte bit, located after the R/W bit in the first byte transfer
(MB in Figure 37 to Figure 39), must be set. After the register
addressing and the first byte of data, each subsequent set of clock
pulses (eight clock pulses) causes the ADXL345 to point to the
next register for a read or write. This shifting continues until the
clock pulses cease and CS is deasserted. To perform reads or writes
on different, nonsequential registers, CS must be deasserted
between transmissions and the new register must be addressed
separately.
我对 ADXL345 数字加速度计中存在的寄存器感到困惑。
让我感到困惑的第一件事是我必须在哪里写入数据以设置 +/-2g 的分辨率。我没有在数据表中找到任何提及此寄存器的内容。
其次,有两个寄存器存储了X轴的测量值。我如何从两个寄存器中读取该数据?是需要同时发送寄存器的地址,还是什么?
The first thing which confuses me is where I have to write the data to set resolution for +/-2g. I didn't find any mention of this register in the datasheet.
您可以在 the data sheet 的第 26 页找到此信息(至少在数据 sheet 的 Rev. E 中)。该范围由寄存器 0x31 (DATA_FORMAT
) 中的位 0 和 1 控制。
Register 0x31—DATA_FORMAT (Read/Write)
The DATA_FORMAT register controls the presentation of data to Register 0x32 through Register 0x37. All data, except that for the ±16 g range, must be clipped to avoid rollover.
SELF_TEST Bit
A setting of 1 in the SELF_TEST bit applies a self-test force to the sensor, causing a shift in the output data. A value of 0 disables the self-test force.
SPI Bit
A value of 1 in the SPI bit sets the device to 3-wire SPI mode, and a value of 0 sets the device to 4-wire SPI mode.
INT_INVERT Bit
A value of 0 in the INT_INVERT bit sets the interrupts to active high, and a value of 1 sets the interrupts to active low. FULL_RES Bit
When this bit is set to a value of 1, the device is in full resolution mode, where the output resolution increases with the g range set by the range bits to maintain a 4 mg/LSB scale factor. When the FULL_RES bit is set to 0, the device is in 10-bit mode, and the range bits determine the maximum g range and scale factor.
Justify Bit
A setting of 1 in the justify bit selects left-justified (MSB) mode, and a setting of 0 selects right-justified mode with sign extension.
Range Bits
These bits set the g range as described in Table 21.
Table 21. g Range Setting
╔═════════╦══════════╗ ║ Setting ║ ║ ╠════╦════╣ g Range ║ ║ D1 ║ D0 ║ ║ ╠════╬════╬══════════╣ ║ 0 ║ 0 ║ +/- 2 g ║ ╠════╬════╬══════════╣ ║ 0 ║ 1 ║ +/- 4 g ║ ╠════╬════╬══════════╣ ║ 1 ║ 0 ║ +/- 8 g ║ ╠════╬════╬══════════╣ ║ 1 ║ 1 ║ +/- 16 g ║ ╚════╩════╩══════════╝
所以,你要做的是读取寄存器 0x31 的当前值,屏蔽位 0 和 1,设置你想要的值(根据 Table 21),然后写入注册 0x31 的新值。
Secondly, there are two registers in which the measurement value for the X axis is stored. How do I read that data from both registers? Do I need to send the address of the register at the same time, or what?
不,你依次读取每个寄存器。
寄存器0x32保存x轴值的最低有效位,寄存器0x33保存x[=34的最高有效位=]-轴值。它们一起组合成 x 轴读数,精度为 13(最大)位,采用二进制补码格式。如果你只需要 8 位精度,你可以只从寄存器 0x33 读取 MSB,这会比读取两个寄存器稍微快一些。
数据sheet确实提出了一个你应该注意的额外建议:
It is recommended that a multiple-byte read of all registers be performed to prevent a change in data between reads of sequential registers.
多字节读取的具体方式会有所不同,具体取决于您使用的是 SPI 还是 I2C 总线,但无论哪种方式,都在数据 sheet 中进行了描述。对于 SPI:
To read or write multiple bytes in a single transmission, the multiple-byte bit, located after the R/W bit in the first byte transfer (MB in Figure 37 to Figure 39), must be set. After the register addressing and the first byte of data, each subsequent set of clock pulses (eight clock pulses) causes the ADXL345 to point to the next register for a read or write. This shifting continues until the clock pulses cease and CS is deasserted. To perform reads or writes on different, nonsequential registers, CS must be deasserted between transmissions and the new register must be addressed separately.