Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 #include "mbed.h" 00002 #include "DirectSPI.h" 00003 00004 00005 /* SPI1 */ 00006 #define MOSI SPI_MOSI /* D11 PA_7 */ 00007 #define MISO SPI_MISO /* D12 PA_6 */ 00008 #define SCLK SPI_SCK /* D13 PA_5 */ 00009 #define CS SPI_CS /* D10 PB_6 */ 00010 00011 DirectSPI spi(MOSI, MISO, SCLK); // mosi, miso, sclk 00012 DigitalOut cs(CS); 00013 00014 /* auto width transfer test */ 00015 void test_auto() { 00016 spi.format(8,3); 00017 while(1){ 00018 cs = 1; 00019 spi.directWrite(0xaa); 00020 spi.directWrite(0xaa); 00021 cs = 0; 00022 } 00023 } 00024 00025 /* 8bit width transfer test */ 00026 void test_bit8() { 00027 spi.format(8,3); 00028 while(1){ 00029 cs = 1; 00030 spi.directWrite8(0xaa); 00031 spi.directWrite8(0xaa); 00032 cs = 0; 00033 } 00034 } 00035 00036 /* 16bit width transfer test */ 00037 void test_bit16() { 00038 spi.format(16,3); 00039 while(1){ 00040 cs = 1; 00041 spi.directWrite16(0x5503); 00042 spi.directWrite16(0x5503); 00043 cs = 0; 00044 } 00045 } 00046 00047 /* 8bit width transfer test using standard library*/ 00048 void test_std8() { 00049 spi.format(8,3); 00050 while(1){ 00051 cs = 1; 00052 spi.write(0xaa); 00053 spi.write(0xaa); 00054 cs = 0; 00055 } 00056 } 00057 00058 int main(){ 00059 spi.frequency(24 * 1000000); 00060 00061 /* Select the one of the test function */ 00062 //test_auto(); 00063 test_bit8(); 00064 //test_bit16(); 00065 //test_std8(); 00066 } 00067 00068
Generated on Fri Jul 22 2022 00:46:00 by
1.7.2