mariocaptain Posted September 5, 2014 Report Share Posted September 5, 2014 Hi all, I have been using Jeff's MPU6050 Arduino library with great results.However, in my current project, I want to put getAccelerationX() (or getMotion6() for that matter) inside an IRS (ISR(TIMER2_COMPA_vect) specifically) in order to poll the MPU6050 at precise intervals (about 60Hz). But for some reason the code will hang inside the function getAccelerationX().Is this some kind of interrupt conflict? I would like to know if there is anyway to work around this. For a quick reference, this is the code of getAccelerationX(): int16_t MPU6050::getAccelerationX() { I2Cdev::readBytes(devAddr, MPU6050_RA_ACCEL_XOUT_H, 2, buffer); return (((int16_t)buffer[0]) << 8) | buffer[1];} I am using a standalone Arduino UNO, with timer0 untouched, and timer1 already used to control some motors. Will it work if I use an AVR with more timers (3,4,5) and use one of those instead of timer2 above?Thanks in advance, Dave Quote Link to comment Share on other sites More sharing options...
luisrodenas Posted September 5, 2014 Report Share Posted September 5, 2014 Hi, I think you cannot call the function readBytes() from an ISR, at least you shouldnt. The reason for this is because that function includes I2C communications, that take some time and also may conflict with ISR manager for reasons I don't really know. Just use the timer interrupt to change the value of a flag, and then check that flag from main code and execute the readbytes(). Quote Link to comment Share on other sites More sharing options...
mariocaptain Posted September 6, 2014 Author Report Share Posted September 6, 2014 Hi, I think you cannot call the function readBytes() from an ISR, at least you shouldnt. The reason for this is because that function includes I2C communications, that take some time and also may conflict with ISR manager for reasons I don't really know. Thanks a lot for the answer! That makes sense to me, that being the case then it's a big pity for the 6050, since it will limit the applications. Just use the timer interrupt to change the value of a flag, and then check that flag from main code and execute the readbytes(). Well for my application which is a balancing robot, I need to know the exact time elapsed between two consecutive readings (hence the original IRS set at 60Hz), so to move the function to the main loop and use something like micros() to keep track of the time, I would just move everything else with it then... Wish I could do the IRS because it would make the code very tidy. Does anyone have any experience using the MPU-6000 (exactly like the MPU-6050 but also comes with SPI interface) inside an IRS? Or do you think it will work? Thanks, Dave Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.