Since your ATmega328 is stand alone, with only the LCD for output, you were right to make a special sketch. After a closer look, I did find a bug in detectRTCtimeOnly. If you could try this:
#include <NMEAGPS.h> // Using Neo-GPS lib
#include <EEPROM.h>
#include <NeoSWSerial.h> //Serial com
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 12, 13, 7); // RS, EN, D4, D5, D6, D7
static const int RXPin = A5, TXPin = 6;
NeoSWSerial gpsSerial(RXPin, TXPin);
NMEAGPS gps;
gps_fix fix;
uint8_t gsvTracked;
// #define gpsPort Serial1 // you may be using a different serial port
int contr=0; // Correzione manuale al contrasto automatico (-10...+10)
void setup()
{
//Serial.begin( 9600 );
// Serial.println( F("status,date/time,speed") );
// gpsPort.begin( 9600 );
gpsSerial.begin(9600); //Starting GPS at a 9600 baud rate
lcd.begin(16,2);
pinMode(11, OUTPUT);// PWM out per contrasto automatico
if(EEPROM.read(0)==255) contr=70; else contr=EEPROM.read(13); // Carica il valore del contrasto
analogWrite(11,contr); // Applica il contrasto memorizzato
}
extern void detectRTCtimeOnly();
void loop()
{
if (gps.available( gpsSerial ))
{
fix = gps.read();
lcd.clear();
stampa(); // show *before* detectRTCOnly, on line 0
lcd.println(); // on line 1,
detectRTCtimeOnly();
stampa(); // ... show *after* detectRTCOnly
}
}
void stampa()
{
const char *stato;
if (fix.valid.status)
{
if (fix.status == gps_fix::STATUS_NONE)
stato="RTC ";
else if (fix.status == gps_fix::STATUS_TIME_ONLY)
stato="GPS ";
else if (fix.status >= gps_fix::STATUS_STD)
stato="3 ";
}
else
stato="- ";
lcd.print(stato);
if (fix.valid.date) lcd.print( 'd' );
if (fix.valid.time) lcd.print( 't' );
lcd.print( F("sat:") );
if (fix.valid.satellites) lcd.print( fix.satellites );
lcd.print( '/' );
lcd.print( gsvTracked );
// not needed for now
// lcd.print(F(" spd: "));
// if (fix.valid.speed)
// lcd.print( fix.speed_kph() );
}
void detectRTCtimeOnly()
{
if (fix.valid.status && (fix.status == gps_fix::STATUS_TIME_ONLY)) {
// The MTK3339 will never send this value,
// but this is how you might detect it on ublox GPS devices.
return;
}
bool satellites = fix.valid.satellites and (fix.satellites > 0);
bool haveTime = fix.valid.date or fix.valid.time;
bool tracking = fix.valid.status and (fix.status >= gps_fix::STATUS_STD);
// if (not tracking) {
gsvTracked = 0;
// Look for tracked satellites from the GSV sentences
for (uint8_t i=0; i < gps.sat_count; i++) {
if (gps.satellites[ i ].tracked) {
satellites = true;
gsvTracked++;
// break;
}
}
// }
if (haveTime and not tracking and satellites) {
// Force the fix status even though no NMEA sentences set it
fix.valid.status = true;
fix.status = gps_fix::STATUS_TIME_ONLY;
}
} // detectRTCtimeOnly
This will use the two lines of the display to show status, date/time valid, satellites and GSV satellites, both before calling detectRTCtimeOnly and after. I get output like this:
RTC dtsat:0/0 <-- no satellites in GGA, RMC or GSV. Correctly marked as RTC.
RTC dtsat:0/0 (date and time valid)
RTC dtsat:0/0
RTC dtsat:0/0
RTC dtsat:0/0 <-- satellites in GSV. Correctly marked as GPS.
GPS dtsat:0/4 Changed to TIME_ONLY
RTC dtsat:0/4
GPS dtsat:0/7
RTC dtsat:6/4 <-- satellites in all GGA, RMC or GSV. Correctly marked as GPS. (no location yet)
GPS dtsat:6/5 Changed to TIME_ONLY
RTC dtsat:6/5
GPS dtsat:6/6
RTC dtsat:7/6
GPS dtsat:7/5
3 dtsat:7/8 <--satellites in all GGA, RMC or GSV, plus location.
3 dtsat:7/8 Correctly marked as "3" (STATUS_STD)
Let's see what your displays.