cancel
Showing results for 
Search instead for 
Did you mean: 

G431 Full Duplex SPI LL function for Tx and Rcv

HDaji.1
Senior

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.

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

> 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.

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

5 REPLIES 5
TDK
Guru

> 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.

If you feel a post has answered your question, please click "Accept as Solution".
HDaji.1
Senior

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.

TDK
Guru

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.

If you feel a post has answered your question, please click "Accept as Solution".
HDaji.1
Senior

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.

HDaji.1
Senior

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