2018-02-05 02:46 PM
After initializing an SPI 3-wire interface with a STM32L4 MCU on a custom board, the driver always returns zero as the pressure value whenever the get pressure method is called. Even the temperature sensor reading is also returning zero as output. Is this an initialization error or calibration error?
#stm32l4-spi #lps22hb2018-02-05 11:40 PM
Hello,
Do you have a logic analyzer to verify you send the data to the sensor and get the data back correctly?
Have you started the measurement in the sensor?
Could you share your code?
David
2018-02-06 07:47 AM
Hi David,
I don't have a logic analyzer to verify the data. I ported the code from en.x-cube-mems1 expansion package. The sensor is initialized in the 3-wire SPI mode. The pseudo code for initialization and sensor measurement is below
BSP_PRESSURE_Init( PRESSURE_SENSORS_AUTO, &PRESSURE_handle );
BSP_PRESSURE_Sensor_Enable(PRESSURE_handle);
if(BSP_PRESSURE_IsEnabled(PRESSURE_handle, &status) == COMPONENT_OK && status == 1)
{BSP_PRESSURE_Get_Press(PRESSURE_handle, &PRESSURE_Value);
}
2018-02-06 12:54 PM
I suppose the problem is in the SPI 3-wire settings of you microcontroller not in the sensor, it can be tricky and difficult to debug witnout scope or logic analyzer.
I would recomend you to double check your SPI configuration or rather use I2C at firts.
2018-02-06 01:06 PM
This is my SPI configuration
SENSORTILE_SENSORS_SPI_CLK_ENABLE();
SENSORTILE_SENSORS_SPI_GPIO_CLK_ENABLE(); GPIO_InitStruct.Pin = SENSORTILE_SENSORS_SPI_MOSI_Pin; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; GPIO_InitStruct.Alternate = GPIO_AF5_SPI2; HAL_GPIO_Init(SENSORTILE_SENSORS_SPI_Port, &GPIO_InitStruct); GPIO_InitStruct.Pin = SENSORTILE_SENSORS_SPI_SCK_Pin; GPIO_InitStruct.Pull = GPIO_PULLUP; HAL_GPIO_Init(SENSORTILE_SENSORS_SPI_Port, &GPIO_InitStruct); SPI_Sensor_Handle.Instance = SENSORTILE_SENSORS_SPI; SPI_Sensor_Handle.Init.Mode = SPI_MODE_MASTER; SPI_Sensor_Handle.Init.Direction = SPI_DIRECTION_1LINE; SPI_Sensor_Handle.Init.DataSize = SPI_DATASIZE_8BIT; SPI_Sensor_Handle.Init.CLKPolarity = SPI_POLARITY_HIGH; SPI_Sensor_Handle.Init.CLKPhase = SPI_PHASE_2EDGE; SPI_Sensor_Handle.Init.NSS = SPI_NSS_SOFT; // SPI_Sensor_Handle.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16; // 5 MHz SPI_Sensor_Handle.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_32; // 2.5MHz SPI_Sensor_Handle.Init.FirstBit = SPI_FIRSTBIT_MSB; SPI_Sensor_Handle.Init.TIMode = SPI_TIMODE_DISABLED; SPI_Sensor_Handle.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED; SPI_Sensor_Handle.Init.CRCPolynomial = 7; SPI_Sensor_Handle.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE; SPI_Sensor_Handle.Init.NSSPMode = SPI_NSS_PULSE_DISABLED; HAL_SPI_Init(&SPI_Sensor_Handle); SPI_1LINE_TX(&SPI_Sensor_Handle); __HAL_SPI_ENABLE(&SPI_Sensor_Handle);all the defines have been changed to reflect the correct pins on my custom board. Does this initialize the
SPI 3-wire settings of the MCU correctly ?