Skip to main content
jg_spitfire
Senior
March 22, 2020
Solved

How to receive 32-bit data in SPI slave polling mode?

  • March 22, 2020
  • 7 replies
  • 3552 views

Hi, I want to receive 32 bit data from a SPI master but in the cubemx options there are only two options available, 8 bits and 16 bits, so what if I want to receive 32 bits frames, what should I do?

Thanks

This topic has been closed for replies.
Best answer by TDK
Yep, that's pretty much it.
On the STM32, the most common way is to control the CS pins manually (i.e. using HAL_GPIO_WritePin). If you have two CS lines, you need to make sure only one is selected (low) at a time. If that's not happening, could be any number of things wrong.

7 replies

TDK
March 22, 2020

You read 4 bytes, and convert those into the 32 bit value of your choice.

"If you feel a post has answered your question, please click ""Accept as Solution""."
jg_spitfire
Senior
March 22, 2020

But how could I read 4 bytes if the cubemx only gives two options for the data size in the slave?, 8 bits and 16 bits

0693W000000US1WQAW.jpg

TDK
March 22, 2020

You set up the peripheral for 8 bits and send multiple 8-bit transactions. On the bus, these look the same as a 32-bit operation. Are you familiar with the SPI protocol?

For example, if you are trying to send 32 bits:

uint8_t data[4] = {1, 2, 3, 4};
HAL_SPI_Transmit(hspi, data, 4, SPI_TIMEOUT_MAX)

"If you feel a post has answered your question, please click ""Accept as Solution""."
jg_spitfire
Senior
March 22, 2020

I know a little of SPI, so you say that I should do something like this:

1.- CS low

2.- send the data of my 4 bytes buffer

3.-​ CS high

Is this correct? ​

And another question, I hope you could help me or maybe I need a new post, I was testing a máster with two slaves, and when I selected the second slave (with the first deselected) the first slave still was able to receive data in its MOSI line, and both CS have pull up resistors, do you know what could de happening?

Thanks ​

TDK
TDKBest answer
March 22, 2020
Yep, that's pretty much it.
On the STM32, the most common way is to control the CS pins manually (i.e. using HAL_GPIO_WritePin). If you have two CS lines, you need to make sure only one is selected (low) at a time. If that's not happening, could be any number of things wrong.
"If you feel a post has answered your question, please click ""Accept as Solution""."