简体   繁体   English

如何格式化器件数据手册中的I2C数据?

[英]How to format I2C data from device data sheet?

I recently started a project with a Nordic NRF52832 DK . 我最近开始使用Nordic NRF52832 DK进行项目。 To this board I have connected one DRV2605 linear resonant actuator driver. 我已在该板上连接了一个DRV2605线性谐振致动器驱动器。 Before I moved to the Nordic board, I was prototyping on an Arduino with a provided library for the DRV2605, so that was pretty simple. 在转到Nordic板之前,我已经在Arduino上进行了原型设计,并提供了DRV2605的库,因此非常简单。

Now, I am attempting to initialize and control the DRV2605 on my own by writing to the specified registers from the device setup guide . 现在,我尝试通过写入设备设置指南中的指定寄存器来自行初始化和控制DRV2605。

Section 1.6.2 is what I have been looking at. 我一直在看1.6.2节 Let's say I want to write to the feedback control register . 假设我要写入反馈控制寄存器 I know that the address is 0x1A and that I need to write a value that corresponds to the four listed settings. 我知道地址是0x1A ,我需要写一个与列出的四个设置相对应的值。 What I am stuck on is how to actually create the data I need to write. 我所坚持的是如何实际创建我需要写入的数据。 The table has a column for what I assume is the range of bits I'll be modifying for each setting? 表格中有一列,我假设我将为每种设置修改的位范围是多少?

From looking at the chart (using the default settings) I'd assume the data I would need to write would be 13331122 . 通过查看图表(使用默认设置),我假设我需要写入的数据为13331122 If I plug that value into a dec to hex converter I get CB6AB2 . 如果我将该值插入dec至hex转换器, 则会得到CB6AB2 Does "B6" portion of that value correlate to the "Value (Hex)" column from the chart or is it coincidence? 该值的“ B6”部分是否与图表中的“值(十六进制)”列相关,或者是巧合?

Here's the code I would use to write to the FC reg: 这是我将用于写入FC reg的代码:

#define DRV_ADDR 0x5A
uint8_t fc_reg[2] = {0x1A, 13331122};
nrf_drv_twi_tx(&m_twi, DRV_ADDR, fc_reg, sizeof(fc_reg), false);

From doing some research it seems bit masking might be what I'm missing? 通过做一些研究 ,似乎掩盖了我所缺少的东西吗? This still doesn't really explain the value mismatch from the chart. 这仍然不能真正解释图表中的值不匹配。

I'd really appreciate any help I can get on this, thanks! 我真的很感谢我能为此提供的任何帮助,谢谢!

Based on the provided screenshot you can see that the Feedback Control register has an address 0x1A, more so, that register holds 1 byte of information. 根据提供的屏幕截图,您可以看到反馈控制寄存器的地址为0x1A,更重要的是,该寄存器包含1字节的信息。 It effectively serves as a bitflag where each bit represents something different. 它有效地用作位标记,其中每个位代表不同的内容。 For example only bit 7 represents LRA. 例如,仅比特7代表LRA。 So, if you were to write 0x80(DEC 128) into that register, it would turn on LRA and if you wanted to enable/configure something else, it would just be a bitwise OR of the 0x80. 因此,如果您要将0x80(DEC 128)写入该寄存器,它将打开LRA,并且如果您想启用/配置其他功能,则只能是0x80的按位或。 You have the right idea for the frames your constructing, however, it should instead look something like this for LRA. 您对构建的框架有正确的想法,但是,对于LRA,它应该看起来像这样。

uint8_t fc_reg[2] = {0x1A, 0x80}; uint8_t fc_reg [2] = {0x1A,0x80};

Obviously, replace the 0x80 with whatever flags you would like to set. 显然,将0x80替换为您要设置的任何标志。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM