Created Thu, 03 Mar 2016 12:52:44 +0000 by YOBE.
Thu, 03 Mar 2016 12:52:44 +0000
Hi,
any smart guys who know how to solve this professionally? I use Fubarino, but Chipkit has same issue. As soon as I start to generate interrupts the software hangs, These are the defined interrupts.
attachInterrupt(4, leftEncoder, RISING); attachInterrupt(0, rightEncoder, RISING);
When I execute a routine which involves wire.h and simultaneously external interrupts are generated, the software hangs. Without generating interrupts the software runs perfectly. External interrupts come from 2 motor-encoders who generate a high amount of pulses. For the moment I can solve it by disabling the interrupts when the wire routine is executed. But looks amateurism... (see code below).
Anybody has suggestions how to solve this as a pro. Or is this the only way?
Thanks!
const uint8_t IMUAddress = 0x68; // AD0 is logic low on the PCB const uint16_t I2C_TIMEOUT = 1000; // Used to check for errors in I2C communication
uint8_t i2cWrite(uint8_t registerAddress, uint8_t data, bool sendStop) { return i2cWrite(registerAddress,&data,1,sendStop); // Returns 0 on success }
uint8_t i2cWrite(uint8_t registerAddress, uint8_t *data, uint8_t length, bool sendStop) { Wire.beginTransmission(IMUAddress); Wire.send(registerAddress); Wire.send(data, length); uint8_t rcode = Wire.endTransmission();//sendStop); // Returns 0 on success if (rcode) { Serial1.print(("i2cWrite failed: ")); Serial1.println(rcode); } return rcode; }
uint8_t i2cRead(uint8_t registerAddress, uint8_t *data, uint8_t nbytes) { uint32_t timeOutTimer;
Wire.beginTransmission(IMUAddress); Wire.send(registerAddress);
***THIS PART NEEDS ISOLATION!!!! clearIntEnable(_EXTERNAL_0_VECTOR); used to disable external interrupt, crashes with wire.h clearIntEnable(_EXTERNAL_4_VECTOR);
uint8_t rcode = Wire.endTransmission();//false); // Don't release the bus if (rcode) { Serial1.print(("i2cRead failed: ")); Serial1.println(rcode); return rcode; } Wire.requestFrom(IMUAddress, nbytes);//,(uint8_t)true); // Send a repeated start and then release the bus after reading
setIntEnable(_EXTERNAL_0_VECTOR); // used to enable external interrupt, crashes with wire!! setIntEnable(_EXTERNAL_4_VECTOR); BEYOND THIS PART, NO NEED ISOLATION!!!!***
for (uint8_t i = 0; i < nbytes; i++) { if (Wire.available()) data[i] = Wire.receive(); else } }
return 0; // Success }
Sun, 12 Jun 2016 01:28:07 +0000
Which version of the tools are you using? I was trying to use interrupts with the Fubarino SD a couple of days ago with no luck with chipKIT-core 1.1.0. I'm going to dig in to it in about a week if someone else doesn't get to it first.
Jacob