gpt4 book ai didi

accelerometer - ADXL345数字加速度计中的寄存器地址

转载 作者:行者123 更新时间:2023-12-04 08:32:46 25 4
gpt4 key购买 nike

我对 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 页上找到此信息。 (至少,在数据表的修订版 E 中)。该范围由寄存器 0x​​31 ( DATA_FORMAT ) 中的位 0 和 1 控制。

Register 0x31—DATA_FORMAT (Read/Write)

The DATA_FORMAT register controls the presentation of datato Register 0x32 through Register 0x37. All data, except that forthe ±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 tothe sensor, causing a shift in the output data. A value of 0 disablesthe 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 activehigh, 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 resolutionmode, where the output resolution increases with the g rangeset by the range bits to maintain a 4 mg/LSB scale factor. Whenthe FULL_RES bit is set to 0, the device is in 10-bit mode, andthe 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 ║
╚════╩════╩══════════╝

因此,您需要做的是读取寄存器 0x​​31 的当前值,屏蔽位 0 和 1,设置您想要的值(如表 21),然后将新值写入寄存器 0x​​31。

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?


不,您按顺序读取每个寄存器。
寄存器 0x​​32 保存 x 轴值的最低有效位,寄存器 0x​​33 保存 x 轴值的最高有效位。它们一起以二进制补码格式组合成具有 13(最大)位精度的 x 轴读数。如果您只需要 8 位精度,则可以仅从寄存器 0x​​33 读取 MSB,这比读取两个寄存器略快。
数据表确实提出了一项额外的建议,您应该注意:

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 总线,但无论哪种方式,都在数据表中进行了描述。对于 SPI:

To read or write multiple bytes in a single transmission, themultiple-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 registeraddressing and the first byte of data, each subsequent set of clockpulses (eight clock pulses) causes the ADXL345 to point to thenext register for a read or write. This shifting continues until theclock pulses cease and CS is deasserted. To perform reads or writeson different, nonsequential registers, CS must be deassertedbetween transmissions and the new register must be addressedseparately.

关于accelerometer - ADXL345数字加速度计中的寄存器地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64942956/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com