SPI on Arduino not working? [solved]

Discussion in 'Arduino IDE' started by frankalicious, Jan 12, 2014.

  1. frankalicious

    frankalicious New Member

    Joined:
    Nov 1, 2013
    Messages:
    3
    Likes Received:
    0
    Hi there,

    has anybody SPI working on the arduino?

    I attached a logic analyzer to the connector J20 (MOSI J20.2, SCK J20.3, GND J20.4).
    This example code does not seem seem to work.

    Code:
    #include <SPI.h>
    
    void setup() {
      SPI.begin();
      SPI.setBitOrder(MSBFIRST);
      SPI.setDataMode(SPI_MODE0);
      SPI.setClockDivider(42);
    }
    
    void loop() {
      delay(100);
      SPI.transfer(0xAA);
      delay(100);
      SPI.transfer(0xFF);
    }
    
    According to http://21stdigitalhome.blogspot.de/2013/02/arduino-due-hardware-spi.html MOSI should be digital pin number 75 and SCK should be pin number 76.
    When I toggle the MOSI and SCK pins via digital out I can see the changes in my logic analyzer. So the hardware connection seems to be OK.
    Code:
    #define TEST_MOSI 75
    #define TEST_CLK 76
    
    void setup() {
      pinMode(TEST_MOSI, OUTPUT);
      pinMode(TEST_CLK, OUTPUT);
    }
    
    void loop() {
      delay(100);
      digitalWrite(TEST_MOSI, 0);
      digitalWrite(TEST_CLK, 0);
      delay(100);
      digitalWrite(TEST_MOSI, 1);
      digitalWrite(TEST_CLK, 1);
    }
    
    Anybody an idea?

    Thanks,
    frankalicious
     
  2. frankalicious

    frankalicious New Member

    Joined:
    Nov 1, 2013
    Messages:
    3
    Likes Received:
    0
    Re: SPI on Arduino not working?

    Silly me.
    I thought I see spikes on the logic analyzer but after zooming in I can see the expected data.
     

Share This Page