已回答假定已回答

Adxl362读取数据错误,读取的时序是没有问题的,但是返回的值就是不正确,是什么原因?

KevinChen000 在 2018-5-17 詢問的問題

时序图如上,读取PART ID 返回0xF0。从时序可以看到依次写入的是0x0B,0x02,后返回了0xF0。这是什么问题,求解答?

 

配置代码:

  hspi1.Instance = SPI1;

  hspi1.Init.Mode = SPI_MODE_MASTER;

  hspi1.Init.Direction = SPI_DIRECTION_2LINES;

  hspi1.Init.DataSize = SPI_DATASIZE_8BIT;

  hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;

  hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;

  hspi1.Init.NSS = SPI_NSS_SOFT;

  hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8;

  hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;

  hspi1.Init.TIMode = SPI_TIMODE_DISABLE;

  hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;

  hspi1.Init.CRCPolynomial = 10;

  if (HAL_SPI_Init(&hspi1) != HAL_OK)

  {

    _Error_Handler(__FILE__, __LINE__);

  }

引脚初始化:

 

  hspi1.Instance = SPI1;

  hspi1.Init.Mode = SPI_MODE_MASTER;

  hspi1.Init.Direction = SPI_DIRECTION_2LINES;

  hspi1.Init.DataSize = SPI_DATASIZE_8BIT;

  hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;

  hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;

  hspi1.Init.NSS = SPI_NSS_SOFT;

  hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8;

  hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;

  hspi1.Init.TIMode = SPI_TIMODE_DISABLE;

  hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;

  hspi1.Init.CRCPolynomial = 10;

  if (HAL_SPI_Init(&hspi1) != HAL_OK)

  {

    _Error_Handler(__FILE__, __LINE__);

  }

 

读取:

 

uint8_t rd_addr = 0;

  uint8_t reg_cmd = 0;

  rd_addr = registerAddress;

  ADXL362_ENABLE();

  //HAL_Delay(2);

  reg_cmd = ADXL362_READ_REG;

  HAL_SPI_Transmit(&hspi1, &reg_cmd, 1, 1000);

  HAL_SPI_Transmit(&hspi1, &rd_addr, 1, 1000);

  HAL_SPI_Receive(&hspi1, pReadData, bytesNumber, 1000);

  //HAL_Delay(200);

  ADXL362_DISABLE();

 

附件为逻辑分析仪捕捉的时序图。

附件

結果