Sog Yang
/
mbed_SPIS_multiByte_example_SOG
Sog update version
Fork of mbed_SPIS_multiByte_example by
main.cpp@0:b7415ae44dac, 2017-05-24 (annotated)
- Committer:
- tsungta
- Date:
- Wed May 24 10:17:56 2017 +0000
- Revision:
- 0:b7415ae44dac
- Child:
- 1:58f0712d9aa2
First commit; reply is functional, need to work on read
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tsungta | 0:b7415ae44dac | 1 | #include "mbed.h" |
tsungta | 0:b7415ae44dac | 2 | |
tsungta | 0:b7415ae44dac | 3 | #include "SPISlave_multiByte.h" |
tsungta | 0:b7415ae44dac | 4 | SPISlave_multiByte device(A1, A2, A3, p3); // mosi, miso, sclk, ssel |
tsungta | 0:b7415ae44dac | 5 | Serial uart(USBTX, USBRX); |
tsungta | 0:b7415ae44dac | 6 | |
tsungta | 0:b7415ae44dac | 7 | int main() { |
tsungta | 0:b7415ae44dac | 8 | uart.printf("START!"); |
tsungta | 0:b7415ae44dac | 9 | device.format(8,1); |
tsungta | 0:b7415ae44dac | 10 | |
tsungta | 0:b7415ae44dac | 11 | device.reply(0xAA); // Prime SPI with first reply |
tsungta | 0:b7415ae44dac | 12 | while(1) { |
tsungta | 0:b7415ae44dac | 13 | if(device.receive()) { |
tsungta | 0:b7415ae44dac | 14 | int v = device.read(); // Read byte from master |
tsungta | 0:b7415ae44dac | 15 | v = (v + 1) % 0x100; // Add one to it, modulo 256 |
tsungta | 0:b7415ae44dac | 16 | device.reply(v); // Make this the next reply |
tsungta | 0:b7415ae44dac | 17 | |
tsungta | 0:b7415ae44dac | 18 | v = device.read(); // Read byte from master |
tsungta | 0:b7415ae44dac | 19 | v = (v + 1) % 0x100; // Add one to it, modulo 256 |
tsungta | 0:b7415ae44dac | 20 | device.reply(v); // Make this the next reply |
tsungta | 0:b7415ae44dac | 21 | |
tsungta | 0:b7415ae44dac | 22 | v = device.read(); // Read byte from master |
tsungta | 0:b7415ae44dac | 23 | v = (v + 1) % 0x100; // Add one to it, modulo 256 |
tsungta | 0:b7415ae44dac | 24 | device.reply(v); // Make this the next reply |
tsungta | 0:b7415ae44dac | 25 | } |
tsungta | 0:b7415ae44dac | 26 | } |
tsungta | 0:b7415ae44dac | 27 | } |