chipKIT® Development Platform

Inspired by Arduino™

Wire.endTransmission(false); equivalent

Created Mon, 16 Feb 2015 12:39:41 +0000 by alexceltare2


alexceltare2

Mon, 16 Feb 2015 12:39:41 +0000

Hi guys. My project is killing me when I want to use TWI/I2C. On Arduino, i can use the Adafruit MPR121 sketch without any problem but on chipKit the Wire.endTransmission(false); is a problem. I get the error:

D:\Documents\mpide\libraries\Adafruit_MPR121_Library\Adafruit_MPR121.cpp: In member function 'uint8_t Adafruit_MPR121::readRegister8(uint8_t)':
D:\Documents\mpide\libraries\Adafruit_MPR121_Library\Adafruit_MPR121.cpp:102:31: error: no matching function for call to 'TwoWire::endTransmission(int)'
C:\Program Files\MPIDE\.\hardware\pic32\libraries\Wire/Wire.h:96:13: note: candidate is: uint8_t TwoWire::endTransmission()
D:\Documents\mpide\libraries\Adafruit_MPR121_Library\Adafruit_MPR121.cpp: In member function 'uint16_t Adafruit_MPR121::readRegister16(uint8_t)':
D:\Documents\mpide\libraries\Adafruit_MPR121_Library\Adafruit_MPR121.cpp:110:31: error: no matching function for call to 'TwoWire::endTransmission(int)'
C:\Program Files\MPIDE\.\hardware\pic32\libraries\Wire/Wire.h:96:13: note: candidate is: uint8_t TwoWire::endTransmission()

this happens because, in the library, the line Wire.endTransmission(false); isn't supported and using Wire.endTransmission(); won't make the code work.

The few lines of code where the problem occurs are:

uint8_t Adafruit_MPR121::readRegister8(uint8_t reg) {
    Wire.beginTransmission(_i2caddr);
    Wire.write(reg);
    Wire.endTransmission(false);
    while (Wire.requestFrom(_i2caddr, 1) != 1);
    return ( Wire.read());
}

uint16_t Adafruit_MPR121::readRegister16(uint8_t reg) {
    Wire.beginTransmission(_i2caddr);
    Wire.write(reg);
    Wire.endTransmission(false);
    while (Wire.requestFrom(_i2caddr, 2) != 2);
    uint16_t v = Wire.read();
    v |=  ((uint16_t) Wire.read()) << 8;
    return v;
}

Thanks


JesseN

Wed, 25 Feb 2015 22:36:37 +0000

Wire.endTransmission(Bool); is not a defined function in the TWI library for chipKIT borads. When you say that Wire.endTransmission(); will not work, what do you mean? What are the results of this when you run it?

You should try this

Wire.beginTransmission(_i2caddr); Wire.send(reg); Wire.endTransmission();

//do a repeat start Wire.beginTransmission(_i2caddr); Wire.requestFrom(_i2caddr, 1); uint8_t data = Wire.receive(); Wire.endTransmission();

return data;


alexceltare2

Wed, 25 Feb 2015 22:47:45 +0000

When you say that Wire.endTransmission(); will not work, what do you mean? What are the results of this when you run it?

In Arduino, the code works fine, but if I put Wire.endTransmission(); the Serial monitor says "Adafruit MPR121 Capacitive Touch sensor test. MPR121 not found, check wiring?". But if I compile the code in chipKit using your idea, or any other idea like before it just says "Adafruit MPR121 Capacitive Touch sensor test." and then nothing happens. Is like the code froze at some point. I've previously contacted Keith Vogel, the creator of the Wire library for chipKit but he said the Chipkit Wifire has a hardware bug relating the I2C and suggested I should use DTWI, but is hard. :( Anyway, hope someone can help me undo this issue as i'm quite desperate at the moment. But thank you so much Jesse. I appreciate :D