Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp@0:cda27773d8b4, 2012-02-27 (annotated)
- Committer:
- polytech01
- Date:
- Mon Feb 27 16:30:35 2012 +0000
- Revision:
- 0:cda27773d8b4
Test SPI slave - Leonardo Wesseling
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| polytech01 | 0:cda27773d8b4 | 1 | #include "mbed.h" |
| polytech01 | 0:cda27773d8b4 | 2 | |
| polytech01 | 0:cda27773d8b4 | 3 | SPISlave slave(p11,p12,p13,p14); |
| polytech01 | 0:cda27773d8b4 | 4 | |
| polytech01 | 0:cda27773d8b4 | 5 | Serial pc(USBTX, USBRX); |
| polytech01 | 0:cda27773d8b4 | 6 | |
| polytech01 | 0:cda27773d8b4 | 7 | int main() { |
| polytech01 | 0:cda27773d8b4 | 8 | |
| polytech01 | 0:cda27773d8b4 | 9 | slave.format(8,0); |
| polytech01 | 0:cda27773d8b4 | 10 | slave.frequency(1000000); |
| polytech01 | 0:cda27773d8b4 | 11 | int v, res; |
| polytech01 | 0:cda27773d8b4 | 12 | |
| polytech01 | 0:cda27773d8b4 | 13 | |
| polytech01 | 0:cda27773d8b4 | 14 | while(1) { |
| polytech01 | 0:cda27773d8b4 | 15 | |
| polytech01 | 0:cda27773d8b4 | 16 | if(slave.receive()) { |
| polytech01 | 0:cda27773d8b4 | 17 | |
| polytech01 | 0:cda27773d8b4 | 18 | v = slave.read(); // Read byte from master |
| polytech01 | 0:cda27773d8b4 | 19 | if(v!=0){// discard the dummy buffer write |
| polytech01 | 0:cda27773d8b4 | 20 | pc.printf("v=%d\n\r", v); |
| polytech01 | 0:cda27773d8b4 | 21 | res=(v+5); // Add 5 to it |
| polytech01 | 0:cda27773d8b4 | 22 | slave.reply(res); // Make this the next reply |
| polytech01 | 0:cda27773d8b4 | 23 | pc.printf("v++=%d\n\r", res); |
| polytech01 | 0:cda27773d8b4 | 24 | } |
| polytech01 | 0:cda27773d8b4 | 25 | |
| polytech01 | 0:cda27773d8b4 | 26 | } |
| polytech01 | 0:cda27773d8b4 | 27 | } |
| polytech01 | 0:cda27773d8b4 | 28 | |
| polytech01 | 0:cda27773d8b4 | 29 | |
| polytech01 | 0:cda27773d8b4 | 30 | |
| polytech01 | 0:cda27773d8b4 | 31 | } |