Go to Post Back in MY day, we had full metal to metal contact. Not any of this wussy bumper stuff! - Michael Hill [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 11-01-2012, 02:06
theprgramerdude theprgramerdude is offline
WPI Freshman
AKA: Alex
FRC #2503 (Warrior Robotics)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2008
Location: Brainerd, Minnesota
Posts: 347
theprgramerdude has much to be proud oftheprgramerdude has much to be proud oftheprgramerdude has much to be proud oftheprgramerdude has much to be proud oftheprgramerdude has much to be proud oftheprgramerdude has much to be proud oftheprgramerdude has much to be proud oftheprgramerdude has much to be proud oftheprgramerdude has much to be proud oftheprgramerdude has much to be proud of
Java SPI comm

We're in the midst of switching from C++ to Java on our team (various reasons, mainly because it's easier to teach in for the 5 or so new programmers, and the only other senior programmer is more comfortable with it). While I was looking through the WPILibj library for using our ADXL345 in SPI mode, I noticed there were no classes for communicating via SPI. AT ALL.

What's the reason that we're limited to using the I2C interface, rather than SPI if we need to talk to other digital sensors that we dont have the slots for?
__________________
Attending: MN Duluth Regional
  #2   Spotlight this post!  
Unread 11-01-2012, 06:28
rudun's Avatar
rudun rudun is offline
Registered User
FRC #0496 (Royals)
Team Role: Coach
 
Join Date: Jan 2009
Rookie Year: 2005
Location: Babylon
Posts: 45
rudun is an unknown quantity at this point
Re: Java SPI comm

Communicating with spi is done at the fpga level. There is a provided class called tSPI.

edu.wpi.first.wpilibj.fpga.tSPI

this thread has a great example of SPI in java

http://www.chiefdelphi.com/forums/sh...&highlight=SPI

Last edited by rudun : 11-01-2012 at 07:29.
  #3   Spotlight this post!  
Unread 25-01-2012, 17:58
mitchellweb1 mitchellweb1 is offline
Registered User
AKA: Mitchell W
FRC #0190
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2009
Location: Acton, MA
Posts: 30
mitchellweb1 is an unknown quantity at this point
Re: Java SPI comm

Here is the SPI code that I have been working on for WPILibJ http://users.wpi.edu/~mwills/frc/ It is a little different than the current C implementation but I tried to make it so that it would be very easy to interact with multiple devices on the same SPI bus (the cRIO is only capable of one SPI bus). Please note that before you use the SPI device you must call SPIDevice.initBus (and you can call SPIDevice.freeBus to cleanup) with the clock, miso, and mosi pins.You can look at ADXL345_SPI.java for an example implementation of an SPIDevice (note this class does not contain the calls to initBus!). Please let me know if you get it working or have any problems or suggestions to improve the class. Eventually this code will be rolled into WPILibJ but it is still relatively untested.

--Mitchell
  #4   Spotlight this post!  
Unread 26-01-2013, 00:44
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,586
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: Java SPI comm

Quote:
Originally Posted by mitchellweb1 View Post
Here is the SPI code that I have been working on for WPILibJ http://users.wpi.edu/~mwills/frc/.
Thanks for working on this!

I've been playing with this code and had trouble with the chip select being short when I used a slower clock rate. I traced this to calling the following code after the transfer (in the transfer method)

Code:
            tSPI.writeChannels_SS_Module(0);
            tSPI.writeChannels_SS_Channel(0);
I commented it out and things are working. This might break if there are multiple devices on the bus, but I'm only using one. My problem might have been aggravated because I'm using a write only device and I had to remove the loop waiting for the read.

Last edited by Joe Ross : 26-01-2013 at 09:39.
  #5   Spotlight this post!  
Unread 26-01-2013, 12:00
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,586
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: Java SPI comm

Here's my updated SPIDevice class which is working for the LCD screen that I'm working with.

Changes (I also included a patch to Mitchel's version):
Don't read if writeOnly is true.
Add method for setting frame mode
fix typo in transferStatic method name
don't reset SS module and channel after transfer (fixes CS problem previously mentioned)
Attached Files
File Type: java SPIDevice.java (17.0 KB, 25 views)
File Type: txt SPIDevice.patch.txt (5.9 KB, 15 views)
Closed Thread


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 18:54.

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