[SOLVED] Problem with read the serial from STM32L053R8

borombo96
Tue Aug 21, 2018 3:14 pm
Hi,
I’m working on an application that uses a sim7000 breakout board and STM32L053R8 (with the I-Nucleo-LRWAN1 expansion board).
Now I have to read data from the gps with sim7000 in the serial of STM32L0.
When the chip is connecting to the satellite I read this in the serial:

AT+CGNSINF

+CGNSINF: 0,,,,,,,,,,,,,,,,,,,,

OK

comand send
AT+CGNSINF

+CGNSINF: 1,0,,,,,,,0,,,,,,1,,,,49,,

OK

comand send

ant it’s ok.. but when it connects to satellite I read on the serial this:

comand send
AT+CGNSINF

+CGNSINF: 1,1,20180821145743.000,38.121140,15.666
comand send
AT+CGNSINF

+CGNSINF: 1,1,20180821145745.000,38.121241,15.665
comand send
AT+CGNSINF

+CGNSINF: 1,1,20180821145747.000,38.121229,15.665

I don’t understand why the data after +CGNSINF are not complete, in fact it should be something like:

AT+CGNSINF
+CGNSINF: 1,1,20180821151003.000,38.121095,15.666267,80.200,0.00,0.0,1,,0.7,1.0,0.7,,18,10,,,46,,

The code that I’m using is this:
HardwareSerial SerialForSim7000(PA_10, PA_9);

HardwareSerial SerialLora(PC_11, PC_10);
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
SerialForSim7000.begin(9600);
SerialForSim7000.write("AT+CGNSCFG=1 \r\n");
delay(500);
SerialForSim7000.write("AT+CGNSPWR=1 \r\n");
delay(500);

}

void loop() // run over and over
{
SerialForSim7000.write("AT+CGNSINF \r\n");
while(SerialForSim7000.available())
Serial.write(SerialForSim7000.read());
Serial.println();
Serial.write("comand send");
Serial.println();
delay(2000);

}


edogaldo
Tue Aug 21, 2018 3:39 pm
try checking the SerialForSim7000 read buffer size.

borombo96
Tue Aug 21, 2018 6:46 pm
[edogaldo – Tue Aug 21, 2018 3:39 pm] –
try checking the SerialForSim7000 read buffer size.

how can i check this?

Can I fix it with a lower baud rate?

Ty


borombo96
Thu Aug 23, 2018 11:25 am
Someone can help me, how can I increase the buffer’s size? I read that modifing the library is not a good thing to do..
Ty 4 help ��

borombo96
Tue Aug 28, 2018 8:29 am
Someone can help me? :(

madias
Tue Aug 28, 2018 11:31 am
You can try to catch up the output of SerialForSim7000.read(); into an array and after finishing just print the array with Serial.print

madias
Tue Aug 28, 2018 11:35 am
I do not own the board or LRWAN, but after some googleing:
You can try to raise the buffer here:
https://github.com/stm32duino/I-NUCLEO- … hw_usart.h
Line 53: #define SERIAL_RX_BUFFER_SIZE 256
I would try 512 or something.
If it works, please open an issue on github.

borombo96
Fri Aug 31, 2018 8:29 am
[madias – Tue Aug 28, 2018 11:35 am] –
I do not own the board or LRWAN, but after some googleing:
You can try to raise the buffer here:
https://github.com/stm32duino/I-NUCLEO- … hw_usart.h
Line 53: #define SERIAL_RX_BUFFER_SIZE 256
I would try 512 or something.
If it works, please open an issue on github.

Ty for help madias!
I try this but it doesn’t work. This is the code
#include "LoRaRadio.h"
#include "lora_driver.h"

HardwareSerial SerialForSim7000(PA_10, PA_9);

HardwareSerial SerialLora(PC_11, PC_10);
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
SerialForSim7000.begin(9600);
SerialForSim7000.write("AT+CGNSCFG=1 \r\n");
delay(500);
SerialForSim7000.write("AT+CGNSPWR=1 \r\n");
delay(500);
}

void loop() // run over and over
{
SerialForSim7000.write("AT+CGNSINF \r\n");
while(SerialForSim7000.available())
Serial.write(SerialForSim7000.read());
Serial.println();
Serial.write("comand send");
Serial.println();
delay(2000);

}


fpiSTM
Mon Sep 03, 2018 8:54 am
Try to not call the SerialForSim7000.read in the Serial.write:
Serial.write(SerialForSim7000.read());

borombo96
Mon Sep 03, 2018 4:06 pm
I fixed it with a small delay, so the serial starts to print result after some bytes…
char risp[94];
String latval;
double lat;
String longval;
HardwareSerial SerialForSim7000(PA_10, PA_9);

HardwareSerial SerialLora(PC_11, PC_10);
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
SerialForSim7000.begin(9600);
SerialForSim7000.write("AT+CGNSCFG=1 \r\n");
delay(500);
SerialForSim7000.write("AT+CGNSPWR=1 \r\n");
delay(500);

}

void loop() // run over and over
{
SerialForSim7000.write("AT+CGNSINF \r\n");
delay(30);
while(SerialForSim7000.available()){
for(int n=0; n<94; n++)
{
risp[n] = SerialForSim7000.read(); //here I put the char into array
}
}
Serial.println();
Serial.write("comand send");
Serial.println();

for(int n=36;n<55;n++){
Serial.print(risp[n]); //I print the arry
}
Serial.println();
for(int n=36; n<45;n++)
latval += risp[n]; //I put the firs part ofarray into a String
Serial.println(latval);
float lat=latval.toFloat(); //convert a string into floa
Serial.println(lat);
latval=""; //clen string
delay(2000);
}


fpiSTM
Tue Sep 04, 2018 10:16 am
I’ve made a PR to add toDouble to the core:
https://github.com/stm32duino/Arduino_C … 2/pull/313

I’ve tested with this sketch based on yours:

void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);

for (uint32_t n = 0; n < sizeof(risp); n++) {
Serial.print(risp[n]); //I print the array
}
Serial.println();

for (uint32_t n = 0; n < 9; n++)
latval += risp[n]; //I put the firs part ofarray into a String
Serial.println(latval);

float flat = latval.toFloat(); //convert a string into float
Serial.println(flat);

lat = latval.toDouble(); //convert a string into double
Serial.println(lat, 6);
}

void loop() // run over and over
{
}


borombo96
Tue Sep 04, 2018 2:08 pm
I did the modify in the library but I have this error:

‘class String’ has no member named ‘toDouble’

this is the code in file WString.cpp: (line 741-750)

float String::toFloat(void) const
{
return float(toDouble());
}

double String::toDouble(void) const
{
if (buffer) return atof(buffer);
return 0;
}


fpiSTM
Tue Sep 04, 2018 2:28 pm
[borombo96 – Tue Sep 04, 2018 2:08 pm] –
This is the root of the file WString.h and WString.cpp C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino

This is not the right core, this is the avr core not the STM32.

You can find the source using this:
https://github.com/stm32duino/wiki/wiki … re-sources


borombo96
Sat Sep 08, 2018 12:03 pm
Ty it’s work ��

All Comments

Leave a Reply

Your email address will not be published. Required fields are marked *