Todd Dale
/
SPI_Project_Master
SPI transmission of an array, Master device.
Revision 2:b95b33894176, committed 2018-05-25
- Comitter:
- el15tcd
- Date:
- Fri May 25 19:42:57 2018 +0000
- Parent:
- 1:c573caf40864
- Commit message:
- SPI transmission of an array, Master device.
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Mon Feb 19 13:09:13 2018 +0000 +++ b/main.cpp Fri May 25 19:42:57 2018 +0000 @@ -1,142 +1,49 @@ #include "mbed.h" -//DigitalIn trigger(p22); -//DigitalOut transmit(p28); - -DigitalIn tl(p17); //change to correct board -DigitalIn tr(p18); -DigitalIn bl(p19); -DigitalIn br(p20); - -Serial device(p28,p27); //tx,rx +SPI lights(p5,p6,p7); +DigitalOut cs_lights(p8); BusOut myleds(LED4, LED3, LED2, LED1); - -int buffer[4]; -int temp1; +DigitalOut led1(LED1); +DigitalOut led2(LED2); -int row; -int columns; - -char array[4]; -char matrix[2][2]; int i; int j; -void Array(); -void Matrix(); +char v; +char redArray[8][8]; int main() { myleds = 0; - device.baud(19200); - buffer[0] = 1; - buffer[1] = 0; - buffer[2] = 1; - buffer[3] = 0; -// buffer[4] = 0; -// buffer[5] = 0; -// buffer[6] = 1; -// buffer[7] = 0; + for (i = 0; i < 8; i++) { + for (j = 0; j < 8; j++) { + redArray[i][j] = 0x30; + } + } + //Array values defined - array[0] = 0; - array[1] = 0; - array[2] = 0; - array[3] = 0; + cs_lights = 1; //data commences when cs = 0 + + lights.format(8,3); //8 bit data (or 16 bit), mode 3 + lights.frequency(1000000); //1MHz clock rate + wait(0.5); while(1) { - - if (tl > 0) { - myleds = 1; - } else { - myleds = 0; - } - - //Array(); - - Matrix(); - - device.putc(1); - for (int i=0; i<2; i++) { - for (int j=0; j<2; j++) { - - //device.printf("%i",buffer[i]); - - //device.putc(buffer[i]); - device.putc(matrix[i][j]); + led1 = !led1; + cs_lights = 0; //selects the slave connected to cs_lights to receive data + v = lights.write(0x01); //start bit + for (i = 0; i < 8; i++) { + for (j = 0; j < 8; j++) { + lights.write(redArray[i][j]); } } - //wait(1); + cs_lights = 1; //stops transmission of data to selected slave + wait(0.1); } - } -void Array() -{ - for(i=0; i<=1 ; i=i+1) { - if (i == 0) { - if (tl > 0) { - array[0] = 1; - } else { - array[0] = 0; - } - } else if (i == 1) { - if (tr > 0) { - array[1] = 1; - } else { - array[1] = 0; - } - } - } - for(i=0; i<=1 ; i=i+1) { - if (i == 0) { - if (bl > 0) { - array[2] = 1; - } else { - array[2] = 0; - } - } else if (i == 1) { - if (br > 0) { - array[3] = 1; - } else { - array[3] = 0; - } - } - } - /* - for (row=0; row<2; row++) { - for(columns=0; columns<2; columns++) { - printf("%d ", array[row][columns]); - } - printf("\n"); - }*/ - //printf("\n"); -} -void Matrix() -{ - if (tl > 0) { - matrix[0][0] = 1; - } else { - matrix[0][0] = 0; - } - if (tr > 0) { - matrix[0][1] = 1; - } else { - matrix[0][1] = 0; - } - if (bl > 0) { - matrix[1][0] = 1; - } else { - matrix[1][0] = 0; - } - if (br > 0) { - matrix[1][1] = 1; - } else { - matrix[1][1] = 0; - } - -}