0% found this document useful (0 votes)
95 views

SPI - 595 Arduino Sketch

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)
95 views

SPI - 595 Arduino Sketch

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
You are on page 1/ 1

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

ino mercoledì 3 gennaio 2018 23:40


// https://www.gammon.com.au/forum/?id=11518
// 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
SPI.begin ();
// below settings reccomended for IDE 1.6.0 and above
SPI.beginTransaction (SPISettings (4000000, MSBFIRST, SPI_MODE0)); // 4 MHz clock, MSB
first, Mode 0
//Serial.begin(115200);
/*
sei(); // Enables Global Interrupts
SPCR |= (1<<SPIE); // sets SPI Interrupt Enable bit
*/
//SPI.attachInterrupt();
} // 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
SPI.transfer (c);
PORTB |= (1<<PB2); // puts SS pin 10 HIGH
//digitalWrite (LATCH, HIGH);
//Serial.println(c);
delay (1000);
} // end of loop

-1-

You might also like