[solved]: Accessing the SPI headers from code

Discussion in 'Arduino IDE' started by alexandros301, Apr 30, 2014.

  1. alexandros301

    alexandros301 Member

    Joined:
    Mar 22, 2014
    Messages:
    40
    Likes Received:
    0
    Looking for the SPI pins on Udoo, I found this thread http://www.udoo.org/forum/board-connection-layout-t217.html and I can see that there's a four pin header just behind the USB ports where the MISO, MOSI and SPCK pins are. When coding in Arduino, how do I access those pins?
    For example, if I wanna do something similar to these tutorials, which use shift registers http://www.gammon.com.au/forum/?id=11979 http://www.gammon.com.au/forum/?id=11518, what numbers should I replace the MISO, MOSI, SCK and SS pins with?
     
  2. alexandros301

    alexandros301 Member

    Joined:
    Mar 22, 2014
    Messages:
    40
    Likes Received:
    0
    Re: Accessing the SPI headers from code

    Sorted it out. There's no need to access those specific pins from code, the SPI library does this for you (I guess). The only pin you need to access is the SS (Slave Select), which is either pin 10 or 4. But just by calling the SPI library, pin 10 works out of the box. So in code it goes like this

    Code:
    
    latchPin = 10; // set pin 10 as the SS pin (often called the latch pin with shift registers)
    byte outputData[numberOfChips]; // buffer to hold the data to be transferred to the shift registers
    
    // function to transfer bytes to the shift registers
    void refreshOutput()
    {
      digitalWrite(latchPin, LOW);
      for(int i = numOfOutputChips - 1; i >= 0; i--)
        SPI.transfer(outputData[i]);
      digitalWrite(latchPin, HIGH);
    }
    
    void setup()
    {
      SPI.begin() // you might want to set the SS pin here like this: SPI.begin(10), but it's not necessary if you're using only one SS (if I got it right)
      // the rest of your setup code
    }
    
    void loop()
    {
       //when you want to refresh your output, call the function
      refreshOutput();
    }
    
    You just need to make sure you connect the chip's pins to the correct pins on Udoo and that's it.
     
  3. udoo_usr

    udoo_usr New Member

    Joined:
    Aug 5, 2014
    Messages:
    2
    Likes Received:
    0
    alexandros301 - I found that the default location for the SDI and SCK (MOSI, SCK) are pin2 and pin3 on terminal block J20 on the UDOO board.
     
  4. alexandros301

    alexandros301 Member

    Joined:
    Mar 22, 2014
    Messages:
    40
    Likes Received:
    0
    Hi udoo_usr, thanks for your answer. I've already found the pins but there seems to be something strange with the output shift registers. There is a strange wrap around in the last bit which affects the first bit of the previous chip. It's a bit of a complicated situation, I've sent another message in the forum about that but got no answer...
    Also I get to much noise in the analog pins and can't seem to solve that either. I'll give Odroid with Teensy a shot and see if I get more luck there...
     

Share This Page