Shop OBEX P1 Docs P2 Docs Learn Events
PNI V2xe compass on Javelin — Parallax Forums

PNI V2xe compass on Javelin

veaugerveauger Posts: 3
edited 2005-02-28 23:33 in General Discussion
Hi, I'm having trouble getting the Javelin to talk to a PNI V2xe digital compass.

I have taken the BASIC code referenced by cwolff at the bottom of this (http://forums.parallax.com/showthread.php?p=469226) thread as a guide.

import stamp.core.*;

class CompassTest{

  private final static int SCLK = CPU.pin11;
  private final static int MISO = CPU.pin10;
  private final static int MOSI = CPU.pin9;
  private final static int SSNOT = CPU.pin8;
  private final static int SYNC = CPU.pin7;


  public static void main(){

  CPU.delay(1000);
  System.out.println("starting...");

  int dataIn = 0;
  int dataOut = 0;

  //just dbl check pins are low
  CPU.writePin(MISO, false);
  CPU.writePin(MOSI, false);

  //initialize clock pin
  CPU.writePin(SCLK, false);

  //send slave select low to enable SPI on target
  CPU.writePin(SSNOT, true);
  CPU.writePin(SSNOT, false);

  //set sync low, then hold it high for 2x8.68us
  CPU.writePin(SYNC, false);
  CPU.pulseOut(2, SYNC);

  //call GetModInfo function
  dataOut = 170;
  CPU.shiftOut(MOSI, SCLK, 8, CPU.SHIFT_MSB, dataOut);

  dataOut = 1;
  CPU.shiftOut(MOSI, SCLK, 8, CPU.SHIFT_MSB, dataOut);

  dataOut = 0;
  CPU.shiftOut(MOSI, SCLK, 8, CPU.SHIFT_MSB, dataOut);

  while(dataIn != 170){
    dataIn = (CPU.shiftIn(MISO, SCLK, 8, CPU.PRE_CLOCK_MSB));
  }
  dataIn = (CPU.shiftIn(MISO, SCLK, 8, CPU.PRE_CLOCK_MSB));

  //bring slave select back up
  CPU.writePin(SSNOT, true);
  CPU.delay(100);

  System.out.println("Data: " + dataIn);
  }
}




This doesn't work, and I really don't see why. I can't get any sort of meaninful response out of the thing. Can anyone help me out?

-J

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-02-28 18:45
    Isn't pin MISO supposed to be an input

    on the javelin?

    Then why set it as output (CPU.writePin(MISO,false)) ???

    regards peter
  • veaugerveauger Posts: 3
    edited 2005-02-28 19:05
    Thanks for the reply Peter -- I commented out that line and tried it -- same results, stays in the loop waiting for input from the compass.
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-02-28 20:03
    Print out the data that you do receive.

    Maybe 170 is not among the bytes received.

    regards peter
  • veaugerveauger Posts: 3
    edited 2005-02-28 20:07
    Earlier on, I had a println inside the loop and all I got was zeros. The compass isn't responding/not getting the command I am sending it.
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-02-28 23:33
    Please check with the datasheet of the device.

    The MOSI is usual the device data input, and so connects to Javelin output.

    The MISO is usual the device data output, and so connect to javelin input.

    Are you 100% sure those two are not swapped, either by wiring

    or their use in the shiftIn() and shiftOut().

    regards peter
Sign In or Register to comment.