Skip to main content
Visitor II
June 25, 2025
Question

Problem with LIS3DSH

  • June 25, 2025
  • 3 replies
  • 804 views

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;
}

 

    This topic has been closed for replies.

    3 replies

    Super User
    June 25, 2025

    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 ?

    alexderAuthor
    Visitor II
    June 25, 2025

    1) separately(LED) it's  working 

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

    Super User
    June 25, 2025

    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 

    alexderAuthor
    Visitor II
    June 25, 2025

    that***

    my board is stm32F407G-DISC1

    Super User
    June 25, 2025

    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.

    alexderAuthor
    Visitor II
    June 25, 2025

    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