Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
10 years, 9 months ago.
SPI Slave
Hello, I'm trying to initiate a communication with a spi master device, so the nucleo must be a spi slave device. The code I use, is the following one :
- include "mbed.h"
SPISlave device(PA_11,PA_12,PA_13,PA_14);
. . . .
but the compiler returns ERROR 20 and ERROR 18
Error: Identifier "SPISlave" is undefined in "main.cpp", Line: 7, Col: 2
Error: Expected a ")" in "main.cpp", Line: 7, Col: 22
What I'm missing here?
Question relating to:
2 Answers
10 years, 9 months ago.
Are you sure about that, is there any other way to use Nucleo (throught mbed) as an SPI slave device?
Just checked it, don't know which one you have, but for the F401: http://mbed.org/users/mbed_official/code/mbed-src/file/a7168c414ef2/targets/hal/TARGET_STM/TARGET_NUCLEO_F401RE/device.h. No SPISlave.
You could either make an SPISlave software implementation (so using only digitalins/outs), or make the code for SPISlave yourself (which I very well understand wasn't exactly how you planned to use it).
Main question though: Why do you need it? SPISlave on most microcontrollers is imo kinda sucky (so not the mbed implementation, but simply how they work on the microcontroller, where the CS line needs to be toggled after every word), but there aren't that many situations where you actually require one.
posted by 10 Mar 2014I found the following code at the the library section
Reply to a SPI master as slave
- include "mbed.h"
SPISlave device(p5, p6, p7, p8); mosi, miso, sclk, ssel
int main() { device.reply(0x00); Prime SPI with first reply while(1) { if(device.receive()) { int v = device.read(); Read byte from master v = (v + 1) % 0x100; Add one to it, modulo 256 device.reply(v); Make this the next reply } } }
and an example here http://mbed.org/users/polytech01/code/TestSPIslave/file/cda27773d8b4/main.cpp
Do you know if this is valid code?
posted by 10 Mar 2014