2023-11-02 04:28 AM - edited 2023-11-02 05:30 AM
Hi,
I readed the default value of the identification register in H3LIS331DL by SPI mode and it responded with 0x32h as per the data sheet,but while reading the STATUS REG default value it responded with 0xFFh instead of 0x00h. How it's possible one register responding with correct data as per data sheet,but another one with incorrect data and for your reference see my code below.
//Address deceleration.
uint16_t Who_am_i=0x8F00;
uint16_t STATUS_REG=0xA700;
//Variable deceleration.
char Status_Reg;
char Identification;
// Implementation part in While loop
HAL_GPIO_WritePin(CS_GPIO_Port, CS_Pin, GPIO_PIN_RESET);
HAL_SPI_Transmit(&hspi1,(uint8_t*) &Who_am_i, 1, 1000);
HAL_SPI_Receive(&hspi1, (uint8_t*)&Identification, 1, 1000);
HAL_GPIO_WritePin(CS_GPIO_Port, CS_Pin, GPIO_PIN_SET);
uart_buf_len = sprintf(uart_buf,"Identification = 0x%02X\r\n", (unsigned int)Identification);
HAL_UART_Transmit(&huart2, (uint8_t*)uart_buf,uart_buf_len, 100);
HAL_GPIO_WritePin(CS_GPIO_Port, CS_Pin, GPIO_PIN_RESET);
HAL_SPI_Transmit(&hspi1,(uint8_t*) &STATUS_REG, 1, 1000);
HAL_SPI_Receive(&hspi1, (uint8_t*)&Status_Reg, 1, 1000);
HAL_GPIO_WritePin(CS_GPIO_Port, CS_Pin, GPIO_PIN_SET);
uart_buf_len = sprintf(uart_buf,"Status_Reg = 0x%02X\r\n", (unsigned int)Status_Reg);
HAL_UART_Transmit(&huart2, (uint8_t*)uart_buf,uart_buf_len, 100);
output
Identification = 0x32
Status_Reg = 0xFF
Thank you
2023-11-02 04:08 AM
Hi,
I'm Working with a project which requires impact detection.I have readed the raw data from the H3LIS331DL module,but what's the proper way to get the motion detection from the raw data.
Thank you
2023-11-02 04:40 PM - edited 2023-11-02 04:53 PM
Hello,
Please consult the std c driver provided by STM32 on their GitHub.
https://github.com/STMicroelectronics/h3lis331dl-pid/tree/d2404b332f7ba6f517b6b959e09014d429cac9ae
In the example section you'll see how it is implemented properly.
Regards.