For read MPU6050 stuck data are summarized in tinyOS

In recent days has been to tinyOS mount peripherals, from the most simple LED, KEY, and then to the serial port, these are no big problem, nothing more than initialize tinyOS, then initialize the hardware peripherals, and then start tinyOS, and then to find tinyOS the highest priority task and run.

 

But I MPU6050 follow these steps to find MPU6050 DMP initialization and initialization no problem, but I could not reproduce the life and death data. In general MPU6050 bare metal program, if read at the data, mpu_dmp_get_data () function will return a value, an error may occur based on the return value positioning what position MPU6050 code in acquiring data. But my mistake is more Niubi, there is not even a return value.

 

 In any case, the difficulties!

 

Single-step debugging mode is turned on!

 

In the step-by-step debugging, we found the problem, because the code is portable punctual atoms, the code stuck in this place.

 

mpu_dmp_get_data()           -->               

dmp_read_fifo()                    -->

mpu_read_fifo_stream()       -->

mpu_reset_fifo()                                                

 

See, here there is a delay of 50ms, for real-time operating systems, 50ms latency is like a thousand years, so decisively put this code deleted. After I have been compared to other vendors MPU6050 stm32 initialization code, we do not have this delay of 50ms, showing that this is added to the list of punctuality atom.

 

OK, get rid of this 50 millisecond delay, try the procedure again, well, this case has a return value, but there is no data out.

 

 

It seems there are still problems, continue to step through and found the problem or locate mpu_reset_fifo () this function, but this function is MPU6050 official manufacturer InvenSense company to write, no problem ah, the official wrote to have any problem then.

 

No way, continue to troubleshoot the problem, which can only be checked at each function in the end is doing it up.

 

Under MPU6050 to check the data sheet. This thing is found FIFO to store data MPU6050 attitude, then go read FIFO, the attitude data read out, but why go to the code resets the FIFO it? Certainly FIFO data is full and overflowing. But why would spill it? Description no time to read the data, the more data lead to heap more, it overflowed. Like you to stop irrigation than kettle, filling into not to use this water, so only the more irrigation leading to overflow.

 

Under the root cause of this problem is found, you can modify the code. The fundamental solution is that after MPU6050 and DMP initialization immediately read FIFO data inside.

 

First is that the code is not modified before the code after tinyOS initialization and hardware initialization, there will be a 1 second to test how much code MCU can run at full speed, which is behind the measure in order to facilitate the use of MCU.

 

After MPU6050 error is because of this one second, so the initialization MPU6050 and DMP initialization on this test MCU 1 second, but the solution is not satisfactory, because there MPU6050 initialization 100 milliseconds of delay.

 

After a series of changes, the best solution is to use a software timer. After tinyOS initialization, the hardware initialization and start tinyOS, before starting the MCU running at full speed for 1 second, open the software timer. In this scanning software timer inside mpu_dmp_get_data () function, this problem is completely solved next.

 

Serial output data as follows:

 

Guess you like

Origin www.cnblogs.com/sanshijvshi/p/11891970.html