cancel
Showing results for 
Search instead for 
Did you mean: 

LIS2DW12 no access to registers

NuEta
Associate

Hello, 

I am using STM32H745 to setup and communicate with LIS2DW12 accelerometer via SPI 4-wires. I am trying to setup the accelerometer and I started with reading the WHO_AM_I register. It's default value is (43h) and I changed the value of the first bit to '1' so that my STM32 can read the value. 

The SPI communication is setup as follows: 

image.png

With the read and write fucntions set like this: 

 

 

 

 

HAL_StatusTypeDef spi_write_LIS2DS12(uint8_t regAddr, uint8_t *pData)
{
	HAL_StatusTypeDef ret;
	uint8_t address = regAddr & 0x7F;
	uint8_t sendData[2] = {address, *pData};
	//HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, 0);
	ret = HAL_SPI_Transmit(&hspi2, sendData, 2, 20);
	//HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, 1);
	return ret;
}
HAL_StatusTypeDef spi_read_LIS2DS12(uint8_t regAddr, uint8_t *pData)
{
    HAL_StatusTypeDef ret = 0x01;
    uint8_t address = regAddr | 0x80; // Set the Read/Write bit to 1 for read operation
	uint8_t sendData[2]= {address,0};
	uint8_t receiveData[2] = {0};
    //HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, GPIO_PIN_RESET);
    HAL_StatusTypeDef status = HAL_SPI_TransmitReceive(&hspi2, sendData, receiveData, 2, 50);
    //HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, GPIO_PIN_SET);
    *pData = receiveData[1];
    return ret;
}

 

When I observe the MISO and MOSI with a logic analyzer, I can see that good register value is sent, but I have random 0s and 1s as a return of MISO. Here is a picture of how it looks: 
Capture d'écran 2024-07-19 142744.png

I tried to add a reboot and/or soft reset before reading the WHO_AM_I registor, but it did not change much. Does anyone know what is the cause of this behaviour and how can it be fixed? 

1 ACCEPTED SOLUTION

Accepted Solutions
Federica Bossi
ST Employee

Hi @NuEta ,

As written also in datasheet the whoami is 44h:

FedericaBossi_0-1721640994577.png

 

Moreover, I suggest you to follow our PID example to implement the readings of LIS2DW12. Let me know if this helps.

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

View solution in original post

3 REPLIES 3
Federica Bossi
ST Employee

Hi @NuEta ,

As written also in datasheet the whoami is 44h:

FedericaBossi_0-1721640994577.png

 

Moreover, I suggest you to follow our PID example to implement the readings of LIS2DW12. Let me know if this helps.

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

I am communicating through SPI thanks to HAL_transmit functions
I don't understand how to implement what you gave me with my actual code

Is this function I don't understand what should be *ctx

int32_t __weak lis2ds12_read_reg(const stmdev_ctx_t *ctx, uint8_t reg,
                                 uint8_t *data,
                                 uint16_t len)
{
  int32_t ret;

  if (ctx == NULL)
  {
    return -1;
  }

  ret = ctx->read_reg(ctx->handle, reg, data, len);

  return ret;
}