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.
Fork of TeensySlave_Nov16 by
main.cpp@0:b120cb6c902f, 2015-11-17 (annotated)
- Committer:
- georgeHuang
- Date:
- Tue Nov 17 01:22:57 2015 +0000
- Revision:
- 0:b120cb6c902f
teensySPISlave
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
georgeHuang | 0:b120cb6c902f | 1 | // Reply to a SPI master as slave |
georgeHuang | 0:b120cb6c902f | 2 | |
georgeHuang | 0:b120cb6c902f | 3 | #include "mbed.h" |
georgeHuang | 0:b120cb6c902f | 4 | int dataToMaster = 96; |
georgeHuang | 0:b120cb6c902f | 5 | //int MOSI=11; |
georgeHuang | 0:b120cb6c902f | 6 | //int MISO=12; |
georgeHuang | 0:b120cb6c902f | 7 | //int SCK=13; |
georgeHuang | 0:b120cb6c902f | 8 | //int CS=10; |
georgeHuang | 0:b120cb6c902f | 9 | SPISlave device(D11, D12, D13, D10); // mosi, miso, sclk, chipSelect |
georgeHuang | 0:b120cb6c902f | 10 | |
georgeHuang | 0:b120cb6c902f | 11 | int main() { |
georgeHuang | 0:b120cb6c902f | 12 | device.reply(0x00); // Prime SPI with first reply |
georgeHuang | 0:b120cb6c902f | 13 | while(1) { |
georgeHuang | 0:b120cb6c902f | 14 | if(device.receive()) { |
georgeHuang | 0:b120cb6c902f | 15 | //int v = device.read(); // Read byte from master |
georgeHuang | 0:b120cb6c902f | 16 | |
georgeHuang | 0:b120cb6c902f | 17 | //v = (v + 1) % 0x100; // Add one to it, modulo 256 |
georgeHuang | 0:b120cb6c902f | 18 | device.reply(dataToMaster); // Make this the next reply |
georgeHuang | 0:b120cb6c902f | 19 | } |
georgeHuang | 0:b120cb6c902f | 20 | } |
georgeHuang | 0:b120cb6c902f | 21 | } |