Tsungta Wu / Mbed OS mbed_SPIS_multiByte_example

main.cpp

Committer:
tsungta
Date:
2017-05-24
Revision:
0:b7415ae44dac
Child:
1:58f0712d9aa2

File content as of revision 0:b7415ae44dac:

#include "mbed.h"

#include "SPISlave_multiByte.h"
SPISlave_multiByte device(A1, A2, A3, p3); // mosi, miso, sclk, ssel
Serial uart(USBTX, USBRX);

int main() {
    uart.printf("START!");
    device.format(8,1);
    
   device.reply(0xAA);              // Prime SPI with first reply
   while(1) {
       if(device.receive()) {
           int v = device.read();   // Read byte from master
           v = (v + 1) % 0x100;     // Add one to it, modulo 256
           device.reply(v);         // Make this the next reply

           v = device.read();   // Read byte from master
           v = (v + 1) % 0x100;     // Add one to it, modulo 256
           device.reply(v);         // Make this the next reply
           
           v = device.read();   // Read byte from master
           v = (v + 1) % 0x100;     // Add one to it, modulo 256
           device.reply(v);         // Make this the next reply                      
       }
   }
}