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? 

0 REPLIES 0