SPI slave 11-03-15

Dependencies:   mbed_SPISlave_LPC

main.cpp

Committer:
Matt3
Date:
2015-03-10
Revision:
0:e1961b6f09d3

File content as of revision 0:e1961b6f09d3:


// Reply to a SPI master as slave
 
#include "mbed.h"
 
Serial pc(USBTX, USBRX); // tx, rx

SPISlave device(dp2, dp1, dp6, dp25); // mosi, miso, sclk, ssel
 
int main() {
      
//    device.reply(0x00);              // Prime SPI with first reply
    while(1) {
        
        //pc.printf("hi\r\n");
        //wait(1);
  
        if(device.receive()) {
            int v = device.read();   // Read byte from master
            pc.printf("received: %x/r/n", v);    // print v to serial
            v = (v + 1) % 0x100;     // Add one to it, modulo 256
            device.reply(v);         // Make this the next reply          
        }

        wait(0.1);
    }
}