HTS221 with Half duplex SPI
Hello,
I'm currently programing a self designed sensor node with a HTS221. I've decided to use SPI to communicate with it (SPI half-duplex master)
Here are the settings:
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_1LINE;
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_256;
hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi2.Init.TIMode = SPI_TIMODE_DISABLE;
hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi2.Init.CRCPolynomial = 7;
hspi2.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
hspi2.Init.NSSPMode = SPI_NSS_PULSE_DISABLE;
if (HAL_SPI_Init(&hspi2) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN SPI2_Init 2 */
/* USER CODE END SPI2_Init 2 */
}Since I couldn't get the content of the WHO_I_AM register, I decided to check the exchanges with my oscilloscope.
I discovered that the CLK level was between 1V and 200mV. And due to some poor design choices, this line take some noise from the SWDCLK.
Here is the way I (try) to communicate with it:
status = HAL_SPI_Transmit(&hspi2, (uint8_t*)&spiTX,1,1000);
if (status != HAL_OK){
//printf(status);
printf("PROBLEM");
}
HAL_Delay(10);
HAL_SPI_Receive(&hspi2, (uint8_t*)&spiRX,1,1000);
if (status != HAL_OK){
//printf(status);
printf("PROBLEM");
}I would like to know if there is something I missed. After some researches, I realised that half duplex SPI seem to be subject to some turnarounds for some designers.
Thank you
