cancel
Showing results for 
Search instead for 
Did you mean: 

LSM6DSL SPI read as in tsw-fcu001.html

MK..1
Associate III

Hi

I was looking at how a register read works for LSM6DSL

https://www.st.com/en/embedded-software/stsw-fcu001.html

I found the function below. Does the number/amount of __asm("dsb\n") correspond to SPI clk?

Is there no easier way to do this? Like using HAL_SPI_TransmitReceive(...)?

 

/**

* @brief This function reads a single byte on SPI 3-wire.

* @param xSpiHandle : SPI Handler.

* @param val : value.

* @retval None

*/

void SPI_Read(SPI_HandleTypeDef* xSpiHandle, uint8_t *val)

{

/* In master RX mode the clock is automaticaly generated on the SPI enable.

So to guarantee the clock generation for only one data, the clock must be

disabled after the first bit and before the latest bit */

/* Interrupts should be disabled during this operation */

 

__disable_irq();

//GPIOA->BSRR = (uint32_t)GPIO_PIN_8 << 16U;

__HAL_SPI_ENABLE(xSpiHandle);

__asm("dsb\n");__asm("dsb\n");

__asm("dsb\n");__asm("dsb\n");

__asm("dsb\n");__asm("dsb\n");

__asm("dsb\n");__asm("dsb\n");

__asm("dsb\n");__asm("dsb\n");

__asm("dsb\n");__asm("dsb\n");

__asm("dsb\n");__asm("dsb\n");

__asm("dsb\n");__asm("dsb\n");

__asm("dsb\n");__asm("dsb\n");

__asm("dsb\n");__asm("dsb\n");

__asm("dsb\n");__asm("dsb\n");

__asm("dsb\n");__asm("dsb\n");

__asm("dsb\n");__asm("dsb\n");

__asm("dsb\n");__asm("dsb\n");

__asm("dsb\n");__asm("dsb\n");

__asm("dsb\n");__asm("dsb\n");

__asm("dsb\n");__asm("dsb\n");

__asm("dsb\n");__asm("dsb\n");

__asm("dsb\n");__asm("dsb\n");

__asm("dsb\n");__asm("dsb\n");

__asm("dsb\n");__asm("dsb\n");

__asm("dsb\n");__asm("dsb\n");

__asm("dsb\n");__asm("dsb\n");

__asm("dsb\n");__asm("dsb\n");

__asm("dsb\n");__asm("dsb\n");

__asm("dsb\n");__asm("dsb\n");

__asm("dsb\n");__asm("dsb\n");

__asm("dsb\n");__asm("dsb\n");

__asm("dsb\n");__asm("dsb\n");

__asm("dsb\n");

__asm("dsb\n");

__asm("dsb\n");

__asm("dsb\n");

__asm("dsb\n");

__asm("dsb\n");

__asm("dsb\n");

__asm("dsb\n");

__asm("dsb\n");

__HAL_SPI_DISABLE(xSpiHandle);

 

__enable_irq();

 

while ((xSpiHandle->Instance->SR & SPI_FLAG_RXNE) != SPI_FLAG_RXNE);

/* read the received data */

*val = *(__IO uint8_t *) &xSpiHandle->Instance->DR;

while ((xSpiHandle->Instance->SR & SPI_FLAG_BSY) == SPI_FLAG_BSY);

}

 

0 REPLIES 0