SPI slave 11-03-15

Dependencies:   mbed_SPISlave_LPC

Committer:
Matt3
Date:
Tue Mar 10 16:52:28 2015 +0000
Revision:
0:e1961b6f09d3
a

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Matt3 0:e1961b6f09d3 1
Matt3 0:e1961b6f09d3 2 // Reply to a SPI master as slave
Matt3 0:e1961b6f09d3 3
Matt3 0:e1961b6f09d3 4 #include "mbed.h"
Matt3 0:e1961b6f09d3 5
Matt3 0:e1961b6f09d3 6 Serial pc(USBTX, USBRX); // tx, rx
Matt3 0:e1961b6f09d3 7
Matt3 0:e1961b6f09d3 8 SPISlave device(dp2, dp1, dp6, dp25); // mosi, miso, sclk, ssel
Matt3 0:e1961b6f09d3 9
Matt3 0:e1961b6f09d3 10 int main() {
Matt3 0:e1961b6f09d3 11
Matt3 0:e1961b6f09d3 12 // device.reply(0x00); // Prime SPI with first reply
Matt3 0:e1961b6f09d3 13 while(1) {
Matt3 0:e1961b6f09d3 14
Matt3 0:e1961b6f09d3 15 //pc.printf("hi\r\n");
Matt3 0:e1961b6f09d3 16 //wait(1);
Matt3 0:e1961b6f09d3 17
Matt3 0:e1961b6f09d3 18 if(device.receive()) {
Matt3 0:e1961b6f09d3 19 int v = device.read(); // Read byte from master
Matt3 0:e1961b6f09d3 20 pc.printf("received: %x/r/n", v); // print v to serial
Matt3 0:e1961b6f09d3 21 v = (v + 1) % 0x100; // Add one to it, modulo 256
Matt3 0:e1961b6f09d3 22 device.reply(v); // Make this the next reply
Matt3 0:e1961b6f09d3 23 }
Matt3 0:e1961b6f09d3 24
Matt3 0:e1961b6f09d3 25 wait(0.1);
Matt3 0:e1961b6f09d3 26 }
Matt3 0:e1961b6f09d3 27 }