Lab 3

Dependencies:   MMA8451Q mbed

Files at this revision

API Documentation at this revision

Comitter:
serenabpolito
Date:
Wed Jan 14 11:31:47 2015 +0000
Commit message:
Lab 3

Changed in this revision

MMA8451Q.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MMA8451Q.lib	Wed Jan 14 11:31:47 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/emilmont/code/MMA8451Q/#c4d879a39775
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Jan 14 11:31:47 2015 +0000
@@ -0,0 +1,73 @@
+#include "mbed.h"
+#include "MMA8451Q.h"
+#include "SPI.h"
+#include "DigitalOut.h"
+
+
+
+
+PinName const mosi = PTD2; //mosi SPI1_mosi
+PinName const miso = PTD3; //miso SPI1_miso
+PinName const sck  = PTD1; //sck SPI1_sck
+PinName const pcs0 = PTD0; //pcs0 SPI1_pcs0
+
+
+#define MMA8451_I2C_ADDRESS (0x1d<<1)
+
+
+
+//instanzia e inizializza oggettto spi della classe SPI
+SPI spi(mosi,miso,sck);
+
+DigitalOut slave_select(pcs0,1); //inizializza slave-select
+                        
+
+
+//int spi_write(character,location)
+//{ 
+//int command = 1000000;
+//int location 
+//spi
+//(char)(65+1)
+//char charecter
+
+
+
+int main(void)
+{
+    
+       //comunicazione con SPI
+        int bits = 8;
+        int mode = 1;
+        spi.format(bits,mode);//definisce formato spi con 16 bit e pol=0 e pha=1
+        //di default la frequenza è 1MHz
+        
+        char character;
+        char lettura;
+        int i;
+       while(1)
+       {
+        int command_wr=128; //comando per la scrittura (10000DDD), di default nella locazione DDD=000
+        //int command_rd=0; //comando per la lettura (00000DDD), dib default nella locazione DDD=000
+       //for(i=0;i<7;i++)
+       //{
+        //character=(char)(65+i);
+       //scrittura
+        slave_select.write(0);
+        spi.write(133);
+        spi.write(3);
+        slave_select.write(1);
+        printf("Carattere in ingresso %c\n",character);
+        //command_wr++;
+        
+        //lettura
+        //slave_select.write(0);
+        //spi.write(command_rd);
+       // lettura=(char)spi.write((int)character);
+        //slave_select.write(1);
+        //printf("Carattere in uscita %c\n",lettura);
+       // command_rd++;
+       // }   
+        }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Jan 14 11:31:47 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/4fc01daae5a5
\ No newline at end of file