0% found this document useful (0 votes)
156 views1 page

Arduino SPI Tutorial

This document describes code for interfacing with a 74HC595 shift register using SPI communication on an Arduino. It defines the pin connections between the Arduino and 74HC595, initializes SPI communication at 4MHz, and uses a byte variable to incrementally shift bits out to the 74HC595 register on each loop iteration when the latch pin is pulsed low and high.

Uploaded by

Dado Gaudi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
156 views1 page

Arduino SPI Tutorial

This document describes code for interfacing with a 74HC595 shift register using SPI communication on an Arduino. It defines the pin connections between the Arduino and 74HC595, initializes SPI communication at 4MHz, and uses a byte variable to incrementally shift bits out to the 74HC595 register on each loop iteration when the latch pin is pulsed low and high.

Uploaded by

Dado Gaudi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

C:\Users\dntg\Documents\Arduino\spi_595\spi_595.

ino mercoledì 3 gennaio 2018 23:40


// [Link]
// code by Nick Gammon

// Connections for UNO and similar

// 595 Chip pin 14 Data (DS) goes to MOSI (pin 11)


// 595 Chip pin 11 Clock (SH) goes to SCK (pin 13)
// 595 Chip pin 12 Latch (ST) goes to SS (pin 10) (or any other pin by changing LATCH)

#include <SPI.h>

const int LATCH = 10; // Defines the LATCH on pin 10

void setup ()
{
//pinMode (LATCH, OUTPUT); // sets pin 10 as OUTPUT, since it plays the SS-Slave Select role
DDRB |= (1<<DDB2); // sets PB2, pin 10, as OUTPUT, since it plays the SS-Slave Select role
[Link] ();
// below settings reccomended for IDE 1.6.0 and above
[Link] (SPISettings (4000000, MSBFIRST, SPI_MODE0)); // 4 MHz clock, MSB
first, Mode 0
//[Link](115200);
/*
sei(); // Enables Global Interrupts
SPCR |= (1<<SPIE); // sets SPI Interrupt Enable bit
*/
//[Link]();
} // end of setup

byte c; // starts the counter at b00000000

// SPI interrupt routine


/*
ISR (SPI_STC_vect)
{
PORTB |= (1<<PB2); // puts SS pin 10 HIGH
}
*/

void loop ()
{
c++; // incremets the byte one bit at the time
//digitalWrite (LATCH, LOW);
PORTB &= ~(1<<PB2); // puts SS pin 10 LOW
[Link] (c);
PORTB |= (1<<PB2); // puts SS pin 10 HIGH
//digitalWrite (LATCH, HIGH);
//[Link](c);
delay (1000);
} // end of loop

-1-

You might also like