Hi Warren,
I think I found where the problem is. You are not addressing the WHO_AM_I register (0x0D) correctly.
As shown in the datasheet:
Byte 0: R/W, ADDR[6], ADDR[5], ADDR[4], ADDR[3], ADDR[2], ADDR[1], ADDR[0]
Byte 1: ADDR[7], X, X, X, X, X, X, X
In your case tx[0] = ( 0x0D >> 1 ) & 0xFF while the correct way is tx[0] = 0x0D & 0x7F. Similarly tx[1] = ( 0x0D << 7 ) & 0xFF while the correct form is tx[1] = 0x0D & 0x80.
Here is my complete read a register function:
unsigned char FXOS8700CQ_ReadRegister(unsigned char RegisterAddress)
{
unsigned char i;
CS_Enable;
while (!(SPI0_S & SPI_S_SPTEF_MASK));
SPI0_D = 0x7F & RegisterAddress;
while (!(SPI0_S & SPI_S_SPRF_MASK));
i = SPI0_D;
while (!(SPI0_S & SPI_S_SPTEF_MASK));
SPI0_D = 0x80 & RegisterAddress;
while (!(SPI0_S & SPI_S_SPRF_MASK));
i = SPI0_D;
while (!(SPI0_S & SPI_S_SPTEF_MASK));
SPI0_D = 0x00;
while (!(SPI0_S & SPI_S_SPRF_MASK));
i = SPI0_D;
CS_Disable;
return i;
}
I hope it helps.
Best regards,
Tomas