Hi. I have such a question, I use eeprom libraries. And I have a problem with saving coordinates downloaded from TinyGPSPlus.
I do it like this gives a pwm signal of 1750 and wants to save the coordinates. Writing to the eprom takes place, but it usually takes about 10 seconds. The question is whether such a record of coordinates can be accelerated or must it remain so?
I think It's not that the writing to EEPROM takes 10 seconds. The reason is different - your GPS receiver only outputs correct data once every 10 seconds
Unfortunately, that's not it. I set the value fetch with nothing gps.location.lat() and gps.location.lon(). And then the same thing takes about 10 seconds to write to eeprom.
I connected an lcd display and the values on it change 10 times per second as I move the GPS lon, lat. And this write to eeprom is a massacre for me.
Save the value of millis()
put() a value in the EEPROM
Save the value of millis() again
Print the difference between the 2 save values
DO NOT DO THIS IN loop() The EEPROM has a limited guaranteed number of write operations and you may have already exceeded that due to the operation of your current sketch
performs the write only once... in the loop, !executed is responsible for that.
As for millis(), it saves immediately, identically, it saves a structure of 10 different byte variables quickly. And if it only gives float() or double() write it stretches to 10 seconds. I changed to other stm32f401, stm32f411 processors, the problem is still the same.
In my UNO setup, the sketch of post #5 reports "writing time" as 22 ms which means that writing delay for each location is about 2.75 ms (22/8) and it makes sense when the maximum writing delay for a location is 5 ms.
11ms it means that something else is delaying my save...I will look for the reason in the code. Maybe the ibusbm library delays writing, I'll test and check.
Thank you in advance for your help, at least now I know that the record is practically immediately stored in memory, even if it has 8 decimal places.
The reason why writing to EEPROM takes around 10 seconds is because EEPROM write operations are relatively slow, and your current code is writing a floating-point value to EEPROM. Floating-point values typically require more bytes to store than integers or booleans, which further slows down the write operation.
To speed up the EEPROM write operation, you can consider the following approaches:
Store the GPS coordinates as integers instead of floating-point values. This can significantly reduce the number of bytes required to store each coordinate, which can speed up the write operation.
Instead of writing to EEPROM every time the threshold is met, you can buffer the GPS coordinates in an array or a circular buffer, and write the entire buffer to EEPROM periodically. This can reduce the number of EEPROM write operations required, which can improve performance.
Use an external EEPROM chip with faster write speeds. This can provide faster write operations compared to the built-in EEPROM in the STM32F103.
In addition to the above approaches, you can also consider optimizing your code to reduce the time spent in other parts of your program. For example, you can try to reduce the amount of data transmitted over the serial port, or optimize your GPS parsing code to reduce the time spent parsing GPS data.
I hope these suggestions help you improve the performance of your code.
A float type variable (no matter how many digits are there after the decimal point) is always encoded into 4-byte (32-bit) as per IEEE-754 standard (Fig-1).
Figure-1: