Go to Post ...from my experience, it is really fun to play defense really well. - Andy Baker [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 22-02-2014, 17:49
fovea1959's Avatar
fovea1959 fovea1959 is offline
Herder of programmers
AKA: Doug Wegscheid
FRC #3620 (The Average Joes)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2011
Location: St Joseph
Posts: 336
fovea1959 will become famous soon enough
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?
Reply With Quote
  #2   Spotlight this post!  
Unread 23-02-2014, 10:49
Mike Bortfeldt Mike Bortfeldt is offline
Registered User
FRC #1126 (& 1511)
Team Role: Mentor
 
Join Date: Oct 2004
Rookie Year: 2004
Location: Rochester, NY
Posts: 119
Mike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud of
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
Reply With Quote
  #3   Spotlight this post!  
Unread 23-02-2014, 11:29
fovea1959's Avatar
fovea1959 fovea1959 is offline
Herder of programmers
AKA: Doug Wegscheid
FRC #3620 (The Average Joes)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2011
Location: St Joseph
Posts: 336
fovea1959 will become famous soon enough
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.
Reply With Quote
  #4   Spotlight this post!  
Unread 23-02-2014, 12:59
fovea1959's Avatar
fovea1959 fovea1959 is offline
Herder of programmers
AKA: Doug Wegscheid
FRC #3620 (The Average Joes)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2011
Location: St Joseph
Posts: 336
fovea1959 will become famous soon enough
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:
This is because there is a bug in the Arduino wire library that sends a "STOP" after the first part of the transaction even though it is setup as a SLAVE. There is a fix for this, but I have not had the chance to test it out.
Reply With Quote
  #5   Spotlight this post!  
Unread 23-02-2014, 13:48
Mike Bortfeldt Mike Bortfeldt is offline
Registered User
FRC #1126 (& 1511)
Team Role: Mentor
 
Join Date: Oct 2004
Rookie Year: 2004
Location: Rochester, NY
Posts: 119
Mike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud of
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();
as the i2c hardware will hold the clock line low until the line
Code:
twi_releaseBus();
is called a few statements later.

Mike

BTW - let me know if it actually works.

Last edited by Mike Bortfeldt : 23-02-2014 at 14:00.
Reply With Quote
  #6   Spotlight this post!  
Unread 23-02-2014, 14:58
fovea1959's Avatar
fovea1959 fovea1959 is offline
Herder of programmers
AKA: Doug Wegscheid
FRC #3620 (The Average Joes)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2011
Location: St Joseph
Posts: 336
fovea1959 will become famous soon enough
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().
Reply With Quote
  #7   Spotlight this post!  
Unread 23-02-2014, 15:54
fovea1959's Avatar
fovea1959 fovea1959 is offline
Herder of programmers
AKA: Doug Wegscheid
FRC #3620 (The Average Joes)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2011
Location: St Joseph
Posts: 336
fovea1959 will become famous soon enough
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...
Reply With Quote
  #8   Spotlight this post!  
Unread 23-02-2014, 16:16
Mike Bortfeldt Mike Bortfeldt is offline
Registered User
FRC #1126 (& 1511)
Team Role: Mentor
 
Join Date: Oct 2004
Rookie Year: 2004
Location: Rochester, NY
Posts: 119
Mike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud of
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
Reply With Quote
  #9   Spotlight this post!  
Unread 23-02-2014, 21:18
fovea1959's Avatar
fovea1959 fovea1959 is offline
Herder of programmers
AKA: Doug Wegscheid
FRC #3620 (The Average Joes)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2011
Location: St Joseph
Posts: 336
fovea1959 will become famous soon enough
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....
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 12:41.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi