Hello, Can anyone please help me in Low level(LL) SPI driver for STM32F7 microcontroller?
I have been trying to establish an SPI communication using STM32F7 microcontroller using Low level drivers in STM32CubeMX. I am facing issue Reading from the DR register. I need to read 8-bits but the values are getting stored as 16-bits. Also the DR register is getting update only after transmitting the command 3 times.
This is the SPI driver which I have written.
void SPITransmitData(char *p8Data, int i16Length)
{
while(SET == LL_SPI_IsActiveFlag_BSY(SPI2);
do
{
while(RESET == LL_SPI_IsActiveFlag_TXE(SPI2);
LL_SPI_TransmitData8(SPI2, *p8Data++);
i16Length--;
}while(i16Length != 0);
while(SET == LL_SPI_GetTxFIFOLevel(SPI2);
while(SET == LL_SPI_GetRxFIFOLevel(SPI2);
LL_SPI_ClearFlag_OVR(SPI2);
return;
}
void SPIReceiveData(char *p8Data, int i16Length)
{
do
{
LL_SPI_SetRxFIFOThreshold(SPI2, LL_SPI_RX_FIFO_TH_QUARTER);
while(RESET == LL_SPI_IsActiveFlag_TXE(SPI2);
LL_SPI_TransmitData8(SPI2, (uint8_t)*(p8Data+i16Count));
while(RESET == LL_SPI_IsActiveFlag_RXNE(SPI2);
*(p8Data+i16Count) = (uint8_t)(LL_SPI_ReceiveData16(SPI2);
i16Count += 1;
i16Length--;
}while(i16Length != 0);
while(SET == LL_SPI_GetTxFIFOLevel(SPI2);
while(SET == LL_SPI_GetRxFIFOLevel(SPI2);
return;
}
Please can anyone help.
-Regards
