Hi,
I'm currently using the STM32F103 SPI to read the MKI194V1, but I've noticed that the ID I'm reading is always 0x4A. Could you please help me check if there's an issue, or provide any sample code?
I also take a photo of the MKI194V1. The marking on the surface I think is SR 934
// SPI Initial
void MX_SPI2_Init(void)
{
/* USER CODE BEGIN SPI2_Init 0 */
/* USER CODE END SPI2_Init 0 */
/* USER CODE BEGIN SPI2_Init 1 */
/* USER CODE END SPI2_Init 1 */
hspi2.Instance = SPI2;
hspi2.Init.Mode = SPI_MODE_MASTER;
hspi2.Init.Direction = SPI_DIRECTION_2LINES;
hspi2.Init.DataSize = SPI_DATASIZE_8BIT;
hspi2.Init.CLKPolarity = SPI_POLARITY_HIGH;
hspi2.Init.CLKPhase = SPI_PHASE_2EDGE;
hspi2.Init.NSS = SPI_NSS_SOFT;
hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16;
hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi2.Init.TIMode = SPI_TIMODE_DISABLE;
hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi2.Init.CRCPolynomial = 10;
if (HAL_SPI_Init(&hspi2) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN SPI2_Init 2 */
/* USER CODE END SPI2_Init 2 */
}
// Write data to Register
void LSM6DSR_Core_Write_Reg(TYPE_U08 U08_Reg, TYPE_U08 U08_Val)
{
TYPE_U08 AxU08_TxBuf[2];
SPI_MKI194_CS_LOW();
AxU08_TxBuf[0] = U08_Reg;
AxU08_TxBuf[1] = U08_Val;
HAL_SPI_Transmit(&hspi2, AxU08_TxBuf, 2,1000);
SPI_MKI194_CS_HIGH();
}
// Read One Register
TYPE_U08 LSM6DSR_Core_Read_Reg(TYPE_U08 U08_Reg)
{
TYPE_U08 AxU08_Ret;
U08_Reg |= 0x80;
SPI_MKI194_CS_LOW();
HAL_SPI_Transmit(&hspi2, &U08_Reg, 1,1000);
HAL_SPI_Receive(&hspi2, &AxU08_Ret, 1,1000);
SPI_MKI194_CS_HIGH();
return AxU08_Ret;
}
// Read All Registers
void LSM6DSR_Core_Read_All(void)
{
TYPE_U08 AxU08_i;
for(AxU08_i = 1 ; AxU08_i < 0x7E ; AxU08_i++)
{
U08_Reg[AxU08_i] = 0x00;
U08_Reg[AxU08_i] = LSM6DSR_Core_Read_Reg(AxU08_i);
}
}