[SPI] Connection between two mbed

27 Jun 2011

Hello,

I want to make a SPI connection between two mbeds. The slave mbed has a value in its program, for exemple : int value = 15. I want to recuperate this value with the other slave, the master.

I have tried this :

On the slave mbed :

#include "mbed.h"

SPISlave B(p5, p6, p7, p8); // mosi, miso, sclk, ssel
int value;

int main() {
     
    value = 15; 

}

On the master slave :

#include "mbed.h"
SPI A(p5,p6,p7);
DigitalOut L1(p8);
Serial pc(USBTX, USBRX);
int main() {
     A.format(8,0);
     A.frequency (1000000);
     
     L1=0;
     
     int value_recup = A.write(0x00);
     pc.printf("value_recup = %d\n", value_recup);
     
     L1=1;

}

And on teraterm I have this message : "value_recup = 255". It's not the good value.

Can you help me ?

27 Jun 2011

Both MBEDs MUST have same bit rate & format, Also miso & mosi, must be swapped over, just like TX & RX in serial.

Additionaly, you will probably need to pole 'data available' flag.

Hope this helps

Ceri.

27 Jun 2011

Also, Slave revives.