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.
Dependencies: mbed
main.cpp@0:286baeef532e, 2018-11-19 (annotated)
- Committer:
- Keith_N
- Date:
- Mon Nov 19 05:26:48 2018 +0000
- Revision:
- 0:286baeef532e
spi_slave
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Keith_N | 0:286baeef532e | 1 | #include "mbed.h" |
Keith_N | 0:286baeef532e | 2 | |
Keith_N | 0:286baeef532e | 3 | SPISlave device(PB_5,PB_4,PB_3,PA_4); // mosi, miso, sclk, ssel |
Keith_N | 0:286baeef532e | 4 | Serial pc(SERIAL_TX, SERIAL_RX); |
Keith_N | 0:286baeef532e | 5 | |
Keith_N | 0:286baeef532e | 6 | |
Keith_N | 0:286baeef532e | 7 | int main() |
Keith_N | 0:286baeef532e | 8 | { |
Keith_N | 0:286baeef532e | 9 | device.format(8,0); |
Keith_N | 0:286baeef532e | 10 | device.frequency(1000000); |
Keith_N | 0:286baeef532e | 11 | uint8_t hbyte = 7; |
Keith_N | 0:286baeef532e | 12 | uint8_t lbyte = 208; |
Keith_N | 0:286baeef532e | 13 | |
Keith_N | 0:286baeef532e | 14 | int counter = 0; |
Keith_N | 0:286baeef532e | 15 | |
Keith_N | 0:286baeef532e | 16 | while(1) { |
Keith_N | 0:286baeef532e | 17 | if(device.receive()) { |
Keith_N | 0:286baeef532e | 18 | |
Keith_N | 0:286baeef532e | 19 | int val = device.read(); |
Keith_N | 0:286baeef532e | 20 | pc.printf("received1: %d, ",val); |
Keith_N | 0:286baeef532e | 21 | device.reply(0xFF); |
Keith_N | 0:286baeef532e | 22 | |
Keith_N | 0:286baeef532e | 23 | int val2 = device.read(); |
Keith_N | 0:286baeef532e | 24 | pc.printf("received2: %d, ",val2); |
Keith_N | 0:286baeef532e | 25 | device.reply(hbyte); // Make this the next reply |
Keith_N | 0:286baeef532e | 26 | |
Keith_N | 0:286baeef532e | 27 | int val3 = device.read(); |
Keith_N | 0:286baeef532e | 28 | pc.printf("receive3: %d, ",val3); |
Keith_N | 0:286baeef532e | 29 | pc.printf("count: %d\r\n",counter); |
Keith_N | 0:286baeef532e | 30 | device.reply(lbyte); // Make this the next reply |
Keith_N | 0:286baeef532e | 31 | |
Keith_N | 0:286baeef532e | 32 | counter = counter+1; |
Keith_N | 0:286baeef532e | 33 | } |
Keith_N | 0:286baeef532e | 34 | wait(0.01); |
Keith_N | 0:286baeef532e | 35 | } |
Keith_N | 0:286baeef532e | 36 | } |