sparkfun / SparkFun_u-blox_GNSS_Arduino_Library

An Arduino library which allows you to communicate seamlessly with the full range of u-blox GNSS modules
Other
227 stars 100 forks source link

checkUblox function can't be run in a loop slower than 10 ms delay #198

Closed YannickRiou closed 1 year ago

YannickRiou commented 1 year ago

Subject of the issue

I use the library to communicate with a ZED-F9P GNSS module. My goal is to log raw gnss data (RAWX) and store them into flash. I found that when I try to obtain RAWX data using the function checkUblox in the main loop, it only works if the delay is 10 ms. I can't manage to get any data from gnss when the delay is above (50 ms or 100 ms). The library is used on ESP32S2 using Arduino framework (2.0.6).

Steps to reproduce

Use the following to configure the GNSS :

    gnssSerial.begin(19200, SWSERIAL_8N1, SOFT_SER_GNSS_RX, SOFT_SER_GNSS_TX, false);

    gnss.disableUBX7Fcheck();                 
    gnss.setFileBufferSize(gnssLogDataRamSize); // setFileBufferSize must be called _before_ .begin
    delay(100);
    gnss.setUART1Output(COM_TYPE_UBX); // Set the UART port to output UBX only

    // Lowest frequency possible
    gnss.setVal16(UBLOX_CFG_RATE_MEAS, 0x3E8, VAL_LAYER_ALL);

    // Set time to be UTC
    gnss.setVal16(UBLOX_CFG_RATE_TIMEREF, 0x00, VAL_LAYER_ALL);

    // Disable beidou
    gnss.setVal16(UBLOX_CFG_SIGNAL_BDS_ENA, 0);

    // Disable sbas
    gnss.setVal16(UBLOX_CFG_SIGNAL_SBAS_ENA, 0);

    gnss.setAutoRXMRAWX(true, false); // Enable automatic RXM RAWX messages: without callback; without implicit update
    gnss.logRXMRAWX();                // Enable RXM RAWX data logging
    gnss.saveConfiguration();         // Save the current settings to flash and BBR

And the data gathering is done into the main "void loop" by calling checkUblox with a "delay(10)"

Expected behavior

I should be able to se the delay in the main loop at different value and still get the ubx buffer to fill with data.

Actual behavior

If I put a delay of 10ms , everything is fine and the buffer fills ok, but if I put 50ms or 100ms, no data is getting into the buffer. even after few seconds.

PaulZC commented 1 year ago

Hi @YannickRiou ,

I think the root cause of this is the default size of the ESP32S2's Serial RX buffer - possibly 256 bytes?

The RXM-RAWX message can be over 2kBytes in size when tracking multiple satellites on dual bands. I suspect that is overflowing the receive buffer, if you do not call checkUblox often enough.

If you call checkUblox often, it will 'catch' the arrival of the start of the RXM-RAWX message and will keep receiving and processing the data.

But if you make your delay too long, the RX buffer will overflow and data will be lost before you next call checkUblox. This causes a checksum error and the data is discarded.

Please try adding gnssSerial.setRxBufferSize(4096); before gnssSerial.begin(19200, SWSERIAL_8N1, SOFT_SER_GNSS_RX, SOFT_SER_GNSS_TX, false); . It may solve this issue.

Please also use hardware serial if possible. SoftwareSerial is always problematic.

I am going to close this, but please reopen it if you need more help or advice.

Best wishes, Paul