0
votes

I'm working with a GPS module, ublox-6 neo6 and trying to pull data off of it from a pic32 microcontroller using SPI. I'm using GPIO pins to do this so the SPI library is off the table.

Apparently, all I need to do is send it 0xFF and read what comes back at the same time to get data. When I try bit-banging it myself, I send 0xFF, but all I receive from the GPS is 0xFF back.

I've also tried implementing the SoftSPI library because I was concerned that I was trying to send and receive information too quickly, but similarly, when I send 0xFF I still receive 0xFF back from the GPS.

Here's my bit-banging code:

#include <plib.h>  
#include <Math.h>
#include <p32xxxx.h> 

void setup() {
  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() {
  gpsHit();
}


void gpsHit() {
  char received = 0;

  digitalWrite(RB04_GPScs, LOW);

  int i = 0;
  for(i = 0; i < 8; i++) {
    digitalWrite(RB05_GPSmosi, ((0xFF >> (7-i)) & 0x01));
    digitalWrite(RB03_GPSsclk, 1);
    received |= digitalRead(RB02_GPSmiso) << (7-i);
    digitalWrite(RB03_GPSsclk, 0);
  }

  if((received & 0xFF) != 0xFF)
    Serial.println(received);

  digitalWrite(RB04_GPScs, HIGH);
}

And now for the SoftSPI code:

#include <SoftSPI.h>
#include <Math.h>
#include <p32xxxx.h> 

#define RB05_GPSmosi 21
#define RB04_GPScs   15
#define RB03_GPSsclk 20
#define RB02_GPSmiso 14

uint8_t recBuf[80];

SoftSPI gps;

void setup() {
  Serial.begin(9600);
  gps.begin(RB04_GPScs, RB05_GPSmosi, RB02_GPSmiso, RB03_GPSsclk);
  gps.setSpeed(80000);
  gps.setDirection(SSPI_SHIFT_LEFT);
  gps.setDelay(10);

  //Reset gps
  sendReset();
}

void loop() {
  int i = 0;
  for(i = 0; i < 80; i++) {
    Serial.print((char) recBuf[i]);
    recBuf[i] = 0;
  }
  Serial.println();

  gps.setSelect(LOW);
  gps.transfer(80, 0xFF, recBuf);
  gps.setSelect(HIGH);
}

In both cases, I receive 0xFF whenever I try to send 0xFF. Funnily enough, I receive actual NMEA strings when I send it garbage that isn't 0xFF, but these NMEA strings don't have actual data in them, it looks something like:

$GPGLL,,,,,,,V*32

$GPGSA,,,,,A*49

etc..

^These examples are just pulled from memory so may not be exactly what I'm getting back, but very similar.

Any idea what could be causing this issue? The datasheet for the device simply says to send 0xFF if you have nothing real to send, and read what you get back for data. I've tried resetting the device to factory default by sending it a UBX code, but that didn't help at all.

Any advice or information would be greatly appreciated.

1

1 Answers

0
votes

So I am not using the SPI but UART for my Ublox LEA6T implementation. I can however speak to the fact that the NEMA you receive look valid IF there is no antenna or signal to the GPS receiver. If you post your actual SPI digitalWrite code I may be able to help more. Do you have access to a logic analyzer or scope to probe the lines?