Patrik GONDA / Mbed 2 deprecated micromag3

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "MSCFileSystem.h"
00003 
00004 Serial usb(USBTX,USBRX);
00005 //Serial ft(p28,p27);
00006 DigitalOut led(LED1);
00007 //LocalFileSystem fs("fs");
00008 MSCFileSystem  fs("fs");
00009 SPI spi(p5,p6,p7); //mosi,miso,sck
00010 
00011 DigitalOut ssnot(p8);
00012 DigitalOut reset(p9);
00013 DigitalIn drdy(p10);
00014 
00015 int x = 0;
00016 int y = 0;
00017 int z = 0;
00018 int heading = 0;
00019 float pauza = 0.0001;
00020 char subor[] = "/fs/data_1.csv";
00021 const char base1[] = "/fs/data_";
00022 const char base2[] = ".csv";
00023 FILE *fp;
00024 
00025 void setup() {
00026     usb.baud(921600);
00027     led = 1;
00028     spi.format(8,3);
00029     spi.frequency(1000000);
00030 
00031 
00032 
00033 }
00034 int main() {
00035     int ps = 1;
00036     // sprintf(subor, "%s%d%s",base1,ps,base2);
00037     //   FILE *fp = fopen(subor,"w");
00038     setup();
00039     int signx = 0;
00040     int signy = 0;
00041     int signz = 0;
00042     int i = 0;
00043 
00044     
00045     while (1) {
00046        
00047 
00048      
00049        
00050             ssnot = 0;
00051             /*    if (i==0) {
00052                     FILE *fp = fopen(subor,"w");
00053                 }*/
00054             led = 1;
00055             reset = 0;
00056             wait(pauza);
00057             reset = 1;
00058             wait(pauza);
00059             reset = 0;
00060 
00061 
00062             //ciatanie
00063             wait(pauza);
00064             spi.write(0x11);
00065             while (drdy == 0) {
00066             }
00067 
00068             x = spi.write(0x00);
00069             //signx = (x & 128) >> 7;
00070             x = x << 8;
00071             x |= spi.write(0x00);
00072             signx = (x & 0x8000) >>  15;
00073             x = x & 0x7FFF;
00074             if (signx==1) {
00075                 x = x - 32768;
00076             }
00077 
00078             reset = 0;
00079             wait(pauza);
00080             reset = 1;
00081             wait(pauza);
00082             reset = 0;
00083 
00084             wait(pauza);
00085             spi.write(0x12);
00086             while (drdy == 0) {
00087             }
00088 
00089             y = spi.write(0x00);
00090             // signy = (y & 128) >> 7;
00091             y = y << 8;
00092             y |= spi.write(0x00);
00093             signy = (y & 0x8000) >> 15;
00094             y = y & 0x7FFF;
00095 
00096             if (signy==1) {
00097                 y = y - 32768;
00098             }
00099 
00100             reset = 0;
00101             wait(pauza);
00102             reset = 1;
00103             wait(pauza);
00104             reset = 0;
00105 
00106             wait(pauza);
00107             spi.write(0x13);
00108             while (drdy == 0) {
00109             }
00110 
00111             z = spi.write(0x00);
00112             z = z << 8;
00113             z |= spi.write(0x00);
00114             signz = (z & 0x8000) >> 15;
00115             z = z & 0x7FFF;
00116 
00117 
00118             if (signz==1) {
00119                 z = z - 32768;
00120             }
00121             wait(0.0002);
00122 
00123             usb.printf("%ld %ld %ld %ld\r\n",x,y,z,z);
00124             /*if (i<=1024) {
00125                  fprintf(fp,"%ld %ld %ld %ld\r\n",x,y,z,z);
00126                  i++;
00127              } else {
00128                  fclose(fp);
00129                   ps++;
00130                  sprintf(subor, "%s%d%s",base1,ps,base2);
00131 
00132                  i=0;
00133                  led = 0;
00134              }*/
00135 
00136             // led = 0;
00137             wait(0.0003);
00138             ssnot=1;
00139          
00140             // wait(1);
00141         }
00142     }
00143 }