cancel
Showing results for 
Search instead for 
Did you mean: 

LIS3DH, x-axis is stuck with spi mode3 but working with mode1

arturdav87
Associate II
Posted on December 28, 2015 at 06:58

MCU: STM32F429NHi. I know from datasheet that spi should be configured as mode3 (CPOL=1, CPHA=1), but its working only with mode 1 (CPOL=0, CPHA=1)

In mode 3 -  x-axis is stuck with value: -32624. 

Someone know the problem?

spi config: 

 Accl_SpiHandle.Instance               = SPI4;

 Accl_SpiHandle.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16; //2.8Mhz (MAX from datasheet is 10MHz)

 Accl_SpiHandle.Init.Direction         = SPI_DIRECTION_2LINES; // Need bidirectional here for read and write.

      Accl_SpiHandle.Init.Mode = SPI_MODE_MASTER; // Stm32f4 should be the master

 Accl_SpiHandle.Init.DataSize          = SPI_DATASIZE_8BIT; // we send 8 Bits

 Accl_SpiHandle.Init.NSS               = SPI_NSS_SOFT; // Chip select hardware/software - set this to software.

 Accl_SpiHandle.Init.FirstBit          = SPI_FIRSTBIT_MSB; // Starting with MSB - (Datatsheet p.22 - Read and write protocol)

 Accl_SpiHandle.Init.CLKPolarity       = SPI_POLARITY_LOW; // Clock polarity- the base value of the clock is one (Datatsheet p.22 - Read and write protocol)

 Accl_SpiHandle.Init.CLKPhase          = SPI_PHASE_2EDGE; // Data should be captured at the rising edge of SPC and data is output on a falling edge.

 HAL_SPI_Init(&Accl_SpiHandle);

}

MEMS config:

int memsSensor_Initialize(void) {

//set Output data rate in normal mode

if (!LIS3DH_SetODR(LIS3DH_ODR_50Hz))

return eERROR;

//set Power Mode as normal(turn ON device) (not power save)

if (!LIS3DH_SetMode(LIS3DH_NORMAL))

return eERROR;

//set axis Enable

if (!LIS3DH_SetAxis(LIS3DH_X_ENABLE | LIS3DH_Y_ENABLE | LIS3DH_Z_ENABLE))

return eERROR;

//set Fullscale measurement range of ±2g.

if (!LIS3DH_SetFullScale(LIS3DH_FULLSCALE_2))

return eERROR;

}
0 REPLIES 0