![]() |
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? |
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 |
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 |
Re: Java SPI comm
Quote:
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); |
Re: Java SPI comm
2 Attachment(s)
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) |
| All times are GMT -5. The time now is 23:32. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi