2025-06-25 6:44 AM - last edited on 2025-06-25 7:40 AM by Amel NASRI
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;
}
2025-06-25 7:04 AM - edited 2025-06-25 7:07 AM
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?
PS:
@alexder wrote:
HAL_SPI_Receive(&hspi1, &rxData, 2, HAL_MAX_DELAY);
Why 2 ?
2025-06-25 7:10 AM
1) separately(LED) it's working
2) this is the problem, I'm testing with LED
2025-06-25 7:14 AM
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?
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
2025-06-25 7:15 AM
that***
my board is stm32F407G-DISC1
2025-06-25 7:21 AM
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.
2025-06-25 7:34 AM - edited 2025-06-25 7:49 AM
okay, full - details:
2025-06-25 7:47 AM
You still have not:
2025-06-25 7:51 AM
okay, full - details:
2025-06-25 8:05 AM
No, you still haven't answered
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.