|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
receiving data from Arduino over i2c?
this is an experiment, not needed to get bot ready for competition, but mentor curiousity:
I think I have writing to the Arduino down: if I do an i2c.write, the Arduino gets a receiveEvent, and the first byte that the Arduino receives is the register number I specified on the I2C.write() call. Getting data back is hurting my brain. If I issue an i2c.read, I would expect for the Arduino to get a requestEvent. It gets a receiveEvent, and the data on that event is the register number. The problem is that even if I write data on the Arduino from the receiveEvent handler, it doesn't seem to get back to the cRIO; cRIO just seems to hang. Does anyone have a good example of a cRIO receiving data from an Arduino over I2C that they can share? |
|
#2
|
|||
|
|||
|
Re: receiving data from Arduino over i2c?
Doug,
The following two threads may help point you in the right direction. My first thought is that you are running into an error I saw last year regarding a bug in the wire library where when you issue a read command, the Arduino outputs a STOP in between the write (register address) and the read portion of the transaction. More detail can be found in the first thread along with a work around. However, from what I recall, this problem did not hang the cRIO, it just returned a transaction failure, so your issue may be different. Let me know if this helps. Also, if you can post your code, I could take a closer look. Mike Link1 Link2 |
|
#3
|
||||
|
||||
|
Re: receiving data from Arduino over i2c?
Mike: thanks. I think I was getting bit by the Wire STOP bug. Not sure about the hang; it may have been something else...
I have your code running as expected; I'll look at finding the Wire patch to see if that simplifies things (don't like the 2-transaction code, but at least I can get data back from the Arduino. |
|
#4
|
||||
|
||||
|
Re: receiving data from Arduino over i2c?
Mike, is this the correct bug/patch for the Arduino wire library?
https://github.com/arduino/Arduino/issues/848 Quote:
|
|
#5
|
|||
|
|||
|
Re: receiving data from Arduino over i2c?
Doug,
That is the correct problem and I believe the "accepted" fix. The line removed is in the TW_SR_STOP case. There is no reason to call Code:
twi_stop(); Code:
twi_releaseBus(); Mike BTW - let me know if it actually works. Last edited by Mike Bortfeldt : 23-02-2014 at 14:00. |
|
#6
|
||||
|
||||
|
Re: receiving data from Arduino over i2c?
I will. Found the source code; need to figure out how to rebuild the library after commenting out the offending twi_stop().
|
|
#7
|
||||
|
||||
|
Re: receiving data from Arduino over i2c?
...and giving up. Doesn't matter what I do to the code in ARDUINO\library\Wire\, nothing seems to change. I even put deliberate syntax errors in there so that the compile would blow up (to verify that my changes are being compiled), nothing happens, so it appears to me that simply fixing ARDUINO\library\Wire\utility\twi.c doesn't make the changed source get recompiled and linked into the final program.
Not familiar enough with the Arduino build process to understand how to make the patch happen. Everything I Google indicates it should just be change the library source code and reload.... Will use your workaround... |
|
#8
|
|||
|
|||
|
Re: receiving data from Arduino over i2c?
Doug,
Have you tried completely closing the IDE and then reopening the sketch? I've found that many times it doesn't recognize a new source version except at startup. Mike |
|
#9
|
||||
|
||||
|
Re: receiving data from Arduino over i2c?
that didn't seem to help, but I moved it from the Arduino install directory to user's Arduino directory, and changes started taking effect.
It's hanging: I'll run some more tests and see if I can figure out what's going on.... |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|