7 years, 1 month ago.

SPISlave function does NOT work on Nucleo-F446RE

I couldn't success SPISlave function on Nucleo-F446RE.
Please try my test program.

Import programNucleo_F446RE_SPISlave_not_work

Test SPISlave \\ Current lib. does not work on STM32F446RE


It looks like initialization problem.
If I modified the CR1 register value, it works well.
Could you check SPISlave library?

Question relating to:

Affordable and flexible platform to ease prototyping using a STM32F446RET6 microcontroller.

1 Answer

7 years ago.

Hi Kenji, I had a look to your code. What I see is that you're trying to use 1 SPI master and 2 SPI slaves from the same board at the same time. To do so, the slave needs to be ready and reading when the master transmit. from MBED design there shall be a polling loop on SPI slave side, like described here: https://docs.mbed.com/docs/mbed-os-api-reference/en/5.1/APIs/interfaces/digital/SPISlave/ Your "WORKS_WELL" implementation seems like a work-around that would only work for 1 word being sent over SPI, I suppose that it may not work if the master SPI sends many words ... What I'd suggest is to create threads for the slave SPI so that you can have a polling loop on SPI slave interfaces before the master starts transmitting. Or to use 2 separate boards, 1 as master, the other one as a slave. hope this helps

Accepted Answer

I'm so sorry, I don't accept your concern.
If set "WORKS_WELL", program works well not only once but forever.
Have your checked my program on your board by yourself or just thinking your brain?
The library that prepared by official supporter, it's very important to ensure quality itself.
I don't want to say like this but your are inside of ST Mbed support member, please check again and give me your next comment.
For instance:
What kind of action can enable CR1 SPE bit and when?
What does it mean BIDIMODE=1?

Could you give me next comment?

posted by Kenji Arai 20 Nov 2017

Hi sorry I answered to this topic yesterday, but the comment never was published :-( so I need to write it again.

First point is that yes, I cannot test and debug all the users reported programs. It is very useful when you ask precise questions together with sharing code.

In your case, your new questions are very useful:

What does it mean BIDIMODE=1? BIDIR means that the MOSI line is used for both writing and reading. This is what we use wen the MISO line of SPI MASTER is declared as NC. This is the case in your code, so we're in BIDIR configuration.

What kind of action can enable CR1 SPE bit and when? In case of BIDIR, it is enabled ONLY during write and read operations. What I found out is that BIDIR is not supported for a slave SPI in our implementation, and this creates the issue that you see.

To solve you issue I see 2 possibilities: 1) Add MISO line to your slaves 2) I entered an issue and issued a PR in github, you can test it. See https://github.com/ARMmbed/mbed-os/pull/5565

Hope this helps

posted by Laurent Meunier 23 Nov 2017

Thank you for your additional explanation and action for improvement.
I understood that my case is very special case.
SPI master send data to Slave every 500uS only one way.
In the beginning, I tried two boards and failed.
I also tried thread mode on mbed-os that you recommended the polling loop.
But all of those attempts never success then I simplified the program only for Q&A.
Thanks again for your support.

posted by Kenji Arai 23 Nov 2017