1 2 Previous Next 16 Replies Latest reply on Nov 11, 2015 3:55 PM by dmccoy

    Has *ANYONE* been able to get SPI bus working on Edison + Arduino board?

    TwistedTrasistor

      I am at my wits end.  !@$^!@$#%$!@%R!!!!

       

      Coding in C++ with Eclipse.

       

      Info:

      - The jumpers on my board are all set in their default positions.

      - The Edison has the latest image "configure_edison --version" gives me 159

      - "opkg list | grep libmraa0" gives me "libmraa0 - 0.7.3 - mraa built using CMake"

      - "opkg list | grep upm" gives me "upm - 0.3.2 - upm built using CMake"

      - Executed the commands in listing 1 below as per the Intel® Edison Kit for Arduino document on page 30 and 31

      - Executed the commands in listing 2 below as per the mraa 0.7.4 instructions at mraa: Intel Edison

      - My code in listing 3 is to connect to the AMIS-30543 Stepper Motor Driver Carrier (Pololu - AMIS-30543 Stepper Motor Driver Carrier)

      - Listing 4 shows  how I have the stepper motor driver connected to the Edison Arduino Kit board.

       

      When I execute my program, all I get is this:

      0: 0

      1: 128

      2: 128

      3: 128

       

      When I should be getting:

      0: 0

      1: 131

      2: 128

      3: 80

       

      I have already tried 2 different Edison modules and 2 different stepper motor drivers.  All give me the same results.

       

      Listing 1

      echo 111 > /sys/class/gpio/export

      echo 115 > /sys/class/gpio/export

      echo 114 > /sys/class/gpio/export

      echo 109 > /sys/class/gpio/export

      echo 263 > /sys/class/gpio/export

      echo 240 > /sys/class/gpio/export

      echo 262 > /sys/class/gpio/export

      echo 241 > /sys/class/gpio/export

      echo 242 > /sys/class/gpio/export

      echo 243 > /sys/class/gpio/export

      echo 258 > /sys/class/gpio/export

      echo 259 > /sys/class/gpio/export

      echo 260 > /sys/class/gpio/export

      echo 261 > /sys/class/gpio/export

      echo 226 > /sys/class/gpio/export

      echo 227 > /sys/class/gpio/export

      echo 228 > /sys/class/gpio/export

      echo 229 > /sys/class/gpio/export

      echo 214 > /sys/class/gpio/export

      echo low > /sys/class/gpio/gpio214/direction

      echo high > /sys/class/gpio/gpio263/direction

      echo high > /sys/class/gpio/gpio240/direction

      echo high > /sys/class/gpio/gpio262/direction

      echo high > /sys/class/gpio/gpio241/direction

      echo high > /sys/class/gpio/gpio242/direction

      echo high > /sys/class/gpio/gpio243/direction

      echo high > /sys/class/gpio/gpio258/direction

      echo high > /sys/class/gpio/gpio259/direction

      echo low > /sys/class/gpio/gpio260/direction

      echo high > /sys/class/gpio/gpio261/direction

      echo in > /sys/class/gpio/gpio226/direction

      echo in > /sys/class/gpio/gpio227/direction

      echo in > /sys/class/gpio/gpio228/direction

      echo in > /sys/class/gpio/gpio229/direction

      echo mode1 > /sys/kernel/debug/gpio_debug/gpio111/current_pinmux

      echo mode1 > /sys/kernel/debug/gpio_debug/gpio115/current_pinmux

      echo mode1 > /sys/kernel/debug/gpio_debug/gpio114/current_pinmux

      echo mode1 > /sys/kernel/debug/gpio_debug/gpio109/current_pinmux

      echo high > /sys/class/gpio/gpio214/direction

       

      Listing 2

      # echo on > /sys/devices/pci0000\:00/0000\:00\:07.1/power/control

      # cat /sys/devices/pci0000\:00/0000\:00\:07.1/power/control

      on

      Listing 3

      #include "mraa.hpp"

      #include <iostream>

      #include <unistd.h>

       

      using namespace std;

       

      #define CLK 13

      #define MISO 12

      #define MOSI 11

      #define CS 10

       

      int main(int argc, char** argv) {

      mraa::Spi* spi = new mraa::Spi(0);

      if (spi == NULL) {

      cout << "Error 1" << endl;

      }

       

      spi->mode(mraa::SPI_MODE0);

      spi->lsbmode(false);

      spi->frequency(100000); /* I tried with 500000 and 250000 too */

      uint8_t txBuf1[] = {0x83, 0x80};

      uint8_t* rxBuf = spi->write(txBuf1, 2);

      cout << "0: " << (int)rxBuf[0] << endl;

      cout << "1: " << (int)rxBuf[1] << endl;

       

      cout << endl;

       

      uint8_t txBuf2[] = {0x03, 0x00};

      rxBuf = spi->write(txBuf2, 2);

      cout << "2: " << (int)rxBuf[0] << endl;

      cout << "3: " << (int)rxBuf[1] << endl;

       

      if (spi) delete spi;

       

      return MRAA_SUCCESS;

      }

       

      Listing 4:
      Edison Pin                  Driver Pin

      13 (CLK)                     CLK

      12 (MISO)                   DO

      11 (MOSI)                   DI

      10 (CS)                       /CS

      GND                          GND on side 1 and 2 of the driver (it has 2 GND that must be tied together) and connected to external 12V DC supply's ground too.

      +5V                            IOREF

                                        MOTV -> connected to external 12V DC supply

                                        Other 4 wires connected to motors

                                        /ERR connected to an LED and it does not indcate any errors

       

      As I said, the output of the program is always the same.  I also tried to drive the driver's /CS pin with a GPIO pin from the Edison and again, nothing.

       

      I have yet to find a client for my Bus Pirate that I can run without any errors (Windows 8 64).

       

       

      Can someone please, pretty please! help me?!!

        • 1. Re: Has *ANYONE* been able to get SPI bus working on Edison + Arduino board?
          CMata_Intel

          Hi,

           

          Do you have a logic analyzer? We could veirfy if the write function is working as it should by checking the MOSI and MISO lines.

          You can also try with the function transfer in MRAA. Also, update the MRAA library to the 0.7.4 version and let us know if you get improvements with this.

           

          Regards,

          Charlie

          • 2. Re: Has *ANYONE* been able to get SPI bus working on Edison + Arduino board?
            TwistedTrasistor

            Hi Charlie

             

            I have a bus pirate, but I haven't been able to get it working yet.

             

            I got the same results using the mraa c library.

            How do I update to 0.7.4?  When I run opkg install libmraa0 it tells me it is up to date.

            • 3. Re: Has *ANYONE* been able to get SPI bus working on Edison + Arduino board?
              CMata_Intel

              Hi,

               

              You have to run the commands:

              opkg update

              opkg install libmraa0

               

              Regards,

              Charlie

              • 4. Re: Has *ANYONE* been able to get SPI bus working on Edison + Arduino board?
                jhane

                Hello,

                   I did get this working on the older 2.0 release.   We connected up a sparkfun 1053 audio board and I used the mraa C library.  I don't really remember the details at this point but I do know I had to hook up a logic analyzer to see what was going on.

                 

                Jeff

                • 5. Re: Has *ANYONE* been able to get SPI bus working on Edison + Arduino board?
                  TwistedTrasistor

                  Hi jhane,

                   

                  I have had some success.

                   

                  My Arduino code works, flawlessly.  My C/C++ code, which does the exact same thing, 1/2 works.  Because I do not have a logic analyzer, at this point I am not able to determine if the issue is in hardware of software.

                   

                  Basically, here's what happens: To write to my SPI registers, I have to send it a command byte, followed by a data byte, both 8 bits, MSB first.  The 3 MSB bits of the command byte, are the Read/Write part of the command, the other 5 bits is the register address.  So to write 0b10101010 to register 0x01, I have to:


                  spi->write 0b10000001

                  then spi->write 0b10101010

                   

                  The write works, and I can confirm that because the device behaves as expected when that command is issued.

                   

                  To read a register, in this case register 0x01, the MSB of the first byte needs to be 0, so:

                   

                  spi->write 0b00000001

                  then spi->write 0b00000000  <= this is a dumy byte, just to shift out the register contents, which is the register's data.

                   

                  The problem is that reading the register's data, returns me bogus data, or 0x00000000 or 0x11111111.

                   

                  In addition to all of this, if I power off the Edison and the spi device, since all of the spi device's registers get cleared to 0x00 on startup, no matter what I do, I cannot get it to work using the C version of the code or the C++ version of the code.

                   

                  The Arduino code, which does the exact same thing, writes to 0x10101010 to 0x01 and reads the contents from 0x01, works flawlessly, and everytime, even if the Edison + the device have been powered down and back on.

                   

                  The only way I can get my C or C++ code to work is to first execute the arduino code, then the C/C++ code.  However, no mater what, reading in C/C++, does not work at all.

                   

                  Here is the C++ code:

                   

                  /*

                  *  Begin C++ Code

                  */

                  #include "Uart.hpp"

                  #include <iostream>

                  #include <signal.h>

                   

                  using namespace std;

                   

                  int main(int argc, char** argv)

                  {

                    signal(SIGINT, my_handler);

                    mraa::Spi* spi = new mraa::Spi(0);

                   

                    // the device doc says the master MUST use SPI MODE 0

                    spi->mode(mraa::SPI_MODE0);

                   

                    // the code behaves exactly the same what regardless of what the frequency is set here.

                    spi->frequency(250000);

                   

                    // MSB First

                    spi->lsbmode(false);

                   

                    uint8_t t[2];

                    uint8_t* r;

                   

                    // write to register 0x01

                    t[0] = 0b10000001; t[1] = 0b11110010;

                    spi->write(t, sizeof(t));

                   

                    // Delay a bit just to make sure the device has had time to do it's thing.

                    // Theoreticall not needed, but who know...

                    sleep(1);

                   

                    // read from register 0x01

                    t[0] = 0x01; t[1] = 0; r = spi->write(t, sizeof(t));

                    cout << "CR0: " << r[1] << endl;

                   

                    if (spi) delete spi;

                   

                    return MRAA_SUCCESS;

                  }

                  /*

                  * End C++ code

                  */

                   

                  And here is the Arduino code (which is a LOT slower than the C/C++ code):

                   

                  /*

                  * Begin Arduino code

                  */

                  #include "SPI.h"

                   

                  #define CLK 13

                  #define MISO 12

                  #define MOSI 11

                  #define CS 10


                  void setup()

                  {

                    pinMode(CLK, OUTPUT);

                    pinMode(MISO, INPUT);

                    pinMode(MOSI, OUTPUT);

                    pinMode(CS, OUTPUT);

                   

                    Serial.begin(115200);

                    SPI.begin();

                    SPI.setBitOrder(MSBFIRST);

                    SPI.setDataMode(SPI_MODE0);

                    SPI.setClockDivider(SPI_CLOCK_DIV2);

                    digitalWrite(SS, HIGH);

                    digitalWrite(NXT, LOW);

                  }

                   

                   

                  uint8_t val;

                   

                  void loop()

                  {

                    digitalWrite(SS, LOW);

                    delay(10);

                    SPI.transfer(0b10000001);

                    SPI.transfer(0b10101010);

                    digitalWrite(SS, HIGH);

                    delay(10);

                   

                    digitalWrite(SS, LOW);

                    delay(10);

                    SPI.transfer(0b00000001);

                    val = SPI.transfer(0b00000000);

                    delay(10);

                    digitalWrite(SS, HIGH);

                    delay(10);

                    Serial.println(val, BIN);


                    exit(0);

                  }


                  /*

                  * End Arduino code

                  */


                  The C++ code did not work properly when I tried using bit banging the SPI stuff either.


                  I'm completely baffled about what is wrong.  To rule out faulty hardware, I have tried 2 different Edison modules, 2 different Arduino boards, and 2 different SPI devices and it they all behave exactly the same.


                  • 6. Re: Has *ANYONE* been able to get SPI bus working on Edison + Arduino board?
                    Axis-Robotics

                    I've gone through the same thing as you guys have and SPI still does not work. I'm going to find a logic analyzer and see what is going on.

                     

                    Dave

                    • 7. Re: Has *ANYONE* been able to get SPI bus working on Edison + Arduino board?
                      CMata_Intel

                      Hi,

                       

                      Do you have updates in this?

                      Have you been able to use the bus pirate? I think it would help us to see what and how are you writing for example if you need to speed up the packages you are sending or if the problem is the CS pin or the SCK. Have you tried with different frequencies? Also I've seen the workaround of downgrade the image version in the board

                       

                      Regards,

                      Charlie

                      • 8. Re: Has *ANYONE* been able to get SPI bus working on Edison + Arduino board?
                        TwistedTrasistor

                        Hi Charlie,

                         

                        No, nothing new.  The bus pirate has been of no help.  I have not been able to get it to capture anything useful while connecting it to the Edison's SPI pins.

                        • 9. Re: Has *ANYONE* been able to get SPI bus working on Edison + Arduino board?
                          Axis-Robotics

                          Just got a "SPI-like" protocol up and running in nodejs to control the WS2801 pixel strip. It's not exactly SPI, but uses mraa in the same way so I know it does work.

                           

                          Dave

                          • 10. Re: Has *ANYONE* been able to get SPI bus working on Edison + Arduino board?
                            TwistedTrasistor

                            Yeah, I can get bit banging working too, but I don't need a $50 MCU to do that

                            • 11. Re: Has *ANYONE* been able to get SPI bus working on Edison + Arduino board?
                              CMata_Intel

                              Hi TwistedTrasistor

                               

                              Unfortunately, if there isn't a way to test the signals of the SPI interface it is really hard to detect where the problem is, as I said in my post above this could help us to see  "how are you writing data, if you need to speed up the packages you are sending or if the problem is the CS pin or the SCK" it also could include variables like noise, the shield you are using and others.

                              If the shield+code are working with another board like Arduino it doesn't mean that both will work with the Edison, as you know all the boards are different and use different libraries and resources so at the end you will need different codes and libraries to make a shield work.

                               

                              Regards,

                              Charlie

                              • 12. Re: Has *ANYONE* been able to get SPI bus working on Edison + Arduino board?
                                TwistedTrasistor

                                Hi CMata_Intel,

                                 

                                You misunderstood what I said.

                                 

                                I didn't run that code in the arduino.  My setup is 1 Intel Edison + 1 Arduino Breakout Board (the one you attached the Edison into it) + 1 AMIS30543 (the SPI chip).

                                 

                                I tried 2 different Edisons, 2 different Intel Edison Arduino Breakout Boards and 2 different AMISW30543 chips.

                                 

                                In all permutations of that setup, the hardware, using the same code, behaves the same way.

                                 

                                The only thing that worked, was programming the Edison to control the AMIS30543 using the Arduino compiler (for the Intel Edison).  The C/C++ code that does the same exact thing as the Arduino code, does not work.

                                 

                                You can see Arduino and the C/C++ code used above.

                                 

                                Again, I did not use an Arduino, I used an Intel Edison on an Intel Edison Arduino breakout board.

                                • 13. Re: Has *ANYONE* been able to get SPI bus working on Edison + Arduino board?
                                  CMata_Intel

                                  Hi,

                                   

                                  I apologize for the misunderstanding, I was trying to say that if you try to test this with an Arduino or another board and if it works this doesn't mean that using the same code and libraries it will work in the other boards like the Edison.

                                  Unfortunately, I don't have an AMIS30543 available to test your configuration and code.

                                   

                                  -Charlie

                                  • 14. Re: Has *ANYONE* been able to get SPI bus working on Edison + Arduino board?
                                    LeonY

                                    Hey TwistedTrasistor

                                    When you compile your code in C++, set the SPI frequency to 25khz or lower and try it out again. If you have the latest firmware on your edison, the spi driver has been restricted to 25khz and under..

                                    1 2 Previous Next