This code acts as an SPI slave controlled by the Master device, done using FRDM_KL25Z

Dependencies:   mbed

main.cpp

Committer:
suhasini
Date:
2016-07-29
Revision:
0:794f7dd0a8ef

File content as of revision 0:794f7dd0a8ef:

// Reply to a SPI master as slave
 
 #include "mbed.h"
 
 SPISlave device(PTD2, PTD3, PTD1, PTD0); // mosi, miso, sclk, ssel
 Serial pc(USBTX,USBRX);

 
 int main() {
     pc.baud(115200);
     int v=0;
     pc.printf("read the data");
 //   device.reply(0x00);              // Prime SPI with first reply
       while(1) {
         if(device.receive()) {
             v = device.read();   // Read byte from master
             pc.printf("read the data %d",v);
             v=0;
             //v = (v + 1) % 0x100;     // Add one to it, modulo 256
             //device.reply(v);         // Make this the next reply
         }
     }
 }