PNI V2xe compass on Javelin
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.
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
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
on the javelin?
Then why set it as output (CPU.writePin(MISO,false)) ???
regards peter
Maybe 170 is not among the bytes received.
regards peter
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