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.
Dependencies: mbed
Diff: main.cpp
- Revision:
- 0:3cf5359a87e8
diff -r 000000000000 -r 3cf5359a87e8 main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Fri Jan 17 20:33:26 2014 +0000
@@ -0,0 +1,77 @@
+#include "mbed.h"
+
+DigitalOut redLed( LED_RED ); // Led used to signal errors
+DigitalOut spiSS( PTD0 ); // Slave select is handled by GPIO
+
+int main() {
+ redLed = 0;
+ // Create SPI master instance, 8bit, CPOL=0, CPHA=1, 100kHz
+ SPI spiMaster( PTD2, PTD3, PTD1 ); // mosi, miso, sclk
+ spiMaster.format( 8, 1 );
+ spiMaster.frequency( 10000 );
+ // Deselect slave
+ spiSS = 1;
+ // Forever
+ wait(1);
+
+ while( 1 ) {
+ int rx, dd1, dd2;
+ // Burst write
+ spiSS = 0;
+ spiMaster.write( '#' );
+ spiMaster.write( 0x07 ); // write RAM burst
+ spiMaster.write( 0x01 ); // AA1
+ spiMaster.write( 0x02 ); // AA2
+ spiMaster.write( 0x03 ); // AA3
+
+
+ for(int i = 0; i < 100; i++ ){
+ spiMaster.write( i ); // DD1
+ spiMaster.write( i+1 ); // DD2
+
+ do{
+ rx = spiMaster.write( 0x55 );
+ }while( rx != '@' );
+ rx = 0;
+ }
+
+ spiMaster.write( '#' ); // termina burst
+
+
+ spiSS = 1;
+ wait( 1 );
+
+ // Burst Read
+ spiSS = 0;
+ spiMaster.write( '#' );
+ spiMaster.write( 0x05 ); // burst read RAM
+ spiMaster.write( 0x01 ); // AA1
+ spiMaster.write( 0x02 ); // AA2
+ spiMaster.write( 0x03 ); // AA3
+
+ for(int i = 0; i < 100; i++ ){
+ do{
+ rx = spiMaster.write( 0x55 );
+ }while( rx != '@' );
+ rx = 0;
+
+ dd1 = spiMaster.write( 0x55 );
+ dd2 = spiMaster.write( 0x55 );
+
+ //if( (dd1 == i) && (dd2 == (i+2))){
+ // redLed = 1;
+ //}
+
+ if(( dd1 != i ) or (dd2 != (i+1) )){
+ redLed = 0; // NON DEVE SBAGLIARE
+ //wait( 0.5 );
+ }
+ redLed = 1;
+
+ //redLed = 0;
+ //wait( 0.5 );
+ }
+
+ spiSS = 1;
+ }
+}