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 X_NUCLEO_IKS01A2
Revision 20:e444e7dd815a, committed 2021-11-03
- Comitter:
- berajay
- Date:
- Wed Nov 03 18:06:48 2021 +0000
- Parent:
- 19:00a099052986
- Commit message:
- STM32F401RE + ISK01A2 + SD Module + GPS Neo 6m
Changed in this revision
--- a/MODSERIAL.lib Wed Nov 03 12:18:19 2021 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -https://os.mbed.com/teams/The-Technology-Partnership/code/MODSERIAL/#2212721dd3fe
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SDFileSystem.lib Wed Nov 03 18:06:48 2021 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/berajay/code/STM32F401RE/#b987b963c3af
--- a/SDFileSystemDMA.lib Wed Nov 03 12:18:19 2021 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -https://os.mbed.com/users/berajay/code/Embedded_System/#5326c8f4849f
--- a/main.cpp Wed Nov 03 12:18:19 2021 +0000 +++ b/main.cpp Wed Nov 03 18:06:48 2021 +0000 @@ -1,27 +1,19 @@ /* Includes */ #include "mbed.h" #include "XNucleoIKS01A2.h" -#include "SDFileSystemDMA.h" +#include "SDFileSystem.h" #include "FATFileSystem.h" #include "iostream" -#include "main.h" +Serial pc(USBTX, USBRX, 115200); +Serial gps(D8, D2, 9800); -Serial pc(USBTX, USBRX); SDFileSystem sd(D11, D12, D13, D10, "sd");// the pinout on the mbed Cool Components workshop board FILE *fp; -//SDFileSystem sd( D11, D12, D13, D10, "sd"); - - -Serial gps(D8, D2); - - - /* Instantiate the expansion board */ static XNucleoIKS01A2 *mems_expansion_board = XNucleoIKS01A2::instance(D14, D15, D4, D5); - /* Retrieve the composing elements of the expansion board */ static LSM6DSLSensor *acc_gyro = mems_expansion_board->acc_gyro; static LSM303AGRAccSensor *accelerometer = mems_expansion_board->accelerometer; @@ -30,50 +22,41 @@ bool live_writing = false; // GPS +char cDataBuffer[500]; +int i = 0; char c; -void parse(char *cmd, int n) -{ - +void parse(char *cmd, int n){ char ns, ew, tf, status; - int fq, nst, fix, date; // fix quality, Number of satellites being tracked, 3D fix + int fq, nst, fix, date; // fix quality, Number of satellites being tracked, 3D fix float latitude, longitude, timefix, speed, altitude; - - + // Global Positioning System Fix Data - if(strncmp(cmd,"$GPGGA", 6) == 0) - { + if(strncmp(cmd,"$GPGGA", 6) == 0){ sscanf(cmd, "$GPGGA,%f,%f,%c,%f,%c,%d,%d,%*f,%f", &timefix, &latitude, &ns, &longitude, &ew, &fq, &nst, &altitude); - pc.printf("GPGGA Fix taken at: %f, Latitude: %f %c, Longitude: %f %c, Fix quality: %d, Number of sat: %d, Altitude: %f M\r\n", timefix, latitude, ns, longitude, ew, fq, nst, altitude); + printf("GPGGA Fix taken at: %f, Latitude: %f %c, Longitude: %f %c, Fix quality: %d, Number of sat: %d, Altitude: %f M\r\n", timefix, latitude, ns, longitude, ew, fq, nst, altitude); } // Satellite status - if(strncmp(cmd,"$GPGSA", 6) == 0) - { + if(strncmp(cmd,"$GPGSA", 6) == 0){ sscanf(cmd, "$GPGSA,%c,%d,%d", &tf, &fix, &nst); - pc.printf("GPGSA Type fix: %c, 3D fix: %d, number of sat: %d\r\n", tf, fix, nst); - } - - // Geographic position, Latitude and Longitude - if(strncmp(cmd,"$GPGLL", 6) == 0) - { - sscanf(cmd, "$GPGLL,%f,%c,%f,%c,%f", &latitude, &ns, &longitude, &ew, &timefix); - pc.printf("GPGLL Latitude: %f %c, Longitude: %f %c, Fix taken at: %f\r\n", latitude, ns, longitude, ew, timefix); + printf("GPGSA Type fix: %c, 3D fix: %d, number of sat: %d\r\n", tf, fix, nst); } // Geographic position, Latitude and Longitude - if(strncmp(cmd,"$GPRMC", 6) == 0) - { + if(strncmp(cmd,"$GPGLL", 6) == 0){ + sscanf(cmd, "$GPGLL,%f,%c,%f,%c,%f", &latitude, &ns, &longitude, &ew, &timefix); + printf("GPGLL Latitude: %f %c, Longitude: %f %c, Fix taken at: %f\r\n", latitude, ns, longitude, ew, timefix); + } + + // Geographic position, Latitude and Longitude + if(strncmp(cmd,"$GPRMC", 6) == 0){ sscanf(cmd, "$GPRMC,%f,%c,%f,%c,%f,%c,%f,,%d", &timefix, &status, &latitude, &ns, &longitude, &ew, &speed, &date); - pc.printf("GPRMC Fix taken at: %f, Status: %c, Latitude: %f %c, Longitude: %f %c, Speed: %f, Date: %d\r\n", timefix, status, latitude, ns, longitude, ew, speed, date); + printf("GPRMC Fix taken at: %f, Status: %c, Latitude: %f %c, Longitude: %f %c, Speed: %f, Date: %d\r\n", timefix, status, latitude, ns, longitude, ew, speed, date); } } - /* Simple main function */ int main() { - //GPS gps = GPS(D8,D2); - gps.baud(9600); - pc.baud(115200); uint8_t id; int32_t x_axes[3]; int32_t g_axes[3]; @@ -82,13 +65,12 @@ float x_sens[2]; float x_fs[2]; // Take time (https://unixtime.org/) - set_time(1634379120); + set_time(1635956827); // DATE char s[100]; time_t t_l = time (NULL); struct tm *tp = localtime (&t_l); - //strftime (s,100, "\t %d %B %Y %H:%M:%S\r\n", tp); strftime (s,100, "\n\t %d %B %Y %H:%M:%S\r\n", tp); printf ("%s", s); @@ -110,12 +92,12 @@ Timer t; Timer t_down; float time[arr_lenght]; -// int acc_x[arr_lenght]; -// int acc_y[arr_lenght]; - //int acc_z[arr_lenght]; - //int gyro_x[arr_lenght]; - //int gyro_y[arr_lenght]; - //int gyro_z[arr_lenght]; + int acc_x[arr_lenght]; + int acc_y[arr_lenght]; + int acc_z[arr_lenght]; + int gyro_x[arr_lenght]; + int gyro_y[arr_lenght]; + int gyro_z[arr_lenght]; float frequency = 1000.0; float range = 8.0; //SET @@ -132,14 +114,13 @@ acc_gyro->get_x_fs(x_fs); printf("Accelerometer meas. range: %.1f, %.1f\r\n", x_fs[0],x_fs[1]); - pc.printf("Check GPS\r\n"); + printf("Check GPS\r\n"); while(1){ if(gps.readable()){ if(gps.getc() == '$');{ // wait a $ for(int i=0; i<sizeof(cDataBuffer); i++){ c = gps.getc(); if( c == '\r' ){ - //pc.printf("%s\n", cDataBuffer); parse(cDataBuffer, i); i = sizeof(cDataBuffer); }else{ @@ -152,9 +133,7 @@ break; } } - - - fprintf(fp, " DATA of STM32F401RE with ISK01A2\r\n"); + printf("OK\r\n"); printf("\r\n"); /* Start the cycle*/ @@ -166,7 +145,7 @@ //Initialize SD CARD char filename[64]; char date[64]; - pc.printf("Check SD\r\n"); + printf("Check SD\r\n"); mkdir("/sd/ISK01A2", 0777); int name = 0; // Save name with next name test_001,test_002, ecc... @@ -187,7 +166,6 @@ // Name file on monitor printf("\n\t test_%03d \r\n", name); - strftime (date,64, "%d %B %Y %H:%M", tp); fprintf(fp, "\t %s \n", date); //DATE fprintf(fp, "N,Time,Temp[C],Acc_x[mg],Acc_y[mg],Acc_z[mg],Gyro_x[mdps],Gyro_y[mdps],Gyro_z[mdps]\r\n"); //Header in the file text @@ -195,43 +173,48 @@ printf("\r\n START NEW RUNNING \r\n"); t.start(); } else { // button is pressed but live_writing is true - t_down.stop(); - pc.printf(" timer download sd: %3.3f\r\n",t_down.read()); - t_down.reset(); // Now we write into sd card all data storaged t.stop(); + int i; + //int elementi = sizeof(acc_x)/sizeof(int); + + for (i=0; i<=n; i++){ + fprintf(fp,"%3d,%3.3f,%6ld,%6ld,%6ld,%6ld,%6ld,%6ld\r\n", i, time[i], acc_x[i], acc_y[i], acc_z[i], gyro_x[i], gyro_y[i], gyro_z[i]); //Save current data into file txt + //printf("%3d,%3.3f,%6ld,%6ld,%6ld,%6ld,%6ld,%6ld\r\n", i, time[i], acc_x[i], acc_y[i], acc_z[i], gyro_x[i], gyro_y[i], gyro_z[i]); + } t.reset(); fclose(fp); - pc.printf("File successfully written!\r\n"); + printf("File successfully written!\r\n"); live_writing = false; wait(2); }//end else } //end if userbutton - if (live_writing==true){ - t_down.start(); + if (live_writing==true){ acc_gyro->get_x_axes(x_axes); //Read data from LSM6DSL accelerometer - //acc_x[n] = x_axes[0]; - //acc_y[n] = x_axes[1]; - //acc_z[n] = x_axes[2]; + acc_x[n] = x_axes[0]; + acc_y[n] = x_axes[1]; + acc_z[n] = x_axes[2]; acc_gyro->get_g_axes(g_axes); //Read data from LSM6DSL gyroscope - //gyro_x[n] = g_axes[0]; - //gyro_y[n] = g_axes[1]; - //gyro_z[n] = g_axes[2]; + gyro_x[n] = g_axes[0]; + gyro_y[n] = g_axes[1]; + gyro_z[n] = g_axes[2]; time[n] = t.read(); - fprintf(fp,"%3d,%3.3f,%6ld,%6ld,%6ld,%6ld,%6ld,%6ld\r\n", n, time[n], x_axes[0], x_axes[1], x_axes[2], g_axes[0], g_axes[1], g_axes[2]); n+=1; if (n==arr_lenght){ - t_down.stop(); - pc.printf(" timer download sd: %3.3f\r\n",t_down.read()); - t_down.reset(); t.stop(); + int i; + + for (i=0; i<=n; i++){ + fprintf(fp,"%3d,%3.3f,%6ld,%6ld,%6ld,%6ld,%6ld,%6ld\r\n", i, time[i], acc_x[i], acc_y[i], acc_z[i], gyro_x[i], gyro_y[i], gyro_z[i]); //Save current data into file txt + //printf("%3d,%3.3f,%6ld,%6ld,%6ld,%6ld,%6ld,%6ld\r\n", i, time[i], acc_x[i], acc_y[i], acc_z[i], gyro_x[i], gyro_y[i], gyro_z[i]); + } t.reset(); fclose(fp); - pc.printf("File successfully written!\r\n"); + printf("File successfully written!\r\n"); live_writing = false; wait(2); }
--- a/main.h Wed Nov 03 12:18:19 2021 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,18 +0,0 @@ -#pragma once -#include "mbed.h" -#include "MODSERIAL.h" - -//MODSERIAL pc(USBTX,USBRX); - -#if defined(TARGET_LPC1768) -MODSERIAL gps(D8, D2); //tx rx -#elif defined(TARGET_LPC4330_M4) -MODSERIAL gps(UART0_TX, UART0_RX); -#endif - -char cDataBuffer[500]; -int i = 0; - - -void Init(); -void parse(char *cmd, int n);