Dear community,
I have been struggeling to get the gyrometer ( a fxas21002c) on the nxp 9DoF precision module work.
For a company project I need to read the measument values of the gyro, using a STM32F446RE via an I2C bus. I wrote a GyroInit() function to initialize the sensor, but if I read the GYRO_REGISTER_CTRL_REG1 register after initilization, the entire register is still 0. So initialization seems to go wrong, I hooked up an osciloscoop and the osciloscoop shows that the STM writes the init data.
For the past few days I have been trying to figure out why the register never gets set, help would be appreciated.
Pin connections:
Module STM
Vin > 3V3
3Vo > <unconnected>
GND > GND
SCL > SCL (D15)
SDA > SDA (D14)
RST > 3V3
Edit:
To test if the sensor works, I used a Raspberry pi 2 model b with a python script, this way I did get the expected measurement values.
Dear Madita,
Are you able to read the WHO_AM_I register (0x0C). This is the first thing I would recommend to check before initialization of the device.
You should see something like this:
1. Send a start sequence
2. Send 0x40 // FXAS21002 slave address with the R/W bit low or 0x20 << 1
3. Send 0x0C
4. Send a start sequence again (repeated start)
5. Send 0x41 // FXAS21002 slave address with the R/W bit high or (0x20 << 1) | 0x01
6. Read the data byte from WHO_AM_I register
7. Send NAK and the stop sequence
A common problem during the read operation is that some customers send the stop condition (a LOW to HIGH transition of SDA while SCL is HIGH) instead of sending the repeated start condition after the second byte (0x0C), so please double check it.
Since you have an oscilloscope, can you please post here a plot illustrating what is going on on the bus when you read the WHO_AM_I register? Also a picture illustrating the traffic when writing to the CTRL_REG1 register might be helpful.
Best regards,
Tomas
PS: If my answer helps to solve your question, please mark it as "Correct" or “Helpful”. Thank you.
Dear Tomas,
Thanks for the fast response!
I tried reading the WHO_AM_I register and it returned 215 dec, as expected.
WHO_AM_I plot:
REG1 read plot:
Initialisation sequence:
Reset:
Set REG1 (control register):
Set Active:
The WHO_AM_I read looks different than yours, but it returns the correct value.
Can you see a mistake?
Dear Madita,
It seems like your write operation is incorrect. The correct format looks like this:
So if you want to write 0x03 to the CTRL_REG1 register (0x13), you need to (when SA0 = 0):
1. Send a start sequence
2. Send 0x40 // FXAS21002 slave address with the R/W bit low or 0x20 << 1
3. Send 0x13 // Address of the CTRL_REG1 register
4. Send 0x03 // Data to be written to the CTRL_REG1 register
5. Send a stop sequence
Hope it helps!
Best regards,
Tomas
Dear Tomas,
At the moment I use a function STM provided to do exactly what you say, I do the following:
uint8_t tempData = 0x03;
HAL_I2C_Mem_Write(&hi2c1, (0x20 << 1), 0x13, 1, &tempData, 1, 100);
Function definition of HAL_I2C_MEM_WRITE:
HAL_StatusTypeDef HAL_I2C_Mem_Write(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size, uint32_t Timeout)
The plot from this code is what is shown in picture 2 (set REG1) of my reaction.
But this does not seem to work.