2 Replies Latest reply on Feb 1, 2017 4:07 PM by Intel Corporation

    When I initilize SPI_0 the onboard LED no longer blinks

    conor100

      Hi,

       

      The code below blinks the onboard led on the Edison board.

       

      Could somebody explain to me why when initialize SPI 0 (commented out in the code below) - the LED no longer blinks?

       

      Am I doing something stupid?

       

      Thanks

       

      #include <mraa.h>
      #include <stdio.h>
      #include <unistd.h>
      
      
      int main()
      {
          // select onboard LED pin based on the platform type
          // create a GPIO object from MRAA using it
          mraa_platform_t platform = mraa_get_platform_type();
          mraa_gpio_context d_pin = NULL;
          mraa_spi_context spi = NULL;
          switch (platform) {
              case MRAA_INTEL_GALILEO_GEN1:
                  d_pin = mraa_gpio_init_raw(3);
                  break;
              case MRAA_INTEL_GALILEO_GEN2:
                  d_pin = mraa_gpio_init(13);
                  break ;
              case MRAA_INTEL_EDISON_FAB_C:
                  d_pin = mraa_gpio_init(13);
      
      
                  /*
                  spi = mraa_spi_init(0);
                  if (spi == NULL) {
                      fputs("Unable to initialize SPI 0 interface\n", stderr);
                      return 1;
                  }
                  */
      
      
                  break;
              case MRAA_INTEL_GT_TUCHUCK:
                  d_pin = mraa_gpio_init(100);
                  break;
              default:
                  fprintf(stderr, "Unsupported platform, exiting");
                  return MRAA_ERROR_INVALID_PLATFORM;
          }
          if (d_pin == NULL) {
              fprintf(stderr, "MRAA couldn't initialize GPIO, exiting");
              return MRAA_ERROR_UNSPECIFIED;
          }
      
      
          // set the pin as output
          if (mraa_gpio_dir(d_pin, MRAA_GPIO_OUT) != MRAA_SUCCESS) {
              fprintf(stderr, "Can't set digital pin as output, exiting");
              return MRAA_ERROR_UNSPECIFIED;
          };
      
      
          // loop forever toggling the on board LED every second
          for (;;) {
              mraa_gpio_write(d_pin, 0);
              sleep(1);
              mraa_gpio_write(d_pin, 1);
              sleep(1);
          }
      
      
          return MRAA_SUCCESS;
      }