Hey people, i'm trying to make communication between two mbeds through SPI, but I'm having problems with the master input slave output, I mean,the slave receives the data from the master, performs a simple addition and should return the value of the addition, but it doesn't return any value to the master.
The codes follow:
Master:
- include "mbed.h"
SPI spi(p11, p12, p13); mosi, miso, sclk
DigitalOut cs(p14);
Serial pc(USBTX, USBRX); tx, rx
int main() {
Setup the spi for 8 bit data, high steady state clock,
second edge capture, with a 1MHz clock rate
spi.format(8,0);
spi.frequency(1000000);
int teste, result;
teste=0xAA;
cs=0;
pc.printf("Answer before = %d\n\r", teste);
wait(5);
spi.write(teste);
result= spi.write(0x00);
pc.printf("Answer later= 0x%X\n\r", result);
cs=1;
}
Slave:
- include "mbed.h"
SPISlave slave(p11,p12,p13,p14);
Serial pc(USBTX, USBRX);
int main() {
slave.format(8,0);
slave.frequency(1000000);
int v, res;
while(1) {
if(slave.receive()) {
v = slave.read(); Read byte from master
pc.printf("v=%d\n\r", v);
res=(v+5); Add 5 to it
slave.reply(res); Make this the next reply
pc.printf("v++=%d\n\r", res);
}
}
}
Please, if anyone could help, I'd very much apprecite it.
Hey people, i'm trying to make communication between two mbeds through SPI, but I'm having problems with the master input slave output, I mean,the slave receives the data from the master, performs a simple addition and should return the value of the addition, but it doesn't return any value to the master. The codes follow:
Master:
SPI spi(p11, p12, p13); mosi, miso, sclk DigitalOut cs(p14);
Serial pc(USBTX, USBRX); tx, rx
int main() { Setup the spi for 8 bit data, high steady state clock, second edge capture, with a 1MHz clock rate spi.format(8,0); spi.frequency(1000000); int teste, result;
teste=0xAA;
cs=0; pc.printf("Answer before = %d\n\r", teste);
wait(5); spi.write(teste); result= spi.write(0x00);
pc.printf("Answer later= 0x%X\n\r", result); cs=1;
}
Slave:
SPISlave slave(p11,p12,p13,p14);
Serial pc(USBTX, USBRX);
int main() {
slave.format(8,0); slave.frequency(1000000); int v, res;
while(1) {
if(slave.receive()) {
v = slave.read(); Read byte from master pc.printf("v=%d\n\r", v); res=(v+5); Add 5 to it slave.reply(res); Make this the next reply pc.printf("v++=%d\n\r", res); } }
}
Please, if anyone could help, I'd very much apprecite it.