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.
Diff: main.cpp
- Revision:
- 0:b191e77dc856
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Mon Feb 27 16:30:10 2012 +0000
@@ -0,0 +1,60 @@
+#include "mbed.h"
+
+
+SPI spi(p11, p12, p13); // mosi, miso, sclk
+DigitalOut cs(p14);
+
+Serial pc(USBTX, USBRX); // tx, rx
+
+// Not possible to use inline assembler language with this device, error 1044
+/*#pragma arm
+void NOP()
+{
+
+ __asm
+ {
+ NOP
+ }
+}
+#pragma thumb*/
+
+
+
+
+
+int main() {
+ // Setup the spi for 8 bit data, high steady state clock,
+ // second edge capture, with a 1MHz clock rate
+ spi.format(8,0);
+ spi.frequency(1000000);
+ int teste, result, b=0;
+
+
+ teste=0xAA;
+
+ cs=0;
+ pc.printf("Answer before = %d\n\r", teste);
+
+
+ spi.write(teste);
+
+ cs=1; // it's necessary to close and open the connection for the program to work, we believe that's necessary to exchange the buffer values
+ // not exactly sure how much must this delay be
+
+ if(b<1){} // delay necessary between closing and opening a connection with the slave, we believe it's because of the high clock value of the mbed
+
+
+
+ cs=0;
+ result=spi.write(0x00); // to read the value of the previous reply from the slave, it's necessary to make another write sending a dummy byte
+ cs=1;
+
+
+ pc.printf("Answer later= 0x%X\n\r", result);
+ // Maybe what is happening is that we need a bigger delay between the two writes so that it works the first time,maybe result is showing not the
+ //value of the previous write in this run of the program, but the value stored in the buffer in the previous run
+
+
+
+
+}
\ No newline at end of file