2021-10-26 12:59 AM
I am playing with G4 LL example code for SPI.
In STM32Cube_FW_G4_V1.4.0, there is example SPI_OneBoard_HalfDuplex_IT_Init.
I have managed to make it work with my Nucleo-G431RB board.
I wonder how I can extend it to a full duplex mode to communicate with a sensor.
After I look through file stm32g4xx_ll_spi.h, there are only LL_SPI_TransmitData8 and LL_SPI_ReceiveData8. There is no such function like TransmitReceive.
Solved! Go to Solution.
2021-10-26 06:59 AM
> After I look through file stm32g4xx_ll_spi.h, there are only LL_SPI_TransmitData8 and LL_SPI_ReceiveData8. There is no such function like TransmitReceive.
If you want low-level access to transmit and receive, you'll need to call both LL_SPI_TransmitData8 and LL_SPI_ReceiveData8 in the correct order and waiting for the appropriate flags to be set. You can look at the HAL functions to understand how this is done, or read the reference manual.
If you want convenience, then use HAL.
2021-10-26 06:59 AM
> After I look through file stm32g4xx_ll_spi.h, there are only LL_SPI_TransmitData8 and LL_SPI_ReceiveData8. There is no such function like TransmitReceive.
If you want low-level access to transmit and receive, you'll need to call both LL_SPI_TransmitData8 and LL_SPI_ReceiveData8 in the correct order and waiting for the appropriate flags to be set. You can look at the HAL functions to understand how this is done, or read the reference manual.
If you want convenience, then use HAL.
2021-10-26 07:56 PM
HAL is too slow for my app: in my experiment, I toggle one GPIO pin as chip select. In between toggle CS pin and SPI transmission, there is too much time wasted, which I cannot control.
If I use LL function, I can adjust the gap between CS low/high and SPI transmit.
2021-10-26 08:00 PM
If you want fast, low-level access, I would strongly recommend ditching the LL library altogether and accessing registers directly. The LL library adds a layer of unnecessary obfuscation and requires that you learn both the LL library as well as the registers.
2021-10-26 08:14 PM
Thanks for the advice. I will bear that in mind and work towards that goal.
Although I have done firmware for many years, so far I've never directly touched registers. I just feel uneasy and a bit strange.
2021-10-29 02:25 AM
I tried another example code: FullDuplex SPI with DMA using LL library.
The original code only do SPI transmission once, so I modified it such that:
in function DMA1_TransmitComplete_Callback()
I call LL_DMA_EnableChannel(DMA1, LL_DMA_CHANNEL_3) again.
But I cannot see any SPI transmission on signal scope.
It looks like I need to do more to enable repeated SPI transmission than just call LL_DMA_EnableChannel