Todd Dale
/
SPI_Project_Master
SPI transmission of an array, Master device.
main.cpp@2:b95b33894176, 2018-05-25 (annotated)
- Committer:
- el15tcd
- Date:
- Fri May 25 19:42:57 2018 +0000
- Revision:
- 2:b95b33894176
- Parent:
- 1:c573caf40864
SPI transmission of an array, Master device.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el15tcd | 0:8a61e3541a5e | 1 | #include "mbed.h" |
el15tcd | 0:8a61e3541a5e | 2 | |
el15tcd | 2:b95b33894176 | 3 | SPI lights(p5,p6,p7); |
el15tcd | 2:b95b33894176 | 4 | DigitalOut cs_lights(p8); |
el15tcd | 0:8a61e3541a5e | 5 | |
el15tcd | 0:8a61e3541a5e | 6 | BusOut myleds(LED4, LED3, LED2, LED1); |
el15tcd | 2:b95b33894176 | 7 | DigitalOut led1(LED1); |
el15tcd | 2:b95b33894176 | 8 | DigitalOut led2(LED2); |
el15tcd | 0:8a61e3541a5e | 9 | |
el15tcd | 0:8a61e3541a5e | 10 | int i; |
el15tcd | 1:c573caf40864 | 11 | int j; |
el15tcd | 0:8a61e3541a5e | 12 | |
el15tcd | 2:b95b33894176 | 13 | char v; |
el15tcd | 2:b95b33894176 | 14 | char redArray[8][8]; |
el15tcd | 0:8a61e3541a5e | 15 | |
el15tcd | 0:8a61e3541a5e | 16 | int main() |
el15tcd | 0:8a61e3541a5e | 17 | { |
el15tcd | 0:8a61e3541a5e | 18 | |
el15tcd | 0:8a61e3541a5e | 19 | myleds = 0; |
el15tcd | 0:8a61e3541a5e | 20 | |
el15tcd | 2:b95b33894176 | 21 | for (i = 0; i < 8; i++) { |
el15tcd | 2:b95b33894176 | 22 | for (j = 0; j < 8; j++) { |
el15tcd | 2:b95b33894176 | 23 | redArray[i][j] = 0x30; |
el15tcd | 2:b95b33894176 | 24 | } |
el15tcd | 2:b95b33894176 | 25 | } |
el15tcd | 2:b95b33894176 | 26 | //Array values defined |
el15tcd | 0:8a61e3541a5e | 27 | |
el15tcd | 2:b95b33894176 | 28 | cs_lights = 1; //data commences when cs = 0 |
el15tcd | 2:b95b33894176 | 29 | |
el15tcd | 2:b95b33894176 | 30 | lights.format(8,3); //8 bit data (or 16 bit), mode 3 |
el15tcd | 2:b95b33894176 | 31 | lights.frequency(1000000); //1MHz clock rate |
el15tcd | 2:b95b33894176 | 32 | wait(0.5); |
el15tcd | 0:8a61e3541a5e | 33 | |
el15tcd | 0:8a61e3541a5e | 34 | while(1) { |
el15tcd | 2:b95b33894176 | 35 | led1 = !led1; |
el15tcd | 2:b95b33894176 | 36 | cs_lights = 0; //selects the slave connected to cs_lights to receive data |
el15tcd | 2:b95b33894176 | 37 | v = lights.write(0x01); //start bit |
el15tcd | 2:b95b33894176 | 38 | for (i = 0; i < 8; i++) { |
el15tcd | 2:b95b33894176 | 39 | for (j = 0; j < 8; j++) { |
el15tcd | 2:b95b33894176 | 40 | lights.write(redArray[i][j]); |
el15tcd | 1:c573caf40864 | 41 | } |
el15tcd | 0:8a61e3541a5e | 42 | } |
el15tcd | 2:b95b33894176 | 43 | cs_lights = 1; //stops transmission of data to selected slave |
el15tcd | 2:b95b33894176 | 44 | wait(0.1); |
el15tcd | 0:8a61e3541a5e | 45 | } |
el15tcd | 0:8a61e3541a5e | 46 | } |
el15tcd | 0:8a61e3541a5e | 47 | |
el15tcd | 1:c573caf40864 | 48 | |
el15tcd | 1:c573caf40864 | 49 |