|
|
View previous topic :: View next topic |
Author |
Message |
filjoa
Joined: 04 May 2008 Posts: 260
|
Problem with arrays |
Posted: Thu May 16, 2013 7:56 pm |
|
|
Hi
I write a program to read strings from GPS, but I don't know what happens with arrays...
Code: |
void read_protocol(void)
{
int i=0, result1 = 0, result2 = 0;
char str1[7], str2[7], prot[7];
str1 = "$GPRMC";
str2 = "$GPGGA";
while(c!='$');
do {
while (data_available==FALSE);
data_available = FALSE;
prot[i]=c;
i++;
}while (c!=',');
result1 = strncmp (str1, prot, 5);
result2 = strncmp (str2, prot, 5);
if (result1 == 0) readgps1();
if (result2 == 0) readgps2();
if (result1 != 0 || result2 !=0) break;
}
//protocolo GPRMC ##
void readgps1(void)
{
char speedstr[10], auxstr[62];
int8 i = 0, speed = 0;
do {
while (data_available==FALSE);
data_available = FALSE;
auxstr[i]=c;
i++;
}while (c!='\r');
fprintf(outport,"%s",auxstr);
fprintf(outport,"\n\r");
}
//protocolo GPRMC ##
void readgps2(void)
{
char auxstr[71];
int8 i = 0;
do {
while (data_available==FALSE);
data_available = FALSE;
auxstr[i]=c;
i++;
}while (c!='\r');
fprintf(outport,"%s",auxstr);
fprintf(outport,"\n\r");
}
|
For example, I need know exactly size of my string, this don´t work if I put an array like this "auxstr[150]" or "auxstr[]", if I put this, I can't see correct string on terminal.
The same happens if I change on function readgps1(), "char speedstr[10], auxstr[62];" to "char auxstr[62], speedstr[10];", only change order.
Some one can explain where stay my error?
best regards |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu May 16, 2013 8:16 pm |
|
|
Quote: |
For example, I need know exactly size of my string, this don't work if I
put an array like this "auxstr[150]" or "auxstr[]", if I put this, I can't see
correct string on terminal.
|
You are probably doing this, from a previous post:
Code: |
#int_rda
void rda_isr(void)
{
c = getc(gpsport);
data_available=TRUE;
}
|
This is not the correct way to do it. You should wait for a start-of-
message character, which is the '$' character. Then start saving
the incoming characters in an array. When you get the end of message
character, you should write a 0x00 to the array, at the end of the
message.
I think it's very likely that you are not writing a 0x00 at the end of
the message. A string is only a string if it has 0x00 at the end of the text.
This doesn't allocate any RAM for the array. It will not work. |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Thu May 16, 2013 8:28 pm |
|
|
Hi,
I'm not really sure what problem what you are reporting, but you are trying to print a 'string' that is not really a string. Keep in mind that a 'C' string is an array of characters that has been 'Null' terminated. Just before you attempt to print the string, add '\0' as the last character in the array (following your character data).
John |
|
|
filjoa
Joined: 04 May 2008 Posts: 260
|
|
Posted: Tue May 21, 2013 3:51 pm |
|
|
Hi
if I try find '\0' program don't work... I need find '\r'
if I don't allocate RAM on my arrays I can't print my string...
Code: |
#int_rda
void rda_isr(void)
{
c = getc(gpsport);
data_available=TRUE;
}
//## escolha e identificação do protocolo GPRMC ##
void read_protocol(void)
{
int i=0, result1 = 0, result2 = 0;
char str1[], str2[], prot[];
str1 = "$GPRMC";
str2 = "$GPGGA";
while(c!='$');
do {
while (data_available==FALSE);
data_available = FALSE;
prot[i]=c;
i++;
}while (c!=',');
result1 = strncmp (str1, prot, 5);
result2 = strncmp (str2, prot, 5);
if (result1 == 0) readgps1();
if (result2 == 0) readgps2();
if (result1 != 0 || result2 !=0) break;
}
//## LER DO GPS protocolo GPRMC ##
void readgps1(void)
{
char auxstr[];
int8 i = 0, speed = 0;
do {
while (data_available==FALSE);
data_available = FALSE;
auxstr[i]=c;
i++;
}while (c!='\r');
// ##### TRATAMENTO DOS DADOS #####
fprintf(outport,"%s", auxstr);
fprintf(outport,"\n\r");
}
|
With this code I detect protocol "$GPRMC" and "$GPGGA", but when I try print it on terminal, my string don't appear correct.
I need save correct string to separate it.
Hi
for example... if I make this:
Quote: |
void readgps1(void)
{
char auxstr[];
int8 i = 0, speed = 0;
do {
while (data_available==FALSE);
data_available = FALSE;
auxstr[i]=c;
i++;
}while (c!= '\r');
speed = i;
// ##### TRATAMENTO DOS DADOS #####
fprintf(outport,"$GPRMC\n\r");
for (i=0;i<speed;i++)
{
fprintf(outport,"%c",auxstr[i]);
}
fprintf(outport,"\n\r");
}
|
resulte is this:
Quote: |
$GPRMC
AccAGPRMC2qp0G000,A,4031.2765GPGGA,223,06,03,01,16,19,22,21,07,18,11,08,,1.17,
0.90,0.76*03
$GPRMC
AccAGPRMC2qp0G000,A,4031.2765GPGGA,223,06,03,01,16,19,22,21,07,18,11,08,,1.17,
0.90,0.76*03
$GPRMC
AccAGPRMC2qp0G000,A,4031.2765GPGGA,223,06,03,01,16,19,22,21,07,18,11,08,,1.17,
0.90,0.76*03
$GPRMC
3iiAGPRMC2qp0G000,A,4031.2765GPGGA,223,12,07,19,294,33,21,14,055,19,01,11,238,
26,08,10,323,19*7B
$GPRMC
AccAGPRMC2qp0G000,A,4031.2765GPGGA,223,06,03,01,16,19,22,21,07,18,11,08,,1.17,
0.90,0.76*03
$GPRMC
AaaAGPRMC2qp0G000,A,4031.2765GPGGA,223,06,03,01,16,19,22,21,07,18,11,,,1.28,1.
03,0.77*0D
$GPRMC
2zzAGPRMC2qp0G000,A,4031.2765GPGGA,223,06,02221.000,4031.2737,N,00825.6803,W,2
,10,1.03,42.7,M,51.1,M,0000,0000*4C
|
some suggestions?
best regards
Last edited by filjoa on Tue May 21, 2013 4:23 pm; edited 1 time in total |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue May 21, 2013 4:17 pm |
|
|
Quote: | void read_protocol(void)
{
int i=0, result1 = 0, result2 = 0;
char str1[], str2[], prot[];
str1 = "$GPRMC";
str2 = "$GPGGA"; |
Why do you do this when you know it doesn't work ?
Make a test program. Look what the compiler does.
Code: | #include <18F4520.h>
#fuses INTRC_IO,NOWDT,BROWNOUT,PUT,NOLVP
#use delay(clock=4M)
//=========================
void main()
{
char str1[], str2[];
str1 = "$GPRMC";
str2 = "$GPGGA";
while(1);
} |
Here is the .LST file. You don't have arrays. You didn't declare the
size of the arrays. So the compiler just takes the first byte of each
string ( the '$' byte) and puts it into str1 and str2.
Code: | .................... void main()
.................... {
0004: CLRF TBLPTRU
0006: BCF RCON.IPEN
0008: CLRF FSR0H
000A: CLRF FSR0L
000C: MOVLW 60
000E: MOVWF OSCCON
0010: MOVF OSCCON,W
0012: MOVF ADCON1,W
0014: ANDLW C0
0016: IORLW 0F
0018: MOVWF ADCON1
001A: MOVLW 07
001C: MOVWF CMCON
.................... char str1[], str2[];
....................
.................... str1 = "$GPRMC";
001E: MOVLW 24 <== First character '$' is put into 'str'
0020: MOVWF str1
.................... str2 = "$GPGGA";
0022: MOVWF str2 <== Same thing here.
....................
.................... while(1);
0024: BRA 0024
.................... }
0026: SLEEP |
Look at the symbol table below. The compiler makes this file in your
project directory. Look for the .SYM file. Notice your "arrays" are not
arrays. They only have 1 byte of RAM allocated to them. They don't
hold your $GPRMC or $GPGGA strings.
Code: |
000 @SCRATCH
001 @SCRATCH
001 _RETURN_
002 @SCRATCH
003 @SCRATCH
005 main.str1 <== Only 1 byte of RAM allocated to 'str1'
006 main.str2 <== Same thing with 'str2'
007 main.@SCRATCH1
008 main.@SCRATCH2
009 main.@SCRATCH3
00A main.@SCRATCH4 |
You know this. You have been on the forum for years. |
|
|
filjoa
Joined: 04 May 2008 Posts: 260
|
|
Posted: Tue May 21, 2013 4:31 pm |
|
|
Hi, thanks...
with this example I print my string correct:
Code: |
void read_protocol(void)
{
int i=0, result1 = 0, result2 = 0;
char str1[7], str2[7], prot[7];
str1 = "$GPRMC";
str2 = "$GPGGA";
while(c!='$');
do {
while (data_available==FALSE);
data_available = FALSE;
prot[i]=c;
i++;
}while (c!=',');
result1 = strncmp (str1, prot, 5);
result2 = strncmp (str2, prot, 5);
if (result1 == 0) readgps1(); //apresenta o protocolo escolhido
if (result2 == 0) readgps2();
if (result1 != 0 || result2 !=0) break; //retorna ao main
}
//## LER DO GPS protocolo GPRMC ##
void readgps1(void)
{
char auxstr[150];
int8 i = 0, speed = 0;
do {
while (data_available==FALSE);
data_available = FALSE;
auxstr[i]=c;
i++;
}while (c!= '\r');
speed = i;
// ##### TRATAMENTO DOS DADOS #####
fprintf(outport,"$GPRMC\n\r");
for (i=0;i<speed;i++)
{
fprintf(outport,"%c",auxstr[i]);
}
fprintf(outport,"\n\r");
}
//## LER DO GPS protocolo GPGGA ##
void readgps2(void)
{
char auxstr[150];
int8 i = 0, speed = 0;
do {
while (data_available==FALSE);
data_available = FALSE;
auxstr[i]=c;
i++;
}while (c!='\r');
// ##### TRATAMENTO DOS DADOS #####
speed = i;
fprintf(outport,"$GPGGA\n\r");
for (i=0;i<speed;i++)
{
fprintf(outport,"%c",auxstr[i]);
}
fprintf(outport,"\n\r");
}
|
|
|
|
filjoa
Joined: 04 May 2008 Posts: 260
|
|
Posted: Tue May 21, 2013 6:07 pm |
|
|
Hi
I'll try separate different information of my string
each information have an ','
Code: |
//## LER DO GPS protocolo GPRMC ##
void readgps1(void)
{
char auxstr[150] ;
int8 i = 0, aux;
int8 horas = 0;
do {
while (data_available==FALSE);
data_available = FALSE;
auxstr[i]=c;
i++;
}while (c!= '\r');
// ##### TRATAMENTO DOS DADOS #####
fprintf(outport,"Horas: %s",auxstr);
fprintf(outport,"\n\r");
}
|
result on terminal:
Quote: |
Horas: 010456.000,A,4031.2722,N,00825.6777,W,0.07,62.36,220513,,,A*47
|
some times appear:
1º character stay wrong.
Quote: |
0oras: 001332.000,A,4031.2710,N,00825.6773,W,0.61,65.02,220513,,,A*46
3oras: 001333.000,A,4031.2710,N,00825.6771,W,0.65,67.77,220513,,,A*41
Doras: 001334.000,A,4031.2709,N,00825.6770,W,0.64,72.83,220513,,,A*41
Eoras: 001335.000,A,4031.2709,N,00825.6772,W,0.42,72.83,220513,,,A*46
Doras: 001336.000,A,4031.2709,N,00825.6772,W,0.41,72.83,220513,,,A*46
Doras: 001337.000,A,4031.2709,N,00825.6772,W,0.39,72.83,220513,,,A*48
8oras: 001338.000,A,4031.2710,N,00825.6773,W,0.37,72.83,220513,,,A*40
9oras: 001339.000,A,4031.2711,N,00825.6772,W,0.34,72.83,220513,,,A*42
7oras: 001340.000,A,4031.2711,N,00825.6772,W,0.44,72.83,220513,,,A*4B
7oras: 001341.000,A,4031.2712,N,00825.6770,W,0.50,72.83,220513,,,A*4E
Doras: 001342.000,A,4031.2713,N,00825.6769,W,0.52,72.83,220513,,,A*46
|
some one can have an ideia how I can separate information, Hours, coordinates, speed?
best regards |
|
|
filjoa
Joined: 04 May 2008 Posts: 260
|
|
Posted: Tue May 21, 2013 6:27 pm |
|
|
if I put this
Quote: |
void read_protocol(void)
{
int i=0, result1 = 0, result2 = 0;
char str1[7], str2[7], prot[10];
|
result:
1º character stay wrong...
Quote: |
31414 002357.000,A,4031.2684,N,00825.6829,W,0.15,227.43,220513,,,A*78
31414 002358.000,A,4031.2685,N,00825.6827,W,0.12,227.43,220513,,,A*7F
31414 002359.000,A,4031.2686,N,00825.6827,W,0.17,227.43,220513,,,A*78
31414 002400.000,A,4031.2685,N,00825.6828,W,0.49,227.43,220513,,,A*74
|
if I put:
Quote: |
void read_protocol(void)
{
int i=0, result1 = 0, result2 = 0;
char str1[7], str2[7], prot[7];
|
result:
is the same like previous post.
this array make me confuse.... but ok.. with "for" cicle I write string correct on terminal...
principal question is: How I can find "," on my array? |
|
|
filjoa
Joined: 04 May 2008 Posts: 260
|
|
Posted: Wed May 22, 2013 1:31 am |
|
|
Hi
now I have this code to try find and separate my string:
Code: |
//## LER DO GPS protocolo GPRMC ##
void readgps1(void)
{
char auxstr[150], horas [10], val[5] ,lat[15];
char coord[5];
int8 i = 0, aux = 0;
do {
while (data_available==FALSE);
data_available = FALSE;
auxstr[i]=c;
i++;
}while (c!= '\r');
////////////// A funcionar
aux = i;
fprintf(outport,"String: ");
for (i=0;i<aux;i++)
{
fprintf(outport,"%c",auxstr[i]);
}
fprintf(outport,"\n\r");
// HORAS
i=0;
do {
horas[i]=auxstr[i];
i++;
} while (auxstr[i]!=',');
aux = i;
fprintf(outport,"Horas: ");
for (i=0;i<aux;i++)
{
fprintf(outport,"%c",horas[i]);
}
//Validade
i=0;
do {
val[i]=auxstr[i+aux];
i++;
} while (auxstr[i+aux]!=',');
aux = i;
fprintf(outport," - Validade: ");
for (i=1;i<aux;i++)
{
fprintf(outport,"%c",val[i]);
}
//LATITUDE
i=0;
do {
lat[i]=auxstr[i+aux];
i++;
} while (auxstr[i+aux]!=',');
aux = i;
fprintf(outport," - Latitude: ");
for (i=0;i<aux;i++)
{
fprintf(outport,"%c",lat[i]);
}
//LAT COORDENATES
i=0;
do {
coord[i]=auxstr[i+aux];
i++;
} while (auxstr[i+aux]!=',');
aux = i;
fprintf(outport," - : ");
for (i=0;i<aux;i++)
{
fprintf(outport,"%c",coord[i]);
}
|
But I think it don't stay correct... my idea is put each part on a string variable, not on array..
is possible?
how I can put this program more efficiently?
best regards |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Wed May 22, 2013 2:22 am |
|
|
Get on thing clear. 'C' does not have an inherent 'string' type. In 'C', a 'string', _is_ an array of characters, _with a terminating null_. This is the basic 'what a string is' in C. Nothing else.
Second thing. You still have the basic "I'm going to lose as much incoming data as possible" approach. The UART has just two characters of buffering in each direction. No more. Now you stop receiving, and go off sending stuff to outport, and parsing the received data, and while this is happening, more data will be arriving, and being lost. Look at ex_sisr.c, for how the receive interrupt should be handled. Then instead of testing 'data_available', use while(!bkbhit()), and instead of just loading the character 'c', use bgetc.
Now, you are using the title 'auxstr' for your character array, and call it a string when you print it, but then don't null terminate it, so it is not a 'string'. If it was a string, you could save yourself line upon line of code, by first simply printing it with fprintf as a string, rather than doing this character by character, then finding the ',' using strstr, etc..
Get a basic C textbook, and read.
Then there is the ongoing problem of sizes. You try to pull the latitude out of the array into 'val[]', and allow five characters for this. The standard for GPRMC, is the coordinates are "xxxxxx.xx". Three digits for the degrees, then two digits more for the decimal minutes, then the decimal point, then two to four digits for the fractional minutes. A total of eleven characters (and to work with this as a string, you would then need a twelth character to store the null). You at this point will have overwritten the next variable in memory.... Look at how many characters there are between the commas in your examples.... |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Wed May 22, 2013 7:43 am |
|
|
filjoa wrote: | Hi
if I try find '\0' program don't work... I need find '\r'
|
Hi,
You completely misunderstood my comment about '\0'..... I never said to search for this character, I said to use it to 'Null Terminate' your character array to make the array a 'C' string. Again, in 'C' a string is nothing more than an array of characters that has '\0' as the final character. So, instead of printing your character array, character by character, you can do this instead:
Code: |
auxstr[i++] = '\0'; //Null terminate the character array
fprintf(outport,"%s\n\r",auxstr);
|
As others have pointed out, you really need to receive the GPS data using an interrupt-driven circular buffer. Start with the CCS example program 'ex_sisr.c', and build on it from there. Inside your serial interrupt routine (int rda), you can 'filter' the incoming data using a 'state machine' to only allow the desired NMEA data strings into your receive buffer. Then, inside your Main routine, you can extract the individual NMEA strings and parse them. Separating the NMEA strings into their individual parameters, because of the comma delimiters, and the fact that each parameter appears at a known position each time.
John |
|
|
filjoa
Joined: 04 May 2008 Posts: 260
|
|
Posted: Tue May 28, 2013 5:57 am |
|
|
Hi
thanks... for this explanation, now I understand.
I'll make this modification on my code and try it...
best regards |
|
|
filjoa
Joined: 04 May 2008 Posts: 260
|
|
Posted: Wed Jun 26, 2013 3:07 pm |
|
|
Hi
I have some problem with interrupts, I think...
This program read some GPS parameters and a temperature.
If I uncomment "readtemp();" in main function, program printing stupid string on terminal.
Code: |
#include <18F458.h>
#device adc=10 //adc com 10bits
#fuses HS,NOWDT,NOPROTECT,NOLVP,BROWNOUT,STVREN
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8, stream=gpsport, Errors)
#use rs232(baud=9600,parity=N,xmit=PIN_C4,rcv=PIN_C5,bits=8, stream=outport, Errors)
#include<string.h>
#include<stdlib.h>
//## Variaveis Globais ##
int1 data_available=FALSE;
char c;
char time[20], lat[20], PNS[10], longi[20], PEW[10], speed[20], alt[20];
int16 temperatura;
//## Declaração de funções ##
void rda_isr();
void read_protocol(void);
void readgps1(void);
void readgps2(void);
void readtemp(void);
#int_rda
void rda_isr(void)
{
c = getc(gpsport);
data_available=TRUE;
}
//## escolha e identificação do protocolo GPRMC ##
void read_protocol(void)
{
int i=0, result1 = 0, result2 = 0;
char str1[7], str2[7], prot[9];
strcpy (str1, "$GPRMC");
strcpy (str2, "$GPGGA");
while(c!='$');
do {
while (data_available==FALSE);
data_available = FALSE;
prot[i]=c;
i++;
}while (c!=',');
result1 = strncmp (str1, prot, 5);
result2 = strncmp (str2, prot, 5);
if (result1 == 0) readgps1(); //apresenta o protocolo escolhido
if (result2 == 0) readgps2();
if (result1 != 0 || result2 !=0) break; //retorna ao main
}
//## LER DO GPS protocolo GPRMC ##
void readgps1(void)
{
char auxstr[150], auxtime [20];
int8 i = 0, x = 0, virg = 0, x2 =0, numspeed = 0;
do {
while (data_available==FALSE);
data_available = FALSE;
auxstr[i]=c;
i++;
}while (c!= '\r');
auxstr[i]='\0'; //para transformar o array numa string
////////////// A funcionar
//fprintf(outport," %s \n\r",auxstr);
// ##### TRATAMENTO DOS DADOS #####
for(i=0;i<20;i++){ time[i]=0;}
for(i=0;i<20;i++){ lat[i]=0;}
for(i=0;i<10;i++){ PNS[i]=0;}
for(i=0;i<20;i++){ longi[i]=0;}
for(i=0;i<10;i++){ PEW[i]=0;}
for(i=0;i<20;i++){ speed[i]=0;}
i=0;
x=0;
x2=0;
while(auxstr[i]!='\0') {
if(auxstr[i]==','){ virg++; x=0; i++; }
//HORAS
if (virg==0){ time[x]=auxstr[i]; x++; x2=x; }
if (virg==1){ time[x2]='\0';}
//LATITUDE
if (virg==2){ lat[x]=auxstr[i]; x++; x2=x; }
if (virg==3){ lat[x2]='\0';}
//POSIÇÃO N/S
if (virg==3){ PNS[x]=auxstr[i]; x++; x2=x; }
if (virg==4){ PNS[x2]='\0';}
//LONGITUDE
if (virg==4){ longi[x]=auxstr[i]; x++; x2=x; }
if (virg==5){ longi[x2]='\0';}
//POSIÇÃO E/W
if (virg==5){ PEW[x]=auxstr[i]; x++; x2=x; }
if (virg==6){ PEW[x2]='\0';}
//VELOCIDADE km/h
if (virg==6){ speed[x]=auxstr[i]; x++; x2=x; }
if (virg==7){ speed[x2]='\0';
numspeed = 1.852*atof(speed); //converter velocidade de nós para kilometros
itoa(numspeed,10,speed);
}
i++;
}
//#### FORMATO HORARIO hh:mm:ss ####
i=0;
x=0;
for(i=0;i<20;i++){ auxtime[i]=0;}
for (i=0;i<=10;i++)
{
if (time[x] == '.') { auxtime[i]='\0'; i=10;}
auxtime[i]=time[x];
if (i == 2) { auxtime[i]=':'; x--;}
if (i == 5) { auxtime[i]=':'; x--;}
x++;
}
strcpy(time, auxtime);
}
//## LER DO GPS protocolo GPGGA ##
void readgps2(void)
{
char auxstr[150];
int8 i = 0, x = 0, x2 = 0, virg = 0;
do {
while (data_available==FALSE);
data_available = FALSE;
auxstr[i]=c;
i++;
}while (c!='\r');
auxstr[i]='\0'; //para transformar o array numa string
////////////// A funcionar
//fprintf(outport," %s \n\r",auxstr);
// ##### TRATAMENTO DOS DADOS #####
for(i=0;i<20;i++) { alt[i]=0;}
i=0;
while(auxstr[i]!='\0') {
if(auxstr[i]==','){ virg++; x=0; i++; }
//ALTURA A PARTIR DO MAR EM (m)
if (virg==8){ alt[x]=auxstr[i]; x++; x2=x; }
if (virg==9){ alt[x2]='\0';}
i++;
}
}
void readtemp(void)
{
int16 aux1 =0 , value1 = 0, aux2 =0 , value2 = 0, i = 0;
int16 lm35 = 0, termop = 0;
// ## TEMP LM35
for (i=0;i<30;i++)
{
set_adc_channel(0); //Porta a ler da ADC RA0
delay_ms(10);
aux1=read_adc(); //ler valor da ADC
value1=value1+aux1;
}
value1 = value1 / i;
lm35 = 0.64+0.26*value1; //y=0.64+0.26*x
// ## TEMP Termopar
aux2=0;
for (i=0;i<30;i++)
{
set_adc_channel(1); //Porta a ler da ADC RA1
delay_ms(10);
aux2=read_adc(); //ler valor da ADC
value2=value2+aux2;
}
value2 = value2 / i;
termop = 8.83+0.19*value2+0.0002*(value2*value2);//y=8.83+0.19*x+0.0002*x^2
//### RESULTADO DA TEMPERATURA ###
temperatura = lm35 + termop;
}
void main(void)
{
//## Configurações ##
enable_interrupts(GLOBAL); //activar interrupts
enable_interrupts(INT_RDA); //activar interrupts porta serie
setup_adc_ports(AN0_AN1_AN3); //escolher portas ADC
setup_adc(ADC_CLOCK_INTERNAL); //activar o modo da ADC
while(TRUE)
{
read_protocol();
//readtemp();
//########### OUT STRING #############
fprintf(outport,"* %s # %s # %s # %s # %s # %s # %s # %lu\n\r",time, PNS, lat, PEW, longi, speed, alt, temperatura);
}
}
|
I need stop interrupts somewhere?
I can't put ADC and INTERRUPTS work at same time
Someone can help me where stay error? |
|
|
filjoa
Joined: 04 May 2008 Posts: 260
|
|
Posted: Wed Jun 26, 2013 6:35 pm |
|
|
Hi
problem SOLVED, I need stop and start interrupts....
so, now I need compare my received string with checksum.
some one know how I can make it?
best regards |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Wed Jun 26, 2013 11:40 pm |
|
|
Quote: | problem SOLVED, I need stop and start interrupts... |
Surprizing conclusion. I don't believe that it solves a substantial problem.
Do you know what #int_rda is made for? As used in your code, polling getc() in the readgps functions would
give exactly the same result: Multiple characters received while not waiting in readgps will overflow the
UART and get lost.
To use #int_rda in a reasonable way, you need to implement a receive buffer. Fortunately CCS provides
an example EX_SISR.C that shows how.
Many comments could be added about effective string processing, e.g. parsing for tokens, copying,
decoding numerical values. But as long as your code serves it's purpose, I'll stay with the maxim
of the Prussian king Frederik the Great "Let every man seek heaven in his own fashion".
Best regards,
Frank |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|