Here is how my code has evolved:
void SPI_init(void)
{ // 1.25 MHz / 896
// SPIBR: ??=0,SPPR2=1,SPPR1=1,SPPR0=0,??=0,SPR2=1,SPR1=1,SPR0=0
SPIBR = 0x66; // Set the baud rate register
// SPICR2: ??=0,??=0,??=0,MODFEN=1,BIDIROE=0,??=0,SPISWAI=0,SPC0=0
SPICR2 = 0x10; // Set control register 2
// SPICR1: SPIE=1,SPE=1,SPTIE=0,MSTR=1,CPOL=0,CPHA=1,SSOE=1,LSBFE=1
SPICR1 = 0xD7; // Set control register 1
}
void SPI_func(void)
{
int i;
PTG_PTG2 = 0; // Drive SS* low
//EnterCritical(); // Save the PS register
for (i=0; i<10; i++)
{
SPIDR = in_buf[i]; // Send 0xA4
while ((SPISR & 0x80) == 0) ;
out_buf[i] = SPIDR; // Receive 0xA4
}
//ExitCritical(); // Restore the PS register
}
As you can see I am no longer using an interrupt driven SPI system. I do get a little data from the compass but only one byte. That one byte fills the return buffer over and over again. If I reset the NE64 the number which fills the return buffer changes. But, I still only get one byte.
What should be appearing in the return buffer is:
0xA4
0x02
two bytes of data
0xA0
What is sent to the compass as a command string is:
0xA4
0x02
0xA0
Errors are written as:
0xAE
8 bit error code (0xFF, 0xFE, or 0xFD)
0xA0
I am using an external pin PinG2 to drive the SS*. This is what allowed me to gain even one byte back from the compass.
My debugger shows the input buffer contains the correct string. My oscilloscope only shows a flicker and then SS* goes back to where it was, and the SCK only shows one pulse and then it returns to baseline. I am beginning to think the SPI port of the compass is dead.
Any more thoughts?
Kevin.