cancel
Showing results for 
Search instead for 
Did you mean: 

SPI communication on STM32G4

newbie_stm32
Associate III

OS : Ubuntu 22.04.2 LTS

STM32CubeIDE : 1.12.0 Build: 14980_20230301_1550 (UTC)

Firmware : STM32Cube FW_G4 V1.5.1

Working on interfacing Nucleo-G491RE to EVAL-AD5592R-PMDZ evaluation board using SPI interface (SPI2). Before jumping on to it I just probed SPI2_SCK and made the necessary configurations to it using STM32CubeIDE and generated code. Using HAL_SPI_TransmitReceive sent bytes to be able to capture the SPI2_SCK on PB13 but did not get the expected clock on the oscilloscope. What did I miss out on configuring SPI?

Please find the screenshot of the SPI configuration on STM32CubeIDE in the attachment.

8 REPLIES 8
newbie_stm32
Associate III

How did the SPI2 get the clock to operate in Clock Configuration?

Pavel A.
Evangelist III

Set the HCLK 1to 170 MHz. Use the Cube Clock configuration tool.

As below. (note: this config is likely not optimal, only as example)


_legacyfs_online_stmicro_images_0693W00000bhnfvQAA.pngThen the SPI baudrate will be as on your screenshot.

Imen.D
ST Employee

Hello @newbie_stm32​ and welcome to the Community :)

I advise you start with ready-to-use SPI example using ioc file available under STM32CubeG4 MCU package:

\STM32Cube_FW_G4_Vx.x.0\Projects\NUCLEO-G474RE\Examples\SPI\

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
newbie_stm32
Associate III

Hi, thanks for your input. It seemed to be a bug from the IDE. If I flash directly using the default Clock Configuration it does not work for me. Changing the clock to some other value, say 100 MHz from 170 MHz and generating code then again changing back to 170MHz, allowed me to view SPI2_CLK and SPI2_MOSI. But still not able to view the SPI2_NSS line.

Please find the attachment. The signal in blue is SPI2_SCK and the signal in yellow is SPI2_NSS.

> But still not able to view the SPI2_NSS line.

What waveform would you expect on NSS? How did you set it up, exactly? Are you aware of the fact that NSS either pulses between frames, or just goes low and remains there, and if you have any other expectation you have to set NSS to GPIO Output and manipulate it "manually"?

Read the SPI chapter in RM. Read out and check content of SPI and relevant GPIO registers.

JW

newbie_stm32
Associate III

Hi, @Community member​. Yes, I am using GPIO instead of SPI NSS function as it didn't work for me as I am expecting a LOW over the entire bit frame and then going to HIGH.

Probably will start to look at the control registers to check for possible configurations that did not happen.

newbie_stm32
Associate III

Hi, I worked on debugging using single stepping, and the SPI2_CR1 and SPI2_CR2 register values are properly set. But no signal at SPI2_NSS (PB12).

Hi @Imen DAHMEN​ can you please guide me to use ready to use SPI example on STM32CubeIDE - Target Selection >> Example Selector? I am not able to find one for me.