ST意法半导体
直播中

张晓宁

7年用户 210经验值
私信 关注
[问答]

LIS3DSH读值和文档请求不起作用怎么办

通过这样做,我已经能够使LIS3DSH为单个值工作:
transmitData [0] =(uint8_t)(LIS3DSH_READ | LIS3DSH_X_L);

SPISend(transmitData,receiveData,2);
xl = receiveData [1];但是如果我想在一个事务中读出多个值,我希望我可以这样做:
transmitData [0] =(uint8_t)(LIS3DSH_READ | LIS3DSH_MULtiPLE | LIS3DSH_X_L);

transmitData [1] =(uint8_t)(LIS3DSH_READ | LIS3DSH_X_L);
SPISend(transmitData,receiveData,3);
xl = receiveData [1];
xh = receiveData [2];或者字节2只是0xFF,因为自动增量会达到我的预期。
但是,唉,它不起作用。 (寄存器6中打开了地址增量)
可以这样做吗?我错过了什么?
现在需要文档,温度寄存器没有记录在数据表中。需要一段时间才能发现它是Celcius并偏向-25C。此外,M / S位也没有记录。我发现AN3393非常有用,数据表,不是那么多。
谢谢,
来自大白北的安德烈。

以上来自于谷歌翻译


以下为原文




I've been able to get the LIS3DSH working for single values by doing this:
transmitData[0] = (uint8_t) (LIS3DSH_READ | LIS3DSH_X_L);

SPISend( transmitData, receiveData, 2);
xl = receiveData[1];But if I wanted to read out multiple values in one transaction, I'd expect that I could do something like:
transmitData[0] = (uint8_t) (LIS3DSH_READ | LIS3DSH_MULTIPLE | LIS3DSH_X_L);

transmitData[1] = (uint8_t) (LIS3DSH_READ | LIS3DSH_X_L);
SPISend( transmitData, receiveData, 3);
xl = receiveData[1];
xh = receiveData[2];Or have byte 2 just be 0xFF because the auto-increment would do what I expected.
But alas, it doesn't work. (yes address increment is turned on in register 6)
Can this be done? What am I missing?
Now for documentation, the temperature register just isn't documented in the data sheet. It took a while to figure out that it is Celcius and biased by -25C. Also, the M/S bit isn't documented either. I found AN3393 to be very useful, the data sheet, not so much.
Thanks,
Andrei from The Great White North.

回帖(5)

曾玲娟

2018-9-11 16:54:29
我假设您使用的是4线SPI接口,比多路读取操作方法更正确。但我不知道SPISend究竟能起什么作用。
最好用示波器或逻辑分析仪检查信号,看它是否与协议匹配。

以上来自于谷歌翻译


以下为原文




I assume you are using 4-wire SPI interface, than you approach for multi read operation is correct. But I don't know what exactly you function SPISend does.
It would be good to check the signal with scope or logic analyzer to see if it match with the protocol.
举报

张晓宁

2018-9-11 17:01:20
对不起,是的,你是对的,我正在使用4线SPI。
我的SPISend例程是:
 (uint8_t
* transmit,uint8_t
*收到,uint16_t
 长度) {
 HAL_StatusTypeDef
 状态;
 HAL_GPIO_WritePin(CS_I2C_SPI_GPIO_Port,CS_I2C_SPI_Pin,
GPIO_PIN_RESET
);
 
 
status = HAL_SPI_TransmitReceive(& hspi1,transmit,receive,length,100);
 
 
HAL_GPIO_WritePin(CS_I2C_SPI_GPIO_Port,CS_I2C_SPI_Pin,GPIO_PIN_SET
);
 
 
 (状态!= HAL_OK
){
 
 

''传输%d  r  n'',状态有问题);
 
 
}
}
当我发送两个字符时,模式是:
所以信号形式是可以的。在5.25 MBaud我没有嗡嗡声芯片。我正在获得的价值观是有意义的。
 
我检查了三字节版本上的波形(读取| multiple | xlow,read | xhigh,dummy)它看起来很好,没有违反,但数据没有改变。
安德烈

以上来自于谷歌翻译


以下为原文




Sorry, yes you are correct, I'm using 4 wire SPI.
My SPISend routine is:



(uint8_t
* transmit, uint8_t
* receive, uint16_t
length) {
HAL_StatusTypeDef
status;

HAL_GPIO_WritePin( CS_I2C_SPI_GPIO_Port, CS_I2C_SPI_Pin,
GPIO_PIN_RESET
);

  
status = HAL_SPI_TransmitReceive( &hspi1, transmit, receive, length, 100);

  
HAL_GPIO_WritePin( CS_I2C_SPI_GPIO_Port, CS_I2C_SPI_Pin, GPIO_PIN_SET
);

  

(status != HAL_OK
) {


   

(
''there is a problem with the transmit %drn'', status);


  
}
}

When I send two characters the pattern is:


So the signaling form is okay. At 5.25 MBaud I'm not buzzing the chip. The values that I'm getting out make sense.


I checked the wave forms on the three byte version (read | multiple | xlow, read | xhigh, dummy) and it looked good, nothing violated, but the data did not change.

Andrei
举报

张晓宁

2018-9-11 17:15:08
好的,我明白了。
根据数据手册中的时序图,位0x80是R / W位,0x40是M / S位,位0x3F是地址位。
在现实生活中,没有M / S位。该图是来自上一代其他芯片的剪切/粘贴。
要读取多个字节,可以在控制器6中设置地址增量位,然后继续发送时钟。
如果将M位设置为0x40,则突然您只是读取其他寄存器。该器件的寄存器位于0x4x-0x7x范围内,您最终只能读取它们。
所以,这个片段有效:
 
 (uint8_t
 i = 0;我< 7;我++){
 transmitData = 0;
 }
 transmitData [0] =(
uint8_t
)(LIS3DSH_READ |
LIS3DSH_X_L);
 SPISend(transmitData,receiveData,7);
 x =(
int16_t
)(receiveData [2]<< 8)| (int16_t
)receiveData [1];
 y =(
int16_t
)(receiveData [4]<< 8)| (int16_t
)receiveData [3];
 z =(
int16_t
)(receiveData [6]<< 8)| (int16_t
)receiveData [5];
来自大白北的安德烈
正如在embedded.fm播客和博客上看到的那样。

以上来自于谷歌翻译


以下为原文




Okay, I figured it out.
According to the timing diagram in the data sheet, bit 0x80 is the R/W bit, and 0x40 is the M/S bit, with bits 0x3F being the address bits.
In real life, there is no M/S bit. The diagram is a cut/paste from a previous generation of some  other chip.
To read multiple bytes, you set the address increment bit in control 6 and just keep sending clocks.
If you set the M bit 0x40, suddenly you are just reading other registers. This device has registers in the 0x4x-0x7x range, and you just end up reading them.
So, this snippet works:



(uint8_t
i = 0; i < 7; i++) {
   transmitData = 0 ;

}

transmitData[0] = (
uint8_t
) (LIS3DSH_READ |  
LIS3DSH_X_L);
SPISend( transmitData, receiveData, 7);

x = (
int16_t
) (receiveData[2] << 8) | (int16_t
) receiveData[1];
y = (
int16_t
) (receiveData[4] << 8) | (int16_t
) receiveData[3];
z = (
int16_t
) (receiveData[6] << 8) | (int16_t
) receiveData[5];
Andrei from The Great White North
As seen on the embedded.fm podcast and blog.
举报

张晓宁

2018-9-11 17:35:01
好的,在DocID022405 Rev 2中,表15显示了寄存器6的默认值,即地址递增关闭和水印中断打开。
第7.7节没有说明地址增量的默认值,但是水印中断是关闭的。
如果我没有设置地址增量位,地址仍会递增。
我认为文档有问题。

以上来自于谷歌翻译


以下为原文




Okay, in DocID022405 Rev 2, table 15 shows the default values for register 6 being address-increment being off and watermark interrupt being on.
Section 7.7 says nothing about the default for address-increment, but has watermark interrupt being off.
If I do not set the address-increment bit, the address still increments.
I think there is something wrong with the documentation.
举报

更多回帖

×
20
完善资料,
赚取积分