cancel
Showing results for 
Search instead for 
Did you mean: 

SPI MISO not working with LIS2DUX12

sespinoza_toro
Associate II

I've been using a nucleo l476rg with a LIS2DUX12 sensor and I need to use the SPI protocol, but came as a surprise that the MISO line is not working. When it's not getting 0xFF (should be 0x47), gets inconsistent values. Tried changing CPHA, CPOL, prescale and none of that is working.

// 1. Tx and Rx arrays
  uint8_t tx_wakeup[2] = {0x3E, 0x01}; // Register 0x3E, value0x01 (Soft Power-Down)
  uint8_t tx_whoami[2] = {0x8F, 0x00}; // Read 0x0F (WHO_AM_I)
  uint8_t rx_buffer[2] = {0x00, 0x00};
  char msg[50];

  HAL_Delay(100);

  // Wake up sequence
  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, GPIO_PIN_RESET);
  HAL_SPI_Transmit(&hspi1, tx_wakeup, 2, 100);
  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, GPIO_PIN_SET);

  // Read who_am_i
  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, GPIO_PIN_RESET);
  //HAL_SPI_TransmitReceive(&hspi1, tx_whoami, rx_buffer, 2, 100);
  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, GPIO_PIN_SET);

  // print data
  sprintf(msg, "WHO_AM_I = 0x%02X\r\n", rx_buffer[1]);
  HAL_UART_Transmit(&huart2, (uint8_t*)msg, strlen(msg), 100);

 

miso_error.png

2 REPLIES 2
Saket_Om
ST Employee

Hello @sespinoza_toro 

As indicated in the device specification, after power-on the device requires a startup delay of 25 ms before any operation can be performed.
Therefore, please ensure that a 25 ms delay is added after power-on before attempting communication or register access.

Saket_Om_0-1776414323142.png

 

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
Saket_Om

I'm already considering that (and also, though i commented line 16 in the post, in my code that line is running and returning hal_ok)