Tsungta Wu
/
mbed_SPIS_multiByte_example_SOG
fork from Sog
Fork of mbed_SPIS_multiByte_example_SOG by
main.cpp@4:8e796b751cd3, 2017-06-01 (annotated)
- Committer:
- tsungta
- Date:
- Thu Jun 01 07:59:21 2017 +0000
- Revision:
- 4:8e796b751cd3
- Parent:
- 2:c520d7c7739d
- Child:
- 5:6a1155885fc9
This version support maximum of receiving 16 bytes in single CS cycle
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tsungta | 4:8e796b751cd3 | 1 | //#include "mbed.h" |
tsungta | 4:8e796b751cd3 | 2 | // |
tsungta | 4:8e796b751cd3 | 3 | //SPI spi(A1, A2, A3); // mosi, miso, sclk |
tsungta | 4:8e796b751cd3 | 4 | //DigitalOut cs(A0); |
tsungta | 4:8e796b751cd3 | 5 | // |
tsungta | 4:8e796b751cd3 | 6 | //uint8_t tx_buf[32] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V'}; |
tsungta | 4:8e796b751cd3 | 7 | // |
tsungta | 4:8e796b751cd3 | 8 | //int main() { |
tsungta | 4:8e796b751cd3 | 9 | // // Chip must be deselected |
tsungta | 4:8e796b751cd3 | 10 | // cs = 1; |
tsungta | 4:8e796b751cd3 | 11 | // |
tsungta | 4:8e796b751cd3 | 12 | // // Setup the spi for 8 bit data, high steady state clock, |
tsungta | 4:8e796b751cd3 | 13 | // // second edge capture, with a 1MHz clock rate |
tsungta | 4:8e796b751cd3 | 14 | // spi.format(8,1); |
tsungta | 4:8e796b751cd3 | 15 | // spi.frequency(8000000); |
tsungta | 4:8e796b751cd3 | 16 | // |
tsungta | 4:8e796b751cd3 | 17 | // // Select the device by seting chip select low |
tsungta | 4:8e796b751cd3 | 18 | // cs = 0; |
tsungta | 4:8e796b751cd3 | 19 | // |
tsungta | 4:8e796b751cd3 | 20 | // for(int i=0; i<32; i++) |
tsungta | 4:8e796b751cd3 | 21 | // spi.write(tx_buf[i]); |
tsungta | 4:8e796b751cd3 | 22 | // printf("End of transmission \r\n"); |
tsungta | 4:8e796b751cd3 | 23 | // |
tsungta | 4:8e796b751cd3 | 24 | // // Deselect the device |
tsungta | 4:8e796b751cd3 | 25 | // cs = 1; |
tsungta | 4:8e796b751cd3 | 26 | //} |
tsungta | 4:8e796b751cd3 | 27 | |
tsungta | 0:b7415ae44dac | 28 | #include "mbed.h" |
tsungta | 0:b7415ae44dac | 29 | |
tsungta | 0:b7415ae44dac | 30 | #include "SPISlave_multiByte.h" |
tsungta | 0:b7415ae44dac | 31 | SPISlave_multiByte device(A1, A2, A3, p3); // mosi, miso, sclk, ssel |
tsungta | 0:b7415ae44dac | 32 | Serial uart(USBTX, USBRX); |
tsungta | 0:b7415ae44dac | 33 | |
tsungta | 4:8e796b751cd3 | 34 | #define TXRX_LENGTH 16 //max is 16 |
tsungta | 0:b7415ae44dac | 35 | int main() { |
tsungta | 0:b7415ae44dac | 36 | uart.printf("START!"); |
tsungta | 1:58f0712d9aa2 | 37 | device.format(8,1); |
tsungta | 4:8e796b751cd3 | 38 | device.frequency(8000000); |
tsungta | 2:c520d7c7739d | 39 | |
tsungta | 4:8e796b751cd3 | 40 | device.reply((uint8_t*)"xyz", TXRX_LENGTH); |
tsungta | 0:b7415ae44dac | 41 | while(1) { |
tsungta | 4:8e796b751cd3 | 42 | if(device.receive(TXRX_LENGTH)) { |
tsungta | 4:8e796b751cd3 | 43 | int ret = device.read(); // Read byte from master |
tsungta | 4:8e796b751cd3 | 44 | uart.printf("ret = %s ", ret); |
tsungta | 1:58f0712d9aa2 | 45 | |
tsungta | 0:b7415ae44dac | 46 | } |
tsungta | 0:b7415ae44dac | 47 | } |
tsungta | 0:b7415ae44dac | 48 | } |