Characteristic Locus
Inheritance System.Object > x74595
Inherited Members System.Object.ToString() System.Object.Equals(System.Object) System.Object.Equals(System.Object, System.Object) System.Object.ReferenceEquals(System.Object, System.Object) System.Object.GetHashCode() System.Object.GetType() System.Object.MemberwiseClone()
Namespace Meadow.Foundation.ICs.IOExpanders
Assembly x74595.dll

Syntax

public class x74595

Remarks

Shift registers offer the ability to increase the number of outputs on a microcontroller by using I2C or SPI interfaces. In the case of the 74xx595 series of shift registers, the SPI interface is used to output a series of bits that are then latched to the output pins of the chip.

This class allows Meadow to control the output pins on a 74HCT595 shift register using the SPI interface.

Note that when using this chip care should be taken to make sure that the total output load of the chip does not exceed the current and thermal dissipation properties for the specific shift register being used.

Examples

The application below uses a ShiftRegister74595 object to cycle through the bits on the shift register and light the appropriate LED.

using System.Threading;
using Meadow;
using Meadow.Foundation.ICs.IOExpanders;

namespace x74595_Sample
{
    public class Program
    {
        static IApp _app; 
        public static void Main()
        {
            _app = new App();
        }
    }

    public class App : AppBase<F7Micro, App>
    {
        public App ()
        {
            var config = new SPI.Configuration(SPI_mod: SPI_Devices.SPI1,
                                             ChipSelect_Port: Pins.GPIO_PIN_D8,
                                             ChipSelect_ActiveState: false,
                                             ChipSelect_SetupTime: 0,
                                             ChipSelect_HoldTime: 0,
                                             Clock_IdleState: true,
                                             Clock_Edge: true,
                                             Clock_RateKHz: 10);

           shiftRegister = new x74595(8, config);
           shiftRegister.Clear(true);

           int index = 0;
           while (true)
           {
               shiftRegister[index] = true;
               Thread.Sleep(500);
               shiftRegister[index] = false;
               index = index == 8 ? 0 : index + 1;
           }
        }
    }
}
Example Circuit

Constructors

View Source

x74595(ISpiBus, Int32)

Constructor a ShiftRegister74595 object.

Declaration
public x74595(ISpiBus spiBus, int pins)

Parameters

Type Name Description
ISpiBus spiBus

SpiBus object

System.Int32 pins

Number of pins in the shift register (should be a multiple of 8 pins).

Properties

View Source

Item[Int32]

Overload the index operator to allow the user to get/set a particular pin in the shift register.

Declaration
public bool this[int pin] { get; set; }

Parameters

Type Name Description
System.Int32 pin

Bit number to get/set.

Property Value

Type Description
System.Boolean

Value in the specified pin.

Methods

View Source

Clear(Boolean)

Clear all of the pins in the shift register.

Declaration
public void Clear(bool latch = false)

Parameters

Type Name Description
System.Boolean latch

If true, latch the data after the shift register is cleared (default is false)?

View Source

CreateOutputPort(IIODevice, IPin, Boolean)

Creates a new DigitalOutputPort using the specified pin and initial state.

Declaration
public IDigitalOutputPort CreateOutputPort(IIODevice device, IPin pin, bool initialState)

Parameters

Type Name Description
IIODevice device
IPin pin

The pin number to create the port on.

System.Boolean initialState

Whether the pin is initially high or low.

Returns

Type Description
IDigitalOutputPort
View Source

IsValidPin(Byte)

Check if the specified pin is valid.

Declaration
protected bool IsValidPin(byte pin)

Parameters

Type Name Description
System.Byte pin

Pin number

Returns

Type Description
System.Boolean

True if the pin number is valid, false if it not.

View Source

LatchData()

Send the data to the SPI interface.

Declaration
protected void LatchData()
View Source

WriteToPort(Byte, Boolean)

Sets a particular pin's value.

Declaration
public void WriteToPort(byte pin, bool value)

Parameters

Type Name Description
System.Byte pin

The pin to write to.

System.Boolean value

The value to write. True for high, false for low.

View Source

WriteToPorts(Byte)

Outputs a byte value across all of the pins by writing directly to the shift register.

Declaration
public void WriteToPorts(byte mask)

Parameters

Type Name Description
System.Byte mask