Hey everyone. I'm working with a GPS module u-blox 6 neo6, M10382 connected via SPI to an Arduino-like board. To be exact it's a somewhat customized board with a pic32, but the coding and everything is very similar to arduino.
I'm having trouble getting the GPS to spit out anything intelligible.
I have the four SPI lines hooked to GPIO pins. (I've also used a very similar approach using a gyroscope, and I was able to read the data off of it through SPI just fine using similar methods)
My code is as follows (and is explained afterward):
#include <Wire.h>
#include <plib.h>
#include <Math.h>
#include <p32xxxx.h>
#define RB05_GPSmosi 21
#define RB04_GPScs 15
#define RB03_GPSsclk 20
#define RB02_GPSmiso 14
// data buffer
uint8_t buf[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
char gpsbuf[80];
void setup() {
Serial.begin(9600);
// setup GPS
pinMode( RB05_GPSmosi, OUTPUT );
pinMode( RB02_GPSmiso, INPUT );
pinMode( RB03_GPSsclk, OUTPUT );
pinMode( RB04_GPScs , OUTPUT );
digitalWrite( RB04_GPScs, 1 );
digitalWrite( RB03_GPSsclk, 0 );
}
void loop() {
gpsRead();
Serial.println();
delay(50);
}
void gpsRead() {
gpsbuf[0] = 0;
//Select GPS
digitalWrite(RB04_GPScs, LOW);
//Write 0xFF while reading the MISO line and store each char in gpsbuf
int i = 0, j =0;
for(j = 0; j < 80; j++) {
for(i = 0; i < 8; i++) {
digitalWrite(RB05_GPSmosi, ((0xFF >> (7-i)) & 0x01));
digitalWrite(RB03_GPSsclk, 1);
delay(1);
gpsbuf[j] |= digitalRead(RB02_GPSmiso) << (7-i);
digitalWrite(RB03_GPSsclk, 0);
}
//Clean gpsbuf while reading
if(j != 79)
gpsbuf[j+1] = 0;
Serial.print(gpsbuf[j], HEX);
}
//Deselect GPS
digitalWrite(RB04_GPScs, HIGH);
}
So basically, I select the GPS by setting the cs low, I then go through sending 0xFF while reading the incoming bits and storing them in a buffer. The datasheet says that if you have nothing to send, then send 0xFF and after 50 sends of 0xFF it will stop parsing the incoming data. The data that I read and print out to the Serial port however just ends up being 0xFF as well. I've been looking through several data sheets and can't really find much about how to access the data on the GPS.
I'm used to just grabbing data from registers, but it seems here that the data should come back to me in a string format, and I should be able to parse that and get the data I need, but I just keep getting all 1's back (0xFF).
The data sheet I'm looking at states:
4.4 SPI Port
A Serial Peripheral Interface (SPI) bus is available with selected receivers. See our online product selector matrix
for availability.
SPI is a four-wire synchronous communication interface. In contrast to UART, the master provides the clock
signal, which therefore doesn't need to be specified for the slave in advance. Moreover, a baud rate setting is
not applicable for the slave. SPI modes 0-3 are implemented and can be configured using the field mode.
spiMode in CFG-PRT for SPI (default is SPI mode 0).
The SPI clock speed is limited depending on hardware and firmware versions!Maximum SPI clock speed
Generation Firmware Max SPI speed
u-blox 6 7 200 kHz
u-blox 6 6.02 100 kHz
u-blox 5 all 25 kHz4.4.1 Read Access
As the register mode is not implemented for the SPI port, only the UBX/NMEA message stream is provided. This
stream is accessed using the Back-To-Back Read and Write Access (see section Back-To-Back Read and Write
Access). When no data is available to be written to the receiver, MOSI should be held logic high, i.e. all bytes
written to the receiver are set to 0xFF.
To prevent the receiver from being busy parsing incoming data, the parsing process is stopped after 50
subsequent bytes containing 0xFF. The parsing process is re-enabled with the first byte not equal to 0xFF. The
number of bytes to wait for deactivation (50 by default) can be adjusted using the field mode.ffCnt in
CFG-PRT for SPI, which is only necessary when messages shall be sent containing a large number of subsequent
0xFF bytes.
If the receiver has no more data to send, it sets MISO to logic high, i.e. all bytes transmitted decode to 0xFF. An
efficient parser in the host will ignore all 0xFF bytes which are not part of a message and will resume data
processing as soon as the first byte not equal to 0xFF is received.
GPS.G6-SW-10018-F Public Release Page 12 of 2104.4.2 Back-To-Back Read and Write Access
The receiver does not provide any write access except for writing UBX and NMEA messages to the receiver,
such as configuration or aiding data. For every byte written to the receiver, a byte will simultaneous be read
from the receiver. While the master writes to MOSI, at the same time it needs to read from MISO, as any
pending data will be output by the receiver with this access. The data on MISO represents the results from a
current address read, returning 0xFF when no more data is available.
SPI Back-To-Back Read/Write Access
So I don't really want to write anything to the GPS, I just want to read from it, which is why I send it a bunch of 0xFF's. But it seems like I need to set an enable bit somewhere or something so that it knows to send me back the string of data that I'm looking for (latitude, longitude, and stuff like that). I'm just having trouble figuring out how to go about getting that string. The parsing shouldn't be an issue once I get the string.
The datasheets I'm looking at are linked here:
http://www.u-blox.com/images/downloads/Product_Docs/u-blox6_ReceiverDescriptionProtocolSpec_(GPS.G6-SW-10018).pdf
http://www.u-blox.com/images/downloads/Product_Docs/NEO-6_DataSheet_(GPS.G6-HW-09005).pdf
http://www.u-blox.com/images/downloads/Product_Docs/NEO-6_ProductSummary_(GPS.G6-HW-09003).pdf