Jump to content
  • 0

wire.endtransmission(false); equivalent


alexceltare2

Question

I already started a thread in chipKit forums(http://chipkit.net/forum/viewtopic.php?f=7&t=3189) and (http://chipkit.net/forum/viewtopic.php?f=7&t=3117) but no one was able to reply so you guys are my last hope. In my last post() I discussed about my intention to use a 2 wire interface device/I2C but I got problems whenever I go. I use a chipkit Wi-Fire board and i want to use an MPR121 capacitive touchpad with it and I have 2 coding options:

- The sparkfun's MPR121 code approach(https://www.sparkfun.com/products/12017) which uses i2c functions which is massive and the code gives me a million of errors and an "AVR specific code incompatible with MPIDE" which is a big "no no".

- The Adafruit's MPR121 code approach(https://learn.adafruit.com/adafruit-mpr121-12-key-capacitive-touch-sensor-breakout-tutorial/wiring) which gives me just 1 error related with the inability of the chipkit libraries to handle multiple states or something. Basically the code has a wire.endtransmission(false); and chipkit only has wire.endtransmission(); funtion. So I would like to ask you guys for an equivalent of that code. Or the library needs modifications. Maybe Keith Vogel from Digilent knows how to fix this as he designed the library.

 

Thank you in advance everyone.

Link to comment
Share on other sites

10 answers to this question

Recommended Posts

Hi alexceltare2,

 

I'm taking a look into the Adafruit MPR121 code. At first glance, the wire library that Adafruit is attempting to use is not the same as the wire library that comes with MPIDE. Specifically, Wire.write and Wire.read are not functions in the chipKIT wire library; they use Wire.send and some other functions instead. I'm going to see if the Adafruit library can be changed easily enough to be compatible.

 

Thanks,

JColvin

Link to comment
Share on other sites

Hi alexceltare2,

 

Turns out the Wire library has different functions available depending on which version of MPIDE you are using. I am using the latest available version of MPIDE (0150-windows-20150204, available here) and when I change the Adafruit library so that the readRegister functions just have WireendTransmission(); as opposed to Wire.endTransmission(false); MPIDE appears to compile the code without complaint.

 

Which version of MPIDE are you using?

 

Thanks,

JColvin

Link to comment
Share on other sites

Hi alexceltare2,

 

Which version of MPIDE are you using?

 

Thanks,

JColvin

 

Hello again J.

I'm using the same version (0150-windows-20150204-test) and don't think i haven't tried that trick already. Yes, it does compile but it doesn't actually work. I hook my MPR121 with the correct 2 wires and when I open the serial viewer it just says "Adafruit MPR121 Capacitive Touch sensor test", nothing after that. When I use my Arduino Uno to test the code, it works perfectly. It says "MPR121 found!" and it displays my touch inputs. But it works only with wire.endTransmission(false); if I change in the Arduino Uno compiler the wire.endTransmission(false); to wire.endTransmission(); it still compiles but has the same behaviour like in MPIDE so i really need to use the wire.endTransmission(false); condition. My assumption is that the latest Wire library in Arduino is updated as I saw but the MPIDE one isn't.

Link to comment
Share on other sites

Hi alexceltare2,

 

After combing through the Wire libraries for awhile between Arduino and MPIDE, the difference that I am seeing is that the wire.endTransmission(false) for an Arduino issues a restart condition.

 

To do the same thing with the wire library in MPIDE (through the use of the Digilent TWI library that MPIDE's Wire relies on in the newest version of MPIDE), you would want to replace all the "Wire.endTransmission(false);" with "Wire.beginTransmission(_i2caddr);" instead. This will effectively issue a restart condition on the I2C bus, as per Keith's comments in the DTWI library.

 

The code on my end compiles, although I don't have the MPR121 to test to see if it works successfully.

 

Let me know how it goes.

 

Thanks,

JColvin

Link to comment
Share on other sites

Still nothing.  :(  The Serial Monitor just says "Adafruit MPR121 Capacitive Touch sensor test" and nothing more happens. Is like the code hangs at some point, or can't read the registers. Do i need to use the IRQ pin? On arduino i leave it floating and everything goes well still. Probably because the original code was i2c based code. Anyway, thanks a lot J. Hope i can get this sorted at some point before the deadline.

Link to comment
Share on other sites

You shouldn't need to use the IRQ pin. As long as you're running everything the same in terms of voltage and only using the pull-up resistors that come on the MPR121, everything should be good to go electrically speaking. 

 

I'll try to keep playing around with the code and confirm that the new library works with other I2C demos that I have successfully completed before on the old library and see if I learn anything from it. 

Link to comment
Share on other sites

Thanks J. I've contacted Keith V. the creator of the library and all he told me is the following:

 

 

  

If you are using the Wi-FIRE board, you are using an MZ which there is a STOP condition bug in the hardware. I have written the DTWI I2C library that works around the stop condition bug on the Wi-FIRE. 

I also wrote a compatibility layer for wire, but that only exists in the latest drop of MPIDE 

        http://chipkit.s3.amazonaws.com/builds/mpide-0150-windows-20150204-test.zip 

Wire should work with some potential timing differences. The endTransmission will apply a stop condition on the bus using the compatibility layer. 

 

As a general rule I find the Wire library to be a horrible interface for I2C, which is why I wrote the DTWI library. You can look at the I2CMasterEEProm and I2CSlaveSimEEProm examples to see how to use the DTWI library. You do just about any Master/Slave operation with this library. It also works with the WiFIRE and MZ MCU. 

Good Luck 
KeithV 

  

 

So far, I still haven't managed how to port from Wire to DTWI so I guess I will cry again. But hey, thank you for your help too J.

Link to comment
Share on other sites

Yeah, I'm not sure why the Wire library isn't nicely porting over to that library. The way that the chipKIT Wire library is written now, it calls functions from the DTWI library (even if it has to jump through a few other functions first), so for all practical purposes (from my limited understanding of the chipKIT libraries), it would work in theory. 

 

My I2C demo that I know works using the older chipKIT library (for an Uno32) is running into some sort of issue as well with the newer Wire/ DTWI libraries. I'll work with Keith on that and see if we can get that resolved (which might help resolve your issue as well.

 

Thanks,

JColvin

Link to comment
Share on other sites

Hmm, I tried just unplugging and replugging in my board from the power supply and now both versions of the Wire library seem to have no issue and keep the demo running as expected. So that's not really an "issue" that I can bring up to Keith...

 

I'll let you know if happen to find anything in the future related to this.

 

Thanks,

JColvin

Link to comment
Share on other sites

Thank you again Mr. J. So like I said, I tried everything the community suggested and it didn't worked. I've uploaded some pics (just link because the forum doesn't allow me to post directly) to show what i get after compilation and testing the MPR121.

 

http://i786.photobucket.com/albums/yy144/alexceltare2/arduino_zpskgdgk6s4.png for Arduino

http://i786.photobucket.com/albums/yy144/alexceltare2/chipkit_zpszbahmbim.png for chipkit

 

In theory, the chipkit should give me a response if IS working or IS NOT working, but it doesn't. It gives me the same behaviour even if i completely disconnect my MPR121.  :(  Thank you again.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...