I just wanted to know whether someone already tested the SPI in slave mode and I am interested in the used code snippet if available.
Currently I am working on a project which involves data transfer between two maple minis over SPI in 16 bit mode, the one is master the other is slave also involving DMA access from SPI Rx to RAM.
I tried to implement some basic functions to setup the SPI in slave mode, similar to the routines of SPI master initialization, but it doesn’t seem to work.
I can see the clock, data and NSS coming out correctly from the master, but the DMA tube on the slave device doesn’t get fired at all, I don’t know whether SPI is receiving data or not.
Any working example could help me a lot.
Thanks.
Steve
There was a good amount of noise in the forum last year about the SPI select, but I could not find anything about SPI slave-mode in our forum. I did find this article in the old Leaflabs forum:
Summary
…. to the point in my checking where it seems that the Maple in slave mode SPI simply doesn’t pay attention to the slave select line. My Seleae logic analyzer shows good clear data going into the Maple on all the right pins. For testing I’m using an Arduino 2009 as an SPI master to generate data, and have been slowing it down trying to find what is going wrong.
Ray
STMs implementation inside the STM32 of what the NSS does is very odd.
It doesn’t operate in the way most people expect a Slave Select line to operate in terms of controlling external SPI devices.
There are plenty of postings on STMs own forum about this, basically complaining it doesn’t work.
So for SPI master, we gave up on using the hardware Slave Select pin (NSS).
Also. like Ray has already said… I dont recall anyone attempting SPI slave functionality before with the Stm32 libmaple core i.e what we use.
Hope I’ll manage alone, just that it will take some time.
The DMA-access had to be enabled before the SPI periphery gets enabled, which is not compatible with the actual “spi_reconfigure()”…
So far only 0xFFFFs got stored, but I’m still working on it.
It looks like the problem was somewhere else, not in the SPI data communication, which is working as expected!
The SPI slave seems to work stable in 16 bit data mode.
Have to think about the most convenient change to check in to the repo, my actual quick’n-dirty solution may not like to everyone
If you dont have time to write a nice clean solution…
Even your prototype solution could be beneficial to anyone else needing this.
It doesnt need to go into the repo, a code snippet here would be better than nothing
Thanks
Roger
Anyway, I wanted to have it clean in the repo compatible format.
In the next week I’ll be in holiday, from tomorrow on, will continue when I’m back.
Cheers,
Steve
I appreciate the sentiment. I often write stuff that I’m happy to use for my own testing, but would not publish as its not tidy or optimised ![]()
Cheers
Roger
I got an error about SPI.beginTransactionSlave, compiler claim is not member of ‘Class SPIClass’.
Do you use standard stm32duino SPI library?
Yes, but I think I didn’t checked in my local changes.
I have to send a PR to Roger.
From what I recall, the SPI and USB were in the same PR, and I manually merged the USB changes, but I can’t recall if I did the SPI changes or not.
I’ll need to check
I think these changes are already initiated in a PR related to another topic due to my incompetency to correctly handle PRs on github

