What does the log say?
On May 18, 2017 1:12 PM, <[email protected]> wrote:
> Hi,
>
> I have tried to implement the SPI master using the example HELLOIOIO
> SPI example. My application is terminating (It says ioio disconnected ) on
> toggling the button.
>
> Here is my looper code
>
> class Looper extends BaseIOIOLooper {
> /** The on-board LED. */
> private DigitalOutput led_;
> private SpiMaster SPI;
>
> int[] slaves = new int[]{0,1,2};
> int[] SS_PINS = new int[]{45,46,47};
> static final int MISO_ = 3;
> static final int MOSI_ = 4;
> static final int CLCK_ = 5;
> final int DATA_SIZE = 19;
> byte[] request = new byte[5];
> byte[] response = new byte[5];
> byte[] incoming = new byte[DATA_SIZE+1];
> /**
> * Called every time a connection with IOIO has been
> established.
> * Typically used to open pins.
> *
> *
> * @throws ConnectionLostException
> * When IOIO connection is lost.
> *
> * @see ioio.lib.util.IOIOLooper#setup()
> */
> @Override
> protected void setup() throws ConnectionLostException {
> showVersions(ioio_, "IOIO connected!");
>
> //Lite the LED
> led_ = ioio_.openDigitalOutput(0, true);
>
> //open SPI Master here
> //SPI = ioio_.openSpiMaster(MISO_,MOSI
> _,CLCK_,SS_PINS,SpiMaster.Rate.RATE_4M);
> SPI = ioio_.openSpiMaster(new DigitalInput.Spec(MISO_,
> Mode.PULL_UP), new
> DigitalOutput.Spec(MOSI_),
> new DigitalOutput.Spec(CLCK_),
> new DigitalOutput.Spec[] { new
> DigitalOutput.Spec(SS_PINS[0]) },
> new SpiMaster.Config(SpiMaster.Rate.RATE_125K,
> true, true));
>
>
> request = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05 };
> enableUi(true);
>
> if(button_.isChecked()){
> //led_.write(!button_.isChecked());
> //just read from slave on pin 45
> try{
> SPI.writeRead(slaves[0],request,
> request.length,1, response, response.length);
> }
> catch (ConnectionLostException e) {
> e.printStackTrace();
> }
> catch (InterruptedException e) {
> e.printStackTrace();
> }
> incoming[request[0]] = response[0];
> }
> }
>
> /**
> * Called repetitively while the IOIO is connected.
> *
> * @throws ConnectionLostException
> * When IOIO connection is lost.
> * @throws InterruptedException
> * When the IOIO thread has been interrupted.
> *
> * @see ioio.lib.util.IOIOLooper#loop()
> */
> @Override
> public void loop() throws ConnectionLostException,
> InterruptedException {
>
> try {
> led_.write(false);
> Thread.sleep(100);
> led_.write(true);
> Thread.sleep(100);
> if(button_.isChecked()){
> led_.write(true);
> //just read from slave on pin 45
> try{
> SPI.writeRead(slaves[0],request,
> request.length,1, response, response.length);
> }
> catch (ConnectionLostException e) {
> e.printStackTrace();
> }
> catch (InterruptedException e) {
> e.printStackTrace();
> }
> incoming[request[0]] = response[0];
> }
> }
> catch (InterruptedException e) {
> }
> }
>
> /**
> * Called when the IOIO is disconnected.
> *
> * @see ioio.lib.util.IOIOLooper#disconnected()
> */
> @Override
> public void disconnected() {
> enableUi(false);
> toast("IOIO disconnected");
> }
>
> /**
> * Called when the IOIO is connected, but has an incompatible
> firmware version.
> *
> * @see ioio.lib.util.IOIOLooper#incompatible(IOIO)
> */
> @Override
> public void incompatible() {
> showVersions(ioio_, "Incompatible firmware version!");
> }
> }
>
> I would like to know the whether writeread is a blocking function call or
> not.
> Is there any way to test the working of SPI master with out slave.
> Something like using Oscilloscope.
>
>
> Thanks in advance
>
> --
> You received this message because you are subscribed to the Google Groups
> "ioio-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/ioio-users.
> For more options, visit https://groups.google.com/d/optout.
>
--
You received this message because you are subscribed to the Google Groups
"ioio-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/ioio-users.
For more options, visit https://groups.google.com/d/optout.