If you have arrived at this article by random means and not via its starting point, then you may find that it may not make much sense. This is because this article is one of several (six) tutorials to aid and assist in understanding the use of the ez_SIPO8_lib
library in managing and controlling Serial-in/Parallel-out ICs (SIPOs) shift registers, for example 74HC595 chips.
If you wish to link to the start of the tutorial then please follow this link (Tutorial Start), otherwise, please read on...
A tutorial to consolidate understanding and use of the ez Serial-in/Parallel-out IC Library (ez_SIPO8_lib
) - Tutorial 1, Absolute Addressing. If you wish to link to the tutorial starting article then follow this link: Tutorial Start.
You can access and download the User Guide, Crib Sheet and the original ez_SIPO8_lib
article by following these links below:
- ez_SIPO8_lib
User Guide
- ez_SIPO8_lib
Crib Sheet
- Read the full ez_SIPO8_lib
article
Introduction to the TutorialIn this first tutorial we will look at configuring and driving a single 8-bit SIPO IC, the 74HC595 IC, which provides us with eight outputs to which we will connect LEDs, one to each SIPO IC output pin.
ObjectivesWe shall concern ourselves with creating a virtual software SIPO environment in which we can apply some basic principles, starting small. In particular we shall learn:
1. how we can wire up and connect a single 74HC595 IC (SIPO IC) to a microcontroller
2. the structure of an Arduino sketch suitably configured to drive the physically connected SIPO IC and its LEDs, in particular:
a. how to create a SIPO8 library class instance
b. how to create a SIPO bank from an array pool of SIPO output pins, thereby making the SIPO output pins individually addressable by software
c. how to use absolute SIPO output pin addressing at array level
3. witness the outputs of the sketch – shifting LED patterns and serial monitor SIPO data
Kit ListGather together the following components:
- 1 x Arduino UNO - The design uses an Arduino UNO, but any suitable microcontroller (Arduino or clone) will do, providing it is able to support the pin out requirements for driving the SIPO interface and power requirements
- 1 x Breadboard - Small or large, whatever you have to hand
- 1 x 74HC595 IC - 8bit SIPO IC, or other clone providing it is genuinely ‘plug-compatible’
- 8 x LEDs - Whatever you have around
- 8 x Resistors, 220 ohm - One per LED. Use 220 ohm resisters and ignore the suggested 180 ohm values in the wiring diagrams
- Connecting wires - Short/long or breadboard wire connectors, whatever suits
Which end is which? Well, notice that the 74HC595 has a notch at one end, here at the top of the diagram. Pin numbering starts at 1 at the top left and continues down the left hand side and the around the bottom of the IC rising to the top right hand side to pin 16:
Every bank of SIPO ICs you connect to the microcontroller requires a 3-wire digital interface (3WI). As this tutorial concerns a single SIPO IC then we shall only need one x 3WI. The table below suggests pin mapping between the microcontroller and the SIPO IC for this tutorial, but you may choose what microcontroller digital pins you wish. If you do choose different pins then be sure to alter the sketch function create_bank
call in setup()
.
- UNO pin 8 to SIPO pin 14 - SIPO Data Pin
- UNO pin 9 to SIPO pin 12 - SIPO Latch Pin
- UNO pin 10 to SIPO pin 11 - SIPO Clock Pin
- UNO pin +5v to SIPO pins 10, 16 - Power to the SIPO
- UNO GND pin to SIPO pins 8, 13 - Return ground (0v)
Using the following diagram, wire up all of the components, taking care to get the output/input connections correct:
Notice that the only 74HC595 IC pin not to have anything connected is pin 9, QH’. This is used as the serial output pin to connect to the serial input pin, 14 SER, of the next SIPO 74HC595 in a cascade which we shall be dealing with in a later tutorial.
The Code/SketchNow that is done, let’s look at a simple sketch to play around with the 75HC595. This sketch will create a single SIPO IC bank of output pins, these having absolute virtual addresses from 0 to 7, once the bank is created using the create_bank
function.
Using the Arduino IDE, start with a new sketch and download the tutorial sketch:
//
// Tutorial 1 - use of ez_SPI8 library
// Absolute addressing.
//
// Ron D Bentley, Stafford, UK
// April 2021
//
// This example and code is in the public domain and
// may be used without restriction and without warranty.
//
#include <ez_SIPO8_lib.h>
#define max_SIPOs 1 // one 1 SIPO for this tutorial
#define max_timers 0 // no timers required
// initiate the class for max SIPOs/timers required
SIPO8 my_SIPOs(max_SIPOs, max_timers);
int my_LEDs; // used to keep the SIPO bank id
void setup() {
Serial.begin(9600);
// create a bank of 1 SIPO using create_bank function:
// data pin, clock pin, latch pin, number of SIPO this bank
my_LEDs = my_SIPOs.create_bank(8, 10, 9, 1); // data pin, clock pin, latch pin, number of SIPO this bank
if (my_LEDs == create_bank_failure) {
Serial.println(F("\nfailed to create bank"));
Serial.flush();
exit(0);
}
// print the bank data for confirmation/inspection
my_SIPOs.print_SIPO_data();
}
void loop() {
// start by setting all SIPO outputs to low (off)
my_SIPOs.set_all_array_pins(LOW);
my_SIPOs.xfer_array(LSBFIRST);
do {
//
// assemble pattern 0b01010101 into the array
my_SIPOs.set_array_pin(0, HIGH);
my_SIPOs.set_array_pin(1, LOW);
my_SIPOs.set_array_pin(2, HIGH);
my_SIPOs.set_array_pin(3, LOW);
my_SIPOs.set_array_pin(4, HIGH);
my_SIPOs.set_array_pin(5, LOW);
my_SIPOs.set_array_pin(6, HIGH);
my_SIPOs.set_array_pin(7, LOW);
my_SIPOs.xfer_array(MSBFIRST); // now move array to physical SIPO and light up the LEDs
delay(500);
// assemble inverted pattern 0b10101010 into the array
my_SIPOs.set_array_pin(0, LOW);
my_SIPOs.set_array_pin(1, HIGH);
my_SIPOs.set_array_pin(2, LOW);
my_SIPOs.set_array_pin(3, HIGH);
my_SIPOs.set_array_pin(4, LOW);
my_SIPOs.set_array_pin(5, HIGH);
my_SIPOs.set_array_pin(6, LOW);
my_SIPOs.set_array_pin(7, HIGH);
my_SIPOs.xfer_array(MSBFIRST); // now move array to physical SIPO and light up the LEDs
delay(500);
} while (true);
}
Compile the sketch and upload. You should now see the LEDs ‘see-sawing’ back and forth with a small delay between cycles:
The sketch uses absolute addressing and the absolute addressing functions set_array_pin
and xfer_array
. We use the set_array_pin
function to set a specified array pin HIGH or LOW and the xfer_array
function to update the physical bank of SIPOs (here only one) once we have finished updating the virtual bit map array.
The pin address used by set_array_pin
is an absolute pin address, starting at 0. Any virtual active output pin may be referenced by its absolute address in the array pool. However, virtual output pins are only active when they are assigned to a bank via the create_bank
function – this brings them into ‘life’ in blocks of eight. The key point here is that the virtual array pool is not addressable until it is configured into one or more SIPO banks.
Note:
that absolute addressing is different to relative addressing which is covered in tutorial 2.
the significance of theMSBFIRST
parameter in the xfer calls and how the physical outputs reflect the virtual pin settings with this parameter. Discover what would happen if you change theMSBFIRST
parameter toLSBFIRST
in the twomy_SIPO.xfer_array
calls.
Finally, check the serial monitor, it should look like this:
SIPOglobal values:
pins_per_SIPO = 8
max_SIPOs = 1
bank_SIPO_count= 1
num_active_pins= 8
num_pin_status_bytes= 1
next_freebank = all SIPOs used
Number
Bank
bank
num SIPOs = 1
latch_pin = 9 clock_pin = 10 data_pin = 8
low_pin = 0 high_pin = 7
Note the helpful details that print_SIPO_data()
function can provide – very useful during development and debugging.
Have a play around varying SIPO output pins, for example use a for-loop for the pins to reduce the code a little, pick pins at random, etc; you will soon get the hang of things.
That is the end of Tutorial 1, a pdf version can be downloaded from github here.
If you are ready and wish to go on to the next tutorial then follow this link - Tutorial 2, Relative Addressing, but if you wish to link to the tutorial starting article then follow this link - Tutorial Start.
Comments
Please log in or sign up to comment.