kriswiner / MPU9250

Arduino sketches for MPU9250 9DoF with AHRS sensor fusion
1.03k stars 471 forks source link

MPU9250 FIFO Data corruption #384

Open lasithf opened 4 years ago

lasithf commented 4 years ago

Hi Kris,

I am seeing a strange behaviour from the MPU9250 FIFO. At some point I am getting FIFO data corrupted! When I look at the data registers for accelerometer (accel), if I print them along with the FIFO data, I can see the accel data registers are quite accurate while at the same time FIFO got some unrealistic large values in the accel data xyz.

Power cycle the MPU9250 seems fixing this issue, but I don’t know what is the root cause.

It looks like when accessing the data registers directly while the FIFO is enabled and running causing FIFO data alignment issue (just a thought!). As I have enabled only accelerometer and magnetometer go in to the FIFO, which is 13 bytes in total, I suspect when I access data registers could cause FIFO data to corrupt (mis-aligned).

Any thoughts what would be going on here? Appreciate your help.

CatInTheRain commented 3 years ago

Hi everyone i think the issue is solved!!!!!!!!!!! (I used only one IMU for now, i' m sorry but i was too excited and i want to share the idea immediately) On my code before take the 7 bits from EXT_SENS_DATA i reset and set the I2C in this way: -In the register 106 USER_CTRL (0x6A) set the bit [1] to 1 (0x02); -In the same register (0x6A) set the bit [5] to 1 (in fact i set also the bit[4] to 1, to remain coherent to the code i use, but i think it' s the same); if you reset the I2C at each reading a new problem arises because the reading goes to "hiccups". To solve this issue in an engineering way you can put an if and a counter to call the reset every 1000 samples (for example). I think the reset it' s a wonderful idea because when i was debugging the code I noticed that at some time the reading feeze (as usual) and after the counter overflowed reading has started working again!! The better think is to find the right flag or interrupt. Anyway i have analyzed the data on Simulink-Matlab and there isn't any weirdness because probably there is noise and if the data is constant for some msec the reset effects are hidden. Now i go to drink a beer !! PJiaHeng if you will write new code to use DMA to read the 2 IMUs i would be very happy if you will explain to me. I'm not very good with DMA and FIFO... Let me know if it works!

PJiaHeng commented 3 years ago

In my code, accel and gyro are running to 100Hz. I think it is a good solution for you to reset the I2C master at intervals. I also made the same configuration on my code. The equals consecutive datas does not appear again. But the result is that when I connect only one IMU to the MCU, there will be no freezing, and when I connect 2 IMUs, the freezing still occurs. Do you only need to connect one IMU in your project? Do you verfy your solution on the connecting 2 IMUs? I will use DMA and FIFO way to get data When I solve the issue about connecting one more IMUs to MCU. Take the liberty to ask, would it be convenient for you to share the library files of your MPU9250?

PJiaHeng commented 3 years ago

Re: 8-10 same mag data: Mag is slower than accel and gyro sample rate, therefore if you run at a higher sample rate, mag will copy same data to fill the sample rate gap. This is what I've seen on my end. Does the mag lockup fix when you power cycle?

Hello, when I power off and powe on, the mag lockup fix. But this is not good solution in my project.

CatInTheRain commented 3 years ago

Hi PJiaHeng, are you sure that sample rate of accel and gyro are run in 100Hz? maybe you call the function to get datas every 10 msec, like me. If you have set the DLPF to accel and gyro their sample rate is 1Khz. However i have to do a project for my university, so i must connect 2 IMUs and I would like to save the cpu for the acquisition using the DMA, but sincerely I lost a lot of time with this problem I would not lose more. In MXCube you have set SPI Receive with DMA and you set FIFO mode (and then generate code?). I send you to you an email with my library (it works with 2 IMUs). I use a temporary email address so have a look at the spam.

CatInTheRain commented 3 years ago

You were right: the bit [0] of register 58 when mag freeze is set to 0!

PJiaHeng commented 3 years ago

Ohhh, that is my fault. I regard the sampling rate configuration when using FIFO as the sampling rate of getting data from the sensor data register. The sample rate can be set to 100Hz by configuring Register 25 – Sample Rate Divider as 0x09. I plan to listen to your suggestions and call the function to get datas every 10 msec.

Yes, the bit [0] of register 58 when mag freeze is set to 0. And do you notice the bit3 is set to 1 when mag freeze?

I don't get your email in my mailbox even spam. In order to receive your email, I changed my email address. Can you send it to me again?

PJiaHeng commented 3 years ago

I don't use MXCube to generate code about DMA and FIFO. Just add a few DMA-related functions directly in your program. It is so easy. The premise is that you need to correspond to the technical documentation of STM32F7 and confirm the correct register operation. There should be encapsulated functions in the HAL library, so in your DMA related functions, you only need to call the related functions according to the process of operating DMA. There are two parts about DMA using. The first is configuration: DMA transmission size, DMA stream, direction and IRQchannel. Second is operation: enable spi dma request, enable dma stream. If you want to more details about these, I can reply this part of the code to your mailbox as a reference for you to implement DMA.

CatInTheRain commented 3 years ago

"I plan to listen to your suggestions and call the function to get datas every 10 msec." In the main i have initialize a timer to ensure that the frequency is that (it's a bit more complicate because i have also potentiometers to read...).

"Yes, the bit [0] of register 58 when mag freeze is set to 0. And do you notice the bit3 is set to 1 when mag freeze?" No, I only read 0x01, i don't know why it' s difference from you.

Yes, i would be very glad if you if you can send me an email with the code for the initialize of the FIFO and the DMA, thanks you so much. I have sent to you the email with the code. I will write my email address in my Github Bio. Give me confirmation if you got it.

P.S. excuse me the curiosity: what time is in your country? I would not want to disturb your sleep taking too long to answer you.

CatInTheRain commented 3 years ago

If you configure Register 25 – Sample Rate Divider as 0x09 you are configured the data output rate of the FIFO? I have a lot of dubts of this register because in page 15 the manual says: "Following is a small subset of ODRs that are configurable for the accelerometer in the normal mode in this manner (Hz): 3.91, 7.81, 15.63, 31.25, 62.50, 125, 250, 500, 1K" So i I thought I could only influence the accelerometer.

PJiaHeng commented 3 years ago

I am already reply your email. Can you recevie it? The sample rate of FIFO is decided only by register25.

PJiaHeng commented 3 years ago

I have not used FIFO on my project yet, I have used MPU9250 FIFO before.

CatInTheRain commented 3 years ago

Sorry PjiaHeng, i lost my account email xD. I didn' t read last email that you send and I don' t remember you address email. I wrote on my BIO my new addres !

PJiaHeng commented 3 years ago

Sorry PjiaHeng, i lost my account email xD. I didn' t read last email that you send and I don' t remember you address email. I wrote on my BIO my new addres !

I resend my email. Do you receive?

CatInTheRain commented 3 years ago

yes I have replayed.