FXOS8700 SPI question

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

FXOS8700 SPI question

116 Views
warr1
Contributor II

I am want to use the FXOS8700 in SPI mode. I set the parameters of the SPI bus according to the FXOS8700 data sheet. 

In order to get the FXOS into SPI mode, I tri-state the MISO pin before toggling the reset pin, and waiting the required time for the auto detection circuit to put the device into SPI mode.

void FXOS8700_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
__HAL_RCC_GPIOA_CLK_ENABLE();
GPIO_InitStruct.Pin = GPIO_PIN_MISO;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
HAL_Delay(10);
GPIO_InitStruct.Pin = GPIO_PIN_RST;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_RST, GPIO_PIN_SET);
HAL_Delay(1);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_RST, GPIO_PIN_RESET);
HAL_Delay(1);
}

 Next, initialize the SPI bus.

void MX_SPI1_Init(void)
{
hspi1.Instance = SPI1;
hspi1.Init.Mode = SPI_MODE_MASTER;
hspi1.Init.Direction = SPI_DIRECTION_2LINES;
hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
hspi1.Init.NSS = SPI_NSS_SOFT;
hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_128;
hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi1.Init.CRCPolynomial = 10;
if (HAL_SPI_Init(&hspi1) != HAL_OK)
{
Error_Handler();
}
}

My STM32 only connects to the FXOS8700. Therefore, the cs_b of FXOS8700 is directly grounded. During the reading process, cs_b remains at a low voltage, so it is not operated in the code. I then attempt to read the WHO_AM_I register and get the value 0xff instead of 0xff which is what I would expect.

Below is the code I am using to reset the device and read the WHO_AM_I register:

unsigned char FXOS8700CQ_ReadRegister(uint8_t RegisterAddress)
{
uint8_t tx_data[3];
unsigned char rx_data[3];
tx_data[0] = (RegisterAddress & 0x7F);
tx_data[1] = (RegisterAddress & 0x80);
tx_data[2] = 0x00;
if (HAL_SPI_TransmitReceive(&hspi1, tx_data, rx_data, 3, HAL_MAX_DELAY) != HAL_OK)
{
return 0x01;
}
return rx_data;
}

The final result is below:

rx_data[0] = 0xFF
rx_data[1] = 0xFF
rx_data[2] = 0xFF

Anybody else getting this problem?

Labels (1)
Tags (2)
0 Kudos
Reply
3 Replies

93 Views
TomasVaverka
NXP TechSupport
NXP TechSupport

Hi,

First of all, please note that the FXOS8700CQ is EOL and not recommended for new designs.

Based on description, the first thing I would recommend to try is to toggle the CS_B pin between low and high to latch data during SPI communication. Grounding the CS_B pin directly may not work.

Next, as I am not familiar with STM MCUs, I cannot check your SPI initialization. Please double check that it matches the FXOS8700 requirements:
Clock Polarity (CPOL): 0 (idle low)
Clock Phase (CPHA): 0 (data captured on the leading edge of the clock)

Your read a register seems to be correct. 

Do you have a logic analyzer or an oscilloscope to see what is going on the bus?

BRs, Tomas

 

0 Kudos
Reply

73 Views
warr1
Contributor II

During the reset process of FXOS8700, I set SA0 to a high impedance state. After resetting, int1 was detected and a reset signal can be detected. Is there any way to detect if FXOS8700 has switched to SPI mode?

0 Kudos
Reply

79 Views
warr1
Contributor II

Hi Tomas,I have revised CS_S according to your suggestion, and now it is completely controlled by the MCU. I still haven't received the correct signal yet. I captured the signal through a logic analyzer as follows:1734664688299.png

 

0 Kudos
Reply