cancel
Showing results for 
Search instead for 
Did you mean: 

Receive only 0xFF from LIS3DSH

Nijat Hasanov
Associate II
Posted on December 08, 2017 at 06:00

 

 

The original post was too long to process during our migration. Please click on the attachment to read the original post.
1 ACCEPTED SOLUTION

Accepted Solutions
Nijat Hasanov
Associate II
Posted on December 11, 2017 at 19:30

Oh!! Finally, the problem is solved just by 3 lines of code:

SPI_send(0x25,0x90);

SPI_send(0x23,0x01);

SPI_send(0x20,0x67);

I think 'force reboot'ing solved my problem(first bit of register 0x25). Now it is working even if I comment it out. Strange. Really, I changed nothing else. I have been writing to 0x20 and 0x23 registers but I had not seen anything about 0x25.

View solution in original post

8 REPLIES 8
Miroslav BATEK
ST Employee
Posted on December 09, 2017 at 10:39

Are you able to capture the SPI communication usign scope or logic analyzer?

It would be very handy to see what os going on the SPI bus.
Posted on December 09, 2017 at 18:45

Hi! I tried to see MOSI and MISO signals. There was something on MOSI line, but MISO line was like pulled up high. I think that's why it gives me ones. Could it be some problem of HAL libraries? I can't seem to find HAL version example for LIS3DSH.

Posted on December 11, 2017 at 15:20

To solve the problem I recommend to investigate more the SPI communication with scope or logic analyzer. First you must be sure that the microcontroler sends correctly the data, only than the slave (sensor) can reply. You can check the most simple read who_am_i procedure, the sensor must respond to this request. If you will share the communication I can check it.

I suppose the problem is in the SPI configuration or in HW connection.

Posted on December 11, 2017 at 16:46

Yes, I also think the problem is in config. I tried exactly the code by Andrei Chichak to read WHO_I_AM register.

void

SPISend

(

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

);

 

if

(status !=

HAL_OK

) {

   

printf

(

'there is a problem with the transmit %d\r\n'

, status);

 

}

}

It gives the same dummy byte to me. I mean I set rx[0],rx[1] to 0. And after SPISend both of them will be 255. Do you think the reason might be that I am not using external clock? I don't use HSE. I set my clock speed to 16MHz.

Unfortunately, right now I can't analyze the signals to share them with you.

Posted on December 11, 2017 at 18:04

The big question is: Why my MISO pin is always high?

Is it related to configuration? Or should I write something to lis3dsh before it uses the MISO line?

Nijat Hasanov
Associate II
Posted on December 11, 2017 at 19:30

Oh!! Finally, the problem is solved just by 3 lines of code:

SPI_send(0x25,0x90);

SPI_send(0x23,0x01);

SPI_send(0x20,0x67);

I think 'force reboot'ing solved my problem(first bit of register 0x25). Now it is working even if I comment it out. Strange. Really, I changed nothing else. I have been writing to 0x20 and 0x23 registers but I had not seen anything about 0x25.

Ahmed  Ben Amara
Associate II
Posted on May 09, 2018 at 23:44

I also have the same problem however my communication with Lis3dsh works fine all the time and suddenly the SPI communication stucks i tried to send reset cmd use the solution given above but still have the same issue until i un-power and power the Lis3dsh again. i tried to slower the clk (i use 2M i tried 1M and even 500K) but no response i always read 0xff if i do not use the hardware reset by unpower and power the Lis3dsh.

Is there any explication about this issue or is there any software solution for it.I will be thankful if someone help me.

Posted on May 16, 2018 at 10:44

Could someone help me please still have the same issue