Thank you kgoveas, you helped me to focus on the correct part of code where to search for the problem and I finally fixed it. This is the correct write function: int8_t bm_spi_write(uint8_t dev_addr, uint8_t reg_addr, const uint8_t *data, uint16_t len) {
UNUSED(dev_addr);
if( len > (SPI_BUFF_SZ-1) ) {
Error_Handler();
}
uint8_t txarr[SPI_BUFF_SZ] = { reg_addr };
memcpy(txarr + 1, data, len);
HAL_GPIO_WritePin(SPI_CS_N_GPIO_Port, SPI_CS_N_Pin, GPIO_PIN_RESET);
HAL_StatusTypeDef status = HAL_SPI_Transmit(hspi_bmi, txarr, len+1, COMM_DELAY);
HAL_GPIO_WritePin(SPI_CS_N_GPIO_Port, SPI_CS_N_Pin, GPIO_PIN_SET);
return (status == HAL_OK ? BMI2_OK : BMI2_E_COM_FAIL);
} A silly "+1" for the writing buffer lenght was missing in the "HAL_SPI_Transmit" calling. Best regards, Walter
... View more