cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with LIS3DSH

alexder
Visitor

Hello, it's code correct for  testing WHO_I_AM? LED doesn't work 

#define LIS3DH_CS_LOW()  HAL_GPIO_WritePin(GPIOE, GPIO_PIN_3, GPIO_PIN_RESET)
#define LIS3DH_CS_HIGH() HAL_GPIO_WritePin(GPIOE, GPIO_PIN_3, GPIO_PIN_SET)
#define LIS3DH_WHO_AM_I_REG  0x0F
#define LIS3DH_READ_CMD      0x80
uint8_t LIS3DH_ReadWhoAmI(void)
{
    uint8_t txData = LIS3DH_WHO_AM_I_REG | LIS3DH_READ_CMD;
    uint8_t rxData = 0;

    LIS3DH_CS_LOW();
    HAL_SPI_Transmit(&hspi1, &txData, 1, HAL_MAX_DELAY);
    HAL_SPI_Receive(&hspi1, &rxData, 2, HAL_MAX_DELAY);
    LIS3DH_CS_HIGH();

    if (rxData == 0x33) {
           HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12, GPIO_PIN_SET);


}
  return rxData;
}

 

9 REPLIES 9
Andrew Neil
Super User

Welcome to the forum,

We need further details of your setup - see How to write your question to maximize your chances to find a solution .

 


@alexder wrote:

LED doesn't work 


So what investigation/testing/debugging have you done to find out why it doesn't work?

  • Can you just turn the LED on/off separately from any accelerometer code ?
  • Are you getting the WHO_AM_I value?
  • Have you checked the SPI lines with an oscilloscope and/or analyser to see what's happening?

 

PS:

 


@alexder wrote:
    HAL_SPI_Receive(&hspi1, &rxData, 2, HAL_MAX_DELAY);

Why 2 ?

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.
alexder
Visitor

1) separately(LED) it's  working 

2) this is the problem, I'm testing with  LED

You still haven't given any details of your setup!

Again, please see  How to write your question to maximize your chances to find a solution.

 

So what investigation/testing/debugging have you done to find out why it doesn't work?

  • Are you getting the WHO_AM_I value?
  • Have you checked the SPI lines with an oscilloscope and/or analyser to see what's happening?

 

    HAL_SPI_Receive(&hspi1, &rxData, 2, HAL_MAX_DELAY);

Why 2 ?

 

Have you looked at C-Driver-MEMS ?

https://www.st.com/en/embedded-software/c-driver-mems.html 

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.
alexder
Visitor

that***

my board is stm32F407G-DISC1

It's really difficult when you just drip-feed information like this.

Please provide full details, as described in How to write your question to maximize your chances to find a solution:

1. [Part Number] Always state the FULL Part Number of the product used <-- now done, thanks.

2. [Environment] Describe the environment used as toolchain and hardware and state the version used.
3. [Schematics] If it is a custom board --> Share the schematics using “Attach file” option or inserting some image.
4. [Details] Describe the symptoms observed (examples: error messages, wrong behavior, screenshots of signals…).
5. [Expected behavior] If the question is related to performance then what is the target.
6. [How to reproduce] Detail the steps you have taken to get the behavior seen and clarify the set-up [Input, Output].
7. [Occurrence] Is the problem systematic? If not, state the frequency.
8. [Sanity checks] What are the checks that you have already performed (example: Have you reviewed the existing examples - GitHub, Cube...).

 

Please take time to consider all the questions asked so far, and give a full reply.

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

okay,  full - details:

  • STM32F407G-DISC1
  • STM32CubeIDE, STM32MX
  • LED doesn't working when,  if ( == 0x33)  this means that the result is not returned, i think it's problem with code or  LIS3DSH
  • -
  • STM32CubeIDE, -  0 errors
  • -
  • i trying , BSP driver - same
  • bsp driver i found only, for old revision, if there is, can you provide a link

 

 

 

You still have not:

  1. Given version details of the tools.

  2. Showed how you have the LIS3DSH connected to the Disco board:
    Show schematic;
    Is the LIS3DSH on a breakout board? Is so, give details; link to manufacturer's page;
    Some good, clear photos would help.
     
  3. Answered whether you get the WHO_AM_I value from the sensor - or, in fact, any value..
     
  4. Described any investigation/debugging that you've done to find the problem;
    eg, check the SPI lines with an oscilloscope and/or analyser to see what's happening
A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

okay,  full - details:

  • STM32F407G-DISC1
  • STM32CubeIDE, STM32MX
  • LED doesn't working when,  if ( == 0x33)  this means that the result is not returned, i think it's problem with code or  LIS3DSH
  • -
  • STM32CubeIDE, -  0 errors
  • -
  • i trying , BSP driver - same
  • bsp driver i found only, for old revision, if there is, can you provide a link

No, you still haven't answered 

AndrewNeil_0-1750863555946.png

 

Remember that we know nothing about you or your project other than what you clearly describe in your post.

Be clear.

Be complete.

Give details - don't leave us guessing.

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.