// Reply to a SPI master as slave
#include "mbed.h"
SPISlave device(p5, p6, p7, p8); // mosi, miso, sclk, ssel
Serial pc(USBTX, USBRX);
int main() {
int u = 8;
device.reply(0x01); // Prime SPI with first reply
while(1) {
if(device.receive()) {
int v = device.read(); // Read byte from master
pc.printf("received: %d\n", v);
//v = 3;
device.reply(u); // Make this the next reply
}
}
} |