mi mi
/
DirectSPI-test
DirectSPI test program
Diff: main.cpp
- Revision:
- 3:b573ad5a8eb7
- Parent:
- 2:688a56c37441
- Child:
- 4:8173ee6ae31b
--- a/main.cpp Thu Feb 23 01:01:22 2017 +0900 +++ b/main.cpp Thu Feb 23 22:25:26 2017 +0900 @@ -1,31 +1,67 @@ #include "mbed.h" #include "DirectSPI.h" + /* SPI1 */ #define MOSI D11 /* PA_7 */ #define MISO D12 /* PA_6 */ #define SCLK D13 /* PA_5 */ #define CS D10 /* PB_6 or etc. */ + DirectSPI spi(MOSI, MISO, SCLK); // mosi, miso, sclk DigitalOut cs(CS); -#define DATA8BIT 1 -int main() { -#if DATA8BIT +/* auto width transfer test */ +void test_auto() { spi.format(8,3); -#else - spi.format(16,3); -#endif - spi.frequency(24*1000000); - while(1){ cs = 1; -#if DATA8BIT + spi.directWrite(0xaa); + spi.directWrite(0xaa); + cs = 0; + } +} + +/* 8bit width transfer test */ +void test_bit8() { + spi.format(8,3); + while(1){ + cs = 1; spi.directWrite8(0xaa); spi.directWrite8(0xaa); -#else - spi.directWrite16(0x5503); - spi.directWrite16(0x5503); -#endif cs = 0; } } + +/* 16bit width transfer test */ +void test_bit16() { + spi.format(16,3); + while(1){ + cs = 1; + spi.directWrite16(0x5503); + spi.directWrite16(0x5503); + cs = 0; + } +} + +/* 8bit width transfer test using standard library*/ +void test_std8() { + spi.format(8,3); + while(1){ + cs = 1; + spi.write(0xaa); + spi.write(0xaa); + cs = 0; + } +} + +int main(){ + spi.frequency(24 * 1000000); + + /* Select the one of the test function */ + //test_auto(); + test_bit8(); + //test_bit16(); + //test_std8(); +} + +