cancel
Showing results for 
Search instead for 
Did you mean: 

LIS2DS12 no access to register value

NuEta
Associate

Hello, 

I am using STM32H745 to setup and communicate with LIS2DS12 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: 

NuEta_0-1721642980728.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: 

NuEta_1-1721642980721.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? 

3 REPLIES 3
TDK
Guru

The MOSI line first byte is 0b10101110 which is a read of register 0x2E. That's not the WHO_AM_I register. The WHO_AM_I register is at 0x0F.

TDK_0-1721654216167.png

You should also uncomment the CS line commands. Not using them can get you out of sync with the chip.

If you feel a post has answered your question, please click "Accept as Solution".

Here is a better screenshot of the logic anlyzer when a query for the WHO_AM_I register is sent: 

image.png

In this configuration, MISO is not reading the value of the WHO_AM_I register. Am I supposed to send another address through MOSI to get the correct return information?

CS line is commented because I setup for the hardware (STM32H745) to manage the connection. If I uncomment it, my sending information are not correct and I know that for sure I can not read the WHO_AM_I register, as in screenshot below. 

Picture2.png

Toggling a GPIO should work as expected. If it doesn't, perhaps the pin isn't configured, or is hooked up to something else, or isn't what you're monitoring.

What you're doing should work. Send two bytes and the second received byte has the response.

If you feel a post has answered your question, please click "Accept as Solution".