10 Replies Latest reply on Apr 24, 2015 5:33 PM by kyungmo.km.kim

    edison SPI not working after sleep()



      I'm trying to use ethernet shield via SPI on edison + Arduino breakout board with libmraa.


      When I initialize and access the chip's register, it works well.

      But if I spend some time and access the register, the shield doesn't respond and I have only zero'ed response.

      Any idea? or am I missing something?

      FYI, the image is edison-image-ww05-15.zip from intel's download link and mraa version is v0.5.2.


      The problem is:

      root@edison:~# ./show_spi_problem

      argc 1, mraa version v0.5.2

      ADDR          NAME VALUE

      ==== ============  =====

      0000                 Mode 0x00, 0

      001f              Version 0x03, 3

      0035           PHY Status 0x37, 55

      Sleeping 1 second...

      001f              Version 0x00, 0



      The code is:

      #include "libmraa.h"

      #include "stdio.h"

      #include "stdlib.h"

      #include "string.h"

      #include "ctype.h"

      #include <sys/socket.h>

      #include <netinet/in.h>

      #include <arpa/inet.h>


      int w5200ReadReg(mraa_spi_context spi, uint16_t addr, uint8_t *buf, int len)


          int r, i;

          r = mraa_spi_write(spi, (addr >> 8) & 0xff);

          r = mraa_spi_write(spi, addr & 0xff );

          r = mraa_spi_write(spi, 0x00);  // length

          r = mraa_spi_write(spi, len);  // length

          for (i=0; i<len; ++i) {

              buf[i] = mraa_spi_write(spi, 0x0);


          return len;



      void display_register_value(mraa_spi_context spi, char *name, int addr)


          uint8_t buf[16];

          int v = w5200ReadReg(spi, addr, buf, 1);

          fprintf(stdout, " %04x %20s 0x%02x, %d\n", addr, name, buf[0], buf[0]);



      int dump_registers(mraa_spi_context spi)


          fprintf(stdout, " ADDR %13s VALUE\n", "NAME");

          fprintf(stdout, " ==== ============  =====\n");

          display_register_value(spi, "Mode",       0x00);

          display_register_value(spi, "Version",    0x1f);

          display_register_value(spi, "PHY Status", 0x35);


          fprintf(stdout, " Sleeping 1 second...\n");


          display_register_value(spi, "Version",    0x1f);




      int main(int argc, char** argv)


          mraa_spi_context spi;

          int r = 0;


          printf("argc %d, mraa version %s\n", argc, mraa_get_version());



          spi = mraa_spi_init(0);

          r = mraa_spi_frequency(spi, 12500000);






          return MRAA_SUCCESS;