MPU6050 raw z-axis data is always zero

61 Views Asked by At

I am using MPU9250 for my projects. From datasheet I could see I need to read 6 bytes to get the accelerometer data. The 5th and 6th byte corresponds to z-axis high byte data and z-axis low byte data. I could see that for x-axis and y-axis I am getting some non-zero values and they are even changing. But for z-axis the two byes are always zero. I am using SPI to read the data and I am using STM32F446RE for my project.

**Raw accelerometer data:**
 *19, 116, 253, 108, 0, 0
 22, 128, 253, 120, 0, 0
 34, 100, 253, 68, 0, 0*

Code to read data using SPI:

uint8_t raw_data[6];
/* 59 is the address of register and 0b10000000 is to mention that we want to read the data from the register*/
uint8_t temp_data = 0b10000000|59;  
HAL_GPIO_WritePin(SPI_CS_GPIO_Port, SPI_CS_Pin, GPIO_PIN_RESET);
HAL_SPI_Transmit(&hspi1, &temp_data, 1, 100);
HAL_SPI_Receive(&hspi1, raw_data, 6, 100);
HAL_GPIO_WritePin(SPI_CS_GPIO_Port, SPI_CS_Pin, GPIO_PIN_SET);

I need help to understand why I am getting raw values as always zero for z-axis. Could someone explain me whether I am doing anything wrong in the way I am reading the data?

0

There are 0 best solutions below