title: GPS ublox-6 neo6 communication with Microcontroller using SPI
body: <p>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.</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>Here's my bit-banging code:</p>
  
  <pre><code>#include &lt;plib.h&gt;  
  #include &lt;Math.h&gt;
  #include &lt;p32xxxx.h&gt; 
  
  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 &lt; 8; i++) {
      digitalWrite(RB05_GPSmosi, ((0xFF &gt;&gt; (7-i)) &amp; 0x01));
      digitalWrite(RB03_GPSsclk, 1);
      received |= digitalRead(RB02_GPSmiso) &lt;&lt; (7-i);
      digitalWrite(RB03_GPSsclk, 0);
    }
  
    if((received &amp; 0xFF) != 0xFF)
      Serial.println(received);
  
    digitalWrite(RB04_GPScs, HIGH);
  }
  </code></pre>
  
  <p>And now for the SoftSPI code:</p>
  
  <pre><code>#include &lt;SoftSPI.h&gt;
  #include &lt;Math.h&gt;
  #include &lt;p32xxxx.h&gt; 
  
  #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 &lt; 80; i++) {
      Serial.print((char) recBuf[i]);
      recBuf[i] = 0;
    }
    Serial.println();
  
    gps.setSelect(LOW);
    gps.transfer(80, 0xFF, recBuf);
    gps.setSelect(HIGH);
  }
  </code></pre>
  
  <p>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:</p>
  
  <p>$GPGLL,,,,,,,V*32</p>
  
  <p>$GPGSA,,,,,A*49</p>
  
  <p>etc..</p>
  
  <p>^These examples are just pulled from memory so may not be exactly what I'm getting back, but very similar.</p>
  
  <p>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.</p>
  
  <p>Any advice or information would be greatly appreciated.</p>