cancel
Showing results for 
Search instead for 
Did you mean: 

Incorrect SPI bus response?

IDili.1
Associate

When trying to read the "who am I" register from different mpu9250 sensors, the decimal response of the bus is 226 or 230, which corresponds to the datasheet if devision the answers to two: 113 (0x71) and 115 (0x73) why?

Read Function:

uint8_t mpu9250_spi_read_8 (uint8_t addr)
    {
    	uint8_t reg = 0, val = 0; reg = addr|0x80;
     
    	CS_ON;
     
    	HAL_SPI_Transmit_DMA(&hspi2, &reg, 1 );
     
    	while (HAL_SPI_GetState(&hspi2) != HAL_SPI_STATE_READY);
     
    	HAL_SPI_Receive_DMA(&hspi2, val, 1);
     
    	while (HAL_SPI_GetState(&hspi2) != HAL_SPI_STATE_READY);
     
    	CS_OFF;
     
    	return val;
     
    }

Function init SPI:

static 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 */
      /* SPI2 parameter configuration*/
      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_LOW;
      hspi2.Init.CLKPhase = SPI_PHASE_1EDGE;
      hspi2.Init.NSS = SPI_NSS_SOFT;
      hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_32;
      hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;
      hspi2.Init.TIMode = SPI_TIMODE_DISABLE;
      hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
      hspi2.Init.CRCPolynomial = 0x0;
      hspi2.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
      hspi2.Init.NSSPolarity = SPI_NSS_POLARITY_LOW;
      hspi2.Init.FifoThreshold = SPI_FIFO_THRESHOLD_01DATA;
      hspi2.Init.TxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
      hspi2.Init.RxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
      hspi2.Init.MasterSSIdleness = SPI_MASTER_SS_IDLENESS_00CYCLE;
      hspi2.Init.MasterInterDataIdleness = SPI_MASTER_INTERDATA_IDLENESS_00CYCLE;
      hspi2.Init.MasterReceiverAutoSusp = SPI_MASTER_RX_AUTOSUSP_DISABLE;
      hspi2.Init.MasterKeepIOState = SPI_MASTER_KEEP_IO_STATE_DISABLE;
      hspi2.Init.IOSwap = SPI_IO_SWAP_DISABLE;
      if (HAL_SPI_Init(&hspi2) != HAL_OK)
      {
        Error_Handler();
      }
      /* USER CODE BEGIN SPI2_Init 2 */
     
      /* USER CODE END SPI2_Init 2 */
     
    }

 Got some debug results:

0693W000008wDbXQAU.png 

The receive buffer contains the correct data but the result is zero, looks like an error in the TransmissionReceive method?

0 REPLIES 0