Skip to main content
Associate
April 21, 2025
Question

Communicate NUCLEO-G070RB USART with SPI as MSB

  • April 21, 2025
  • 2 replies
  • 793 views

Thank you always for your hard work,

I needed 4 SPIs, so while exploring the board, I found a text that could make USART work like SPI, so I tried this with the NUCLEO-G070RB.
The example I referenced is "USART_SyncCommunication_FullDuplex_DMA_Init" on that board.
Referring to the setting of the board, a program was written to check whether it was the same as the buffer sent by the buffer that received a specific message from USART (master) to SPI (slave).

The current code works well.
However, the standard setting of SPI is MSB first, but the example seems to be possible only with LSB first.
I want USART and SPI to communicate by MSB.
Attached is the setup of USART and SPI.

 

yurim_1-1745200797854.png

yurim_0-1745201521951.png

 

 

 

2 replies

TDK
Super User
April 21, 2025

The setting appears to be missing in CubeMX.

Try setting the MSBFIRST bit in USART_CR2 after it's initialized.

SET_BIT(USART_CR2, USART_CR2_MSBFIRST);

 

"If you feel a post has answered your question, please click ""Accept as Solution""."
Andrew Neil
Super User
April 23, 2025
A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
yurimAuthor
Associate
April 24, 2025

@TDK 

I've enabled MSB_FIRST BIT since the initialization of USART, but the output results remain unchanged. (It still seems to be operating as LSB first.)
Is there any way I can try it now?

Below are the buffers I sent to USART(UsartTx) and the buffers I received with SPI(SpiRx). In CUBE MX, I changed SPI to MSB First.

yurim_0-1745455579000.png

yurim_1-1745455586615.png

 


Thank you.

Pavel A.
Super User
April 26, 2025

From the RM, about the MSBFIRST: "This bitfield can only be written when the USART is disabled (UE=0)."

So don't set this bit after init(), rather set the AdvFeatureInit struct members as usual.