Skip to main content
newbie_stm32
Associate III
April 4, 2023
Question

SPI communication on STM32G4

  • April 4, 2023
  • 7 replies
  • 3317 views

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.

This topic has been closed for replies.

7 replies

newbie_stm32
Associate III
April 10, 2023

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

Pavel A.
Super User
April 10, 2023

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.

Technical Moderator
April 10, 2023

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"".ThanksImen"
newbie_stm32
Associate III
April 13, 2023

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.

newbie_stm32
Associate III
April 11, 2023

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.

waclawek.jan
Super User
April 11, 2023

> 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
April 11, 2023

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
April 13, 2023

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