3 Replies Latest reply on May 28, 2015 4:26 PM by CMata_Intel

    Intel Edison SPI delay

    Nicobari

      Hi,

      So I finally got the SPI working on Intel Edison. The code is show below

      #include "mraa.hpp"
      
      #include <iostream>
      #include <unistd.h>
      
      int main() {
      
      
          mraa::Gpio* ledOut = new mraa::Gpio(48, true, false);
      
      
          if (ledOut->dir(mraa::DIR_OUT) != MRAA_SUCCESS) {
              std::cerr << "Can't set digital pin as output, exiting" << std::endl;
              return MRAA_ERROR_UNSPECIFIED;
          }
          mraa_gpio_context gpio;
          gpio = mraa_gpio_init(23);
      
          mraa_gpio_use_mmaped(gpio, 1);
      
          mraa::Spi* IMU = new mraa::Spi(0);
          if (IMU->mode(mraa::SPI_MODE3) != MRAA_SUCCESS
                  || IMU->bitPerWord(16) != MRAA_SUCCESS
                  || IMU->frequency(1000000) != MRAA_SUCCESS) {
      
              std::cerr << "Can't set SPI 0" << std::endl;
              return MRAA_ERROR_UNSPECIFIED;
          }
      
          static uint8_t SPI_command[] = { 0x00, 0x26 };
      
          uint8_t* rcvBuf;
          ledOut->write(1);
      
          while (1) {
      
      
              mraa_gpio_write(gpio, 0);
              rcvBuf=IMU->write(SPI_command, 2);
              mraa_gpio_write(gpio, 1);
      
              if(rcvBuf){
                  float Az = 0.00025 * (short int) (rcvBuf[1] * 256 + rcvBuf[0]);
                  printf("%g \n", Az);
              }
      
          }
      
          return MRAA_SUCCESS;
      }
      
      
      

       

      The code runs fine and prints data on Eclipse console. However I noticed that there is a huge delay (10s) between the time when the sensor is moved and when the change in printed data occurs on Eclipse console. I am not sure what else is wrong with the approach I am taking. Will appreciate any help regarding this matter.

       

      TM

        • 1. Re: Intel Edison SPI delay
          CMata_Intel

          Hi Nicobari

           

          I have a couple of questions:

          1. Which MRAA version are you using and which image version do you have in your board?

          2. Are you checking the signal in an oscilloscope or with a logic analyzer?

          3. Is the delay of 10s? And how are you testing this?

           

          The problem could be in the log of Eclipse you could be having some delays in there related to Eclipse and not with the port itself, are you sure you are not in debug mode?  Please let us know how are you testing this.

           

          Regards;

          CMata

          • 2. Re: Intel Edison SPI delay
            Nicobari

            Hi,

            1. I am using 0.6.0 version of MRAA in Eclipse (That is the default download from Intel Website) but I have 0.6.2 MRAA on the the Edison board. The image on board is 146 build version.

            2. I am checking the signal with a logic analyzer.

            3. It just a rough calculation, I moved my sensor and then timed when the reading on the Eclipse console window changes.

             

            Yeah I also thought that problem could be in Eclipse logging, I am using c/c++ perspective in Eclipse. When I ran the same code by going into Edison Console the delay was not significant (in the order of 1 second) which I am assuming is due to me printing the data on the screen at a very rapid speed (correct me if I am wrong). Do you think the SPI communication is happening at the right speed but the logging is slow, is there any other way in which I can do this?

             

            Thanks,

            Tanmay

             

            Any suggestions?

            • 3. Re: Intel Edison SPI delay
              CMata_Intel

              Hi Nicobari

               

              Yes, it could be related with this. Ten seconds is a considerable delay and in 10s you also could be losing data. The delay you are obtaining when you run the code in Terminal Console could be related to the printing data to the PC and not with the SPI bus itself.

              The best way to see if there is a delay in the communication would be connecting the board to another device capable to send an acknowledge signal to the board.

               

              Regards;

              CMata

              1 of 1 people found this helpful