Bus Pirate Edu Kit Exercise no.2
From DP
Contents |
Overview
Taking it to the next step from exercise no.1, here we control 8 LEDs instead of one. Since the Bus Pirate is designed for serial protocols, controlling 8 pins is out of its scope. This exercise teaches how to use the 74HCT595 serial to parallel IC to implement parallel communications when needed.
The Bus Pirate sends bytes to the 74HCT595 over the serial SPI protocol. Once recived the bytes are forwarded to the 74HCT595's 8 output pins.
The Circuit
The 74HCT595 is shift register, meaning that you send it data bit by bit, and it shifts them through it's registrar byte. The outputs of singular bits within the byte are connected to pins, which makes it suitable for serial in to parallel out conversions.
In this exercise we connect the Bus Pirate to control the 74HCT595 through a serial protocol (SPI), and monitor all the output bits of the registrar with LEDs.
We used the HCT CMOS family 595 IC because it can accept a 3.3v interface even though it's powered through 5V. This is important because Bus Pirates IO interface is limited to 3.3 volts.
Breadboard legend
| IC Location | Breadboard wiring legend | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
- The (+) and (-) next to PIN1 and PIN2 are intended for devices such as LEDs, where PIN1 should be the anode and connected to a higher potential then PIN2.
Bus Pirate Terminal
Connect the Bus pirate and activate the terminal window. Here's a tutorial on how to connect the Bus Pirate, and activate the Terminal window, if you haven't already please check it out now.
HiZ>m<<<the mode command
1. HiZ
2. 1-WIRE
3. UART
4. I2C
5. SPI
6. 2WIRE
7. 3WIRE
8. LCD
x. exit(without change)
(1)>5<<<select SPI mode
Set speed:
1. 30KHz
2. 125KHz
3. 250KHz
4. 1MHz
(1)>2<<<select speed at 125 KHz
Clock polarity:
1. Idle low *default
2. Idle high
(1)>1<<<select Idle low clock polarity
Output clock edge:
1. Idle to active
2. Active to idle *default
(2)>2<<<select active to idle output clock edge
Input sample phase:
1. Middle *default
2. End
(1)>1<<<select middle Input sample phase
CS:
1. CS
2. /CS *default
(2)>2<<<select inverted CS
Select output type:
1. Open drain (H=Hi-Z, L=GND)
2. Normal (H=3.3V, L=GND)
(1)>2<<<select normal output type
Ready
First we'll enter and setup the SPI mode on the Bus Pirate as it's the one the '595 ICs use. Check out the wikipedia entry on the SPI protocol if you're interested in the ins and outs of it. You can also check out our Bus Pirate SPI guide here.
The speed is not that important on the '595 as it should support even the highest 1 MHz option. The other options are more important to get right. The '595 IC uses idle low clock polarity, active to idle clock triggering edge, output is sampled during the middle phase, the CS pin is inverted, and the '595 uses normal instead of open drain signaling. All of these options can be found in the 74HCT595 datasheet.
SPI>W<<<Turn ON power supplies command
POWER SUPPLIES ON
Since we'll be using the Bus Pirate 5v power supply to power the device, we need to switch the power supplies on with the 'W' command. This is it, the '595 is now ready to receive.
SPI>[0]<<<send 0 in decimal format
/CS ENABLED
WRITE: 0x00
/CS DISABLED
To send a byte to the '595 you need to write the byte withing '[' ']' parenthesis. The function of which is to bring the CS pin LOW ('[') at the start of transmission, and bring it HIGH at it's end.
The byte can be written in decimal (number between 0 and 255), in hexadecimal 0x(between 00 and FF), and binary 0b(between 0000000 and 11111111).
First we'll send 0 ([0]), which will set all of the '595's outputs to LOW thus turning all the LEDs off.
SPI>[0xFF]<<<send 255 in hexadecimal format
/CS ENABLED
WRITE: 0xFF
/CS DISABLED
Next we'll send [0xff] which should turn all the LEDs ON. You can send any byte you want, in any one of the above mentioned formats. Perhaps it's best to use the binary format, as it mimics the LED outputs exactly.
SPI>[0b10101010]<<<send 170 in binary format
/CS ENABLED
WRITE: 0xAA
/CS DISABLED
Here we use the binary format to send '10101010' to turn ON each odd LED.
SPI>m<<<mode change command
1. HiZ
2. 1-WIRE
3. UART
4. I2C
5. SPI
6. 2WIRE
7. 3WIRE
8. LCD
x. exit(without change)
(1)>1<<<select HiZ mode
Ready
HiZ>
Once you're done with the exercise you should place the Bus Pirate in High impedance mode (HiZ). This is done by sending the mode change command 'm', and selecting 'HiZ' from the menu.
Not Working?
- This exercise uses lots of wires, check if they are all connected properly.
- Still no luck, sometimes breadboards don't make a good connection, try moving some of the wires to a alternative bread board location, keep in the same row (number) but change the column (letter).
- If an LED is not lighting up when it should be, check that it is connected properly, the notch on the LED should be connected to GND.
- Off course if you are still having issues you are free to contact us through the contact form (please use "[BP_EK]" prefix), or through our support forum.
Taking it further
- Stringing 595s together.
