atsushi uno
/
SPI_Slave_Master_8FIFO
Test 1678 SPI 8 FIFO
main.cpp@0:5c1439ae6776, 2014-12-26 (annotated)
- Committer:
- aie
- Date:
- Fri Dec 26 11:49:29 2014 +0000
- Revision:
- 0:5c1439ae6776
SPI Simple 8 FIFO;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
aie | 0:5c1439ae6776 | 1 | |
aie | 0:5c1439ae6776 | 2 | #include "mbed.h" |
aie | 0:5c1439ae6776 | 3 | DigitalOut led1(LED1); |
aie | 0:5c1439ae6776 | 4 | |
aie | 0:5c1439ae6776 | 5 | SPI spi(p5, p6, p7); // mosi, miso, sclk |
aie | 0:5c1439ae6776 | 6 | DigitalOut cs(p8); |
aie | 0:5c1439ae6776 | 7 | |
aie | 0:5c1439ae6776 | 8 | SPISlave device(p11, p12, p13, p14); // mosi, miso, sclk, ssel |
aie | 0:5c1439ae6776 | 9 | |
aie | 0:5c1439ae6776 | 10 | int main() { |
aie | 0:5c1439ae6776 | 11 | cs = 1; |
aie | 0:5c1439ae6776 | 12 | spi.format(8,3); |
aie | 0:5c1439ae6776 | 13 | device.format(8,3); |
aie | 0:5c1439ae6776 | 14 | spi.frequency(1000000); |
aie | 0:5c1439ae6776 | 15 | device.frequency(1000000); |
aie | 0:5c1439ae6776 | 16 | |
aie | 0:5c1439ae6776 | 17 | led1 = 1; |
aie | 0:5c1439ae6776 | 18 | while(1) { |
aie | 0:5c1439ae6776 | 19 | wait(1); |
aie | 0:5c1439ae6776 | 20 | led1 = !led1; |
aie | 0:5c1439ae6776 | 21 | cs = 0; |
aie | 0:5c1439ae6776 | 22 | spi.write(0x01); |
aie | 0:5c1439ae6776 | 23 | spi.write(0x02); |
aie | 0:5c1439ae6776 | 24 | spi.write(0x03); |
aie | 0:5c1439ae6776 | 25 | spi.write(0x04); |
aie | 0:5c1439ae6776 | 26 | spi.write(0x05); |
aie | 0:5c1439ae6776 | 27 | spi.write(0x06); |
aie | 0:5c1439ae6776 | 28 | spi.write(0x07); |
aie | 0:5c1439ae6776 | 29 | spi.write(0x08); |
aie | 0:5c1439ae6776 | 30 | cs = 1; |
aie | 0:5c1439ae6776 | 31 | |
aie | 0:5c1439ae6776 | 32 | int d1 = device.read(); |
aie | 0:5c1439ae6776 | 33 | int d2 = device.read(); |
aie | 0:5c1439ae6776 | 34 | int d3 = device.read(); |
aie | 0:5c1439ae6776 | 35 | int d4 = device.read(); |
aie | 0:5c1439ae6776 | 36 | int d5 = device.read(); |
aie | 0:5c1439ae6776 | 37 | int d6 = device.read(); |
aie | 0:5c1439ae6776 | 38 | int d7 = device.read(); |
aie | 0:5c1439ae6776 | 39 | int d8 = device.read(); |
aie | 0:5c1439ae6776 | 40 | |
aie | 0:5c1439ae6776 | 41 | printf("d1=%X d2=%X d3=%X d4=%X d5=%X d6=%X d7=%X d8=%X\r\n", |
aie | 0:5c1439ae6776 | 42 | d1, d2, d3, d4, d5, d6, d7, d8); |
aie | 0:5c1439ae6776 | 43 | |
aie | 0:5c1439ae6776 | 44 | } |
aie | 0:5c1439ae6776 | 45 | } |