Go Down

Topic: How to use the SPI on the Zero (Read 93 times) previous topic - next topic

pedrohenriquefguerra

Hi,

I'm trying to connect my zero to a memory using the spi interface. I saw that I can't use the pins 10, 11, 12 and 13 like i used to do with the Uno board. I was wondering if someone could explain how to use the SPI interface on the Zero.

Thanks.

sandeepmistry

Hi @pedrohenriquefguerra,

You'll have to use the pins on the ICSP header for SPI, as mentioned on the product page https://www.arduino.cc/en/Main/ArduinoBoardZero

A diagram of the header pin layout can be found here:

You can continue to use pin 10 for SS.

pedrohenriquefguerra

Hi @sandeepmistry,

Thank you for your quick response, but i have another question.
Which pin I need to define for MISO, MOSI and SCK?

I found this in variants.cpp:

        |SPI (Legacy ICSP) |                   
 22  | 1                       |  PA12  | MISO    | EIC/EXTINT[12] SERCOM2/PAD[0] *SERCOM4/PAD[0] TCC2/WO[0] TCC0/WO[6]
        | 2                       |           | 5V0      |
 23  | 4                       |  PB10  | MOSI    | EIC/EXTINT[10]                *SERCOM4/PAD[2] TC5/WO[0]  TCC0/WO[4]
 24  | 3                       |  PB11  | SCK      | EIC/EXTINT[11]                *SERCOM4/PAD[3] TC5/WO[1]  TCC0/WO[5]
        | 5                       |           | RESET   |
        | 6                       |           | GND     

and I used this code to check with an oscilloscope the signals:

#include <SPI.h>

#define DATAOUT 23//MOSI
#define DATAIN  22//MISO
#define SPICLOCK  24//sck
#define SLAVESELECT 10//ss

void setup()

   
  pinMode(DATAOUT, OUTPUT);
  pinMode(DATAIN, INPUT);
  pinMode(SPICLOCK,OUTPUT);
  pinMode(SLAVESELECT,OUTPUT);
  delay(10);
 
  SPI.beginTransaction(SPISettings(3000000, MSBFIRST, SPI_MODE3));
  digitalWrite(SLAVESELECT,HIGH); //release chip
}

void loop()
{   
  digitalWrite(SLAVESELECT, LOW);
  SPI.transfer(0b00000110);  //write enable
  digitalWrite(SLAVESELECT, HIGH);
  //delay(1);
  digitalWrite(SLAVESELECT, LOW);
  SPI.transfer(0b00000010); //write command
 
  // Transfer memory address
  SPI.transfer(0b00000000);
  SPI.transfer(0b00000000);
  SPI.transfer(0b00000000);

  // Transfer value (byte)
  SPI.transfer(0b01010101);
  SPI.transfer(0b01010101);
  SPI.transfer(0b11110000);
  SPI.transfer(0b00001111);
 
  digitalWrite(SLAVESELECT,HIGH);
  //delay(1);
  //SPI.endTransaction();   
}


but i'm only able to see the slave select, do you have any idea why?

Thanks.

sandeepmistry

The following is not needed:

Code: [Select]

  pinMode(DATAOUT, OUTPUT);
  pinMode(DATAIN, INPUT);
  pinMode(SPICLOCK,OUTPUT);


As the SPI library will set this up for you, if you call "SPI.begin()" instead :)

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy