Éric Poirier
/
SPI_labo1
Labo APP1 (SPI)
Revision 0:f59252c7524a, committed 2017-08-30
- Comitter:
- BobMorane22
- Date:
- Wed Aug 30 18:44:38 2017 +0000
- Commit message:
- SPI example working. 7 segment resets itself automatically.
Changed in this revision
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
spi.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r f59252c7524a mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Aug 30 18:44:38 2017 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/e2bfab296f20 \ No newline at end of file
diff -r 000000000000 -r f59252c7524a spi.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/spi.cpp Wed Aug 30 18:44:38 2017 +0000 @@ -0,0 +1,38 @@ +#include "mbed.h" + +#define ON 0x00 +#define OFF 0x01 +#define ALWAYS 0x01 +#define CLEAR_7SEG 0x76 + +// PC <-USB-> Microcontroller: +Serial pc(USBTX, USBRX); // tx, rx + +// 7segment <-SPI-> Microcontroller: +SPI seg7(p11, p12, p13); + +// Slave select: +DigitalOut cs(p14); + + +int main() +{ + int value = 0; + cs = OFF; + + while(ALWAYS) + { + pc.printf("Value: "); + pc.scanf("%d", &value); + pc.printf("%d\r\n", value); + + cs = ON; + + // Clear and write data: + seg7.write(CLEAR_7SEG); + wait(0.2); + seg7.write(value); + + cs = OFF; + } +} \ No newline at end of file