2026-04-16 5:58 PM
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);
2026-04-17 1:25 AM
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.
2026-04-18 12:51 AM
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)