MPU9250
MPU9250 copied to clipboard
STM32 SPI READ NOT RIGHT
Hi,In function MPU_SPI_Read(), line: HAL_SPI_Receive(&MPU9250_SPI, pBuffer, NumByteToRead, HAL_MAX_DELAY); need read one more byte ,as spi read dump byte , pBuffer[1] as first read byte. Please check it ,Thanks.
we can test like below uint8_t MPU_SPI_Write(uint8_t *pBuffer, uint8_t WriteAddr, uint16_t NumByteToWrite) {
MPU9250_Activate();
if (HAL_SPI_Transmit(&MPU9250_SPI, (uint8_t*) &WriteAddr, 1, HAL_MAX_DELAY)
!= HAL_OK)
{
return -1;
}
if (HAL_SPI_Transmit(&MPU9250_SPI, pBuffer, NumByteToWrite, HAL_MAX_DELAY) != HAL_OK)
{
return -1;
}
MPU9250_Deactivate();
return 0;
}
uint8_t MPU_SPI_Read(uint8_t *pBuffer, uint8_t ReadAddr, uint16_t NumByteToRead) { MPU9250_Activate(); uint8_t data = ReadAddr | READWRITE_CMD;
if (HAL_SPI_TransmitReceive(&MPU9250_SPI, &data, pBuffer, 1, HAL_MAX_DELAY)
!= HAL_OK)
{
return -1;
}
if (HAL_SPI_Receive(&MPU9250_SPI, pBuffer, NumByteToRead, HAL_MAX_DELAY) != HAL_OK)
{
return -1;
}
MPU9250_Deactivate();
return 0;
}
Could you please make a pull request? As I've started this as a hobby project when I had free time, now I do not.