mbed LPC1768とNucleoF401REでSPI通信する

master
mbed LPC1768

#include "mbed.h"

SPI spi(p5, p6, p7); // mosi, miso, sclk
DigitalOut cs(p8);
Serial pc(USBTX, USBRX);
DigitalOut led(LED1);

#define DTIME 0.005

int main()
{
    cs = 1;
    spi.format(8,0);
    spi.frequency(1000000);
    led = 0;

    while(1) {
        led = 1;        
        cs=0;
        wait(DTIME);
        int byte_1 = spi.write(0x03);
        pc.printf("byte_1: %d ",byte_1);
        cs=1;

        cs=0;
        wait(DTIME);
        int byte_2 = spi.write(0xFF);
        pc.printf("byte_2: %d ",byte_2);
        cs=1;
        
        cs=0;
        wait(DTIME);
        int byte_waste = spi.write(0xFF);
        cs=1;

        int rbyte = (byte_1<<8)+byte_2;
        pc.printf("rbyte: %d\n",rbyte);
        led = 0;
        
        wait(3);
    }

}

slave
NucleoF401RE

#include "mbed.h"

SPISlave device(D4,D5,D3,A2); // mosi, miso, sclk, ssel
Serial pc(SERIAL_TX, SERIAL_RX);


int main()
{
    device.format(8,0);
    device.frequency(1000000);
    uint8_t hbyte = 7;
    uint8_t lbyte = 208;

    int counter = 0;

    while(1) {        
        if(device.receive()) {
            
            int val = device.read();
            pc.printf("received1: %d, ",val);
            device.reply(0xFF);

            int val2 = device.read();
            pc.printf("received2: %d, ",val2);
            device.reply(hbyte);         // Make this the next reply

            int val3 = device.read();
            pc.printf("receive3: %d, ",val3);
            pc.printf("count: %d\n",counter);
            device.reply(lbyte);         // Make this the next reply

            counter = counter+1;
        }
    }
}