Hi Paul,
I have been doing alot of testing this weekend trying to figure the SPI comms out.
Below is the best version of what I could come up with.
Nav rates, UBX config and SPI messages have been configured using ucentre.
I have turned the 0xff time out feature off as this seemed to help quite a bit.
It would be great if you could run this code on your ZED F9P and see what you get.
It seems to work ok but, there are things that make me realise I dont understand how the SPI comms on this thing work.
For example, Changing the GPS_Interval from 100 to 105ms messes the whole thing up and read times become unstable and very long. The same thing happens if I change the navigation rate from say 10 to 11hz. wouold have thought that a slight decrease in polling rate (increasing GPS_Interval) would have the opposite effect than what it does.
Another thing is how long the SPI comms take to begin and how long they take to become stable. Often it takes over 100 read cycles before things calm down. Read time will initially stabilize to say 40 ms then they will go down to 10ms. Almost like the bus is taking a while to “sync”. I need to work out how to sync from the get go.
It appears to me that I have to implement some kind of buffer check to ensure new data is ready to read. I cant work out how to do this.
Any thoughts?
/* ZED F9P SPI testing
UBX-CFG(config)-RATE(Rates)
Period = 100ms
Freq = 10 Hz
Rate = 1 cyc
Nav Freq = 10Hz
UBX-CFG(config)-PRT(Ports)
4 -SPI
0_UBX
0_UBX
Max )xFF cnt = 0 (feature off)
0-CPOL=0
CHPA =0
UBX-CFG(config)-MSG(Messages)
Message = 01-07 NAV-PVT
SPI on
*/
#include <SPI.h>
#include <SparkFun_u-blox_GNSS_Arduino_Library.h> //http://librarymanager/All#SparkFun_u-blox_GNSS
SFE_UBLOX_GNSS myGNSS;
#define spiPort SPI
#define GNSS_CS 10
//-----------variables GPS Stuff----------------------//
double doublelatitude = 0.0, doublelongitude = 0.0;
long spEed = 0.0, laTitude = 0.0, loNgitude = 0.0, heading = 0.0, GPS_Heading =0.0;
float KPH = 0.0, RTK = 0.0;
unsigned long GPSlastTime =0,GPS_Interval= 100, looptime, looptimelast,Readtime,Max;
int Rate;
long counter =0, TX_Counter =0;
void setup() {
Serial.begin(115200);
while (!Serial); //Wait for user to open terminal
Serial.println(F("SparkFun u-blox Example"));
spiPort.begin();
delay(50);
// Do a fake transaction to initialize the SPI pins
spiPort.beginTransaction(SPISettings(4000000, MSBFIRST, SPI_MODE0));
spiPort.transfer(0xff);
spiPort.endTransaction();
delay(50);
myGNSS.begin(spiPort, GNSS_CS, 4000000,20);
delay(50);
}
//-------------------------------LOOP------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
void loop() {
looptime = millis() - looptimelast;
looptimelast = millis();
//------------GPS Read Values-------------------
if ((millis() - GPSlastTime) >= GPS_Interval) {// read GPS at given interval.
GPSlastTime = millis(); //Update the timer
TX_Counter++;
LatLong();
Heading();
Speed();
GPS_Solution_Type();
if(TX_Counter >100){//let SPI comms stabalize before recording Max read GPS read time
Readtime = millis() - GPSlastTime;
if(Readtime > Max)
Max = Readtime; //keep updating the max read time
else
Max = Max;
}
counter ++;
Serial.print("latitude- ");
Serial.print(laTitude);
Serial.print(" ");
Serial.print("longitude- ");
Serial.print(loNgitude);
Serial.print(" ");
Serial.print("Rate- ");
Serial.print("Max- ");
Serial.print(Max);
Serial.print(" ");
Serial.print("ReadTime- ");
Serial.print(Readtime);
Serial.print(" ");
Serial.print("cnt- ");
Serial.print(counter);
Serial.println(" ");
}
}
//------ Latitude and Longitude-----------------------------------------------------------------
void LatLong() {
laTitude = myGNSS.getLatitude();
doublelatitude = laTitude / 10000000.0L; //have to declare the variable as a double and put an L after the constant. This makes compiler treat both as double precision (65 bit) floats.
loNgitude = myGNSS.getLongitude(10);
doublelongitude = loNgitude / 10000000.0L; //have to declare the variable as a double and put an L after the constant. This makes compiler treat both as double precision (65 bit) floats.
}
//------ GPS Navigation Rate-----------------------------------------------------------------
void Nav_Rate() {
Rate = myGNSS.getNavigationFrequency();
}
//------ GPS carrier solution type-----------------------------------------------------------------
void GPS_Solution_Type() {
RTK = myGNSS.getCarrierSolutionType();
}
//------ Get the ground speed-----------------------------------------------------------------
void Speed() {
spEed = myGNSS.getGroundSpeed();
KPH = spEed / 277.777; //convert mm/s to KPH
}
//------ GPS Heading-----------------------------------------------------------------
void Heading() {
GPS_Heading = myGNSS.getHeading();
}