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.
Revision 9:db5c39c8cf42, committed 2014-01-28
- Comitter:
- jlpalaci
- Date:
- Tue Jan 28 00:10:05 2014 +0000
- Parent:
- 7:d1eba8f22f3e
- Commit message:
- Version final en base de funcines de C para la lectura/escritura de meorias SD.
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Wed Jan 08 05:13:45 2014 +0000
+++ b/main.cpp Tue Jan 28 00:10:05 2014 +0000
@@ -14,8 +14,9 @@
//SD FAT system
SDFileSystem sd(PTD2, PTD3, PTD1, PTD0,"sd");
//Comunicación Xbee
-Serial xbee(PTA2,PTA1);
-//Serial xbee(USBTX,USBRX);
+Serial xbee(PTA2,PTA1); //Serial xbee(USBTX,USBRX);
+//Pin de control de flujo RTS (usado en la función Serial_RTS)
+DigitalIn rts(PTD4);
//Definición de variables globales
@@ -24,9 +25,16 @@
int inicio = 0;
int fin = 0;
int samples = 1;
+int imax = 0;
char read [64] = {0};
char readvar [512] = {0};
+
+//Declaración de la función UART con control de flujo
+//Sólo RTS
+int Serial_RTS(const char *str);
+
+
int main()
{
//xbee.baud(9600);
@@ -36,17 +44,20 @@
g_sel = 0; //Ajusta la sensibilidad a 1.5g (cambiar a 1 para ajustar sensibilidad a 6g)
while(1) {
- //char read [64] = {0};
- //char readvar [512] = {0};
-
xbee.scanf("%s",read); //Espera la recepción de caracteres
switch(read[0]) {
case 'r': //Lee la información de la memoria SD y la envía mediante Xbee
//if(read[1]=='1') { //Nombre para modulo 1...
fp2 = fopen ("/sd/test.txt","r");
- for (int i=0; i<samples/3; i++) {
+
+ if(samples%42==0 && samples>42) imax=samples/42;
+ else imax=samples/42;
+ //imax=samples/42;
+
+ for (int i=0; i<imax; i++) {
fscanf (fp2,"%s",readvar);
- xbee.printf("%s",readvar);
+ //xbee.printf("%s",readvar);
+ Serial_RTS(readvar);
xbee.putc('\n');
}
fclose (fp2);
@@ -65,7 +76,7 @@
//Ciclo de lectura de los ejes x, y, z del acelerómetro triaxial MMA7361L
for(int i=1; i<=samples; i++) {
fprintf (fp1,"%04X%04X%04X",ain_x.read_u16(),ain_y.read_u16(),ain_z.read_u16());
- if((i>=42) && (i%3==42)) fprintf (fp1,"\n"); //cambiar a 3 para longitud de 12 caracteres
+ if((i>=42) && (i%42==0)) fprintf (fp1,"\n");
}
//Tiempo transcurrido desde la ejecución del reloj
fin = reloj.read_us();
@@ -73,4 +84,15 @@
break;
}
}
+}
+
+
+//Definición de la función UART RTS
+int Serial_RTS(const char *str)
+{
+ while (*str) {
+ while(rts);
+ xbee.putc(*str ++);
+ }
+ return 0;
}
\ No newline at end of file