Meadow.Foundation.ICs.IOExpanders.x74595
x74595 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
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 ensure that the total output load of the chip does not exceed the current and thermal dissipation properties for the specific shift register being used.
Code Example
x74595 shiftRegister;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
shiftRegister = new x74595(Device.CreateSpiBus(), Device.Pins.D00, 8);
return base.Initialize();
}
public override async Task Run()
{
shiftRegister.Clear(true);
Resolver.Log.Info("Set Pin 3 to high");
//turn on pin 3
shiftRegister.WriteToPin(shiftRegister.Pins.GP3, true);
Resolver.Log.Info("Set Pin 4 to high");
//get the port for Pin4
var port4 = shiftRegister.CreateDigitalOutputPort(shiftRegister.Pins.GP4, true, Meadow.Hardware.OutputType.OpenDrain);
Resolver.Log.Info("Toggle pin 4");
await Task.Delay(1000);
port4.State = false;
await Task.Delay(1000);
port4.State = true;
await Task.Delay(1000);
Resolver.Log.Info("Raise all pins to high");
while (true)
{
shiftRegister.Clear();
foreach (var pin in shiftRegister.Pins.AllPins)
{
shiftRegister.WriteToPin(pin, true);
await Task.Delay(50);
}
}
}
Sample project(s) available on GitHub
Wiring Example
To wire a 74HCT595 to your Meadow board, connect the following:
Class x74595
Provide an interface to connect to a 74595 shift register
Assembly: x74595.dll
View Source
public class x74595 : IDigitalOutputController, IPinController, ISpiPeripheral
Implements:
Meadow.Hardware.IDigitalOutputController
, Meadow.Hardware.IPinController
, Meadow.Hardware.ISpiPeripheral
Properties
Pins
The pin definitions
View Source
public x74595.PinDefinitions Pins { get; }
DefaultSpiBusSpeed
The default SPI bus speed for the device
View Source
public Frequency DefaultSpiBusSpeed { get; }
SpiBusSpeed
The SPI bus speed for the device
View Source
public Frequency SpiBusSpeed { get; set; }
DefaultSpiBusMode
The default SPI bus mode for the device
View Source
public SpiClockConfiguration.Mode DefaultSpiBusMode { get; }
SpiBusMode
The SPI bus mode for the device
View Source
public SpiClockConfiguration.Mode SpiBusMode { get; set; }
Fields
spiComms
SPI Communication bus used to communicate with the peripheral
View Source
protected ISpiCommunications spiComms
Methods
CreateDigitalOutputPort(IPin, bool, OutputType)
Creates a new DigitalOutputPort using the specified pin and initial state
View Source
public IDigitalOutputPort CreateDigitalOutputPort(IPin pin, bool initialState, OutputType outputType)
Returns
Meadow.Hardware.IDigitalOutputPort
Parameters
Type | Name | Description |
---|---|---|
Meadow.Hardware.IPin | pin | The pin number to create the port on |
System.Boolean | initialState | Whether the pin is initially high or low |
Meadow.Hardware.OutputType | outputType | The port output type |
Clear(bool)
Clear the shift register buffer
View Source
public void Clear(bool update = true)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | update | If true, send changes to the shift register |
WriteToPin(IPin, bool)
Sets a particular pin's value.
View Source
public void WriteToPin(IPin pin, bool value)
Parameters
Type | Name | Description |
---|---|---|
Meadow.Hardware.IPin | pin | The pin to write to. |
System.Boolean | value | The value to write. True for high, false for low. |
IsValidPin(IPin)
Checks whether or not the pin passed in exists on the chip.
View Source
protected bool IsValidPin(IPin pin)
Returns
System.Boolean
Parameters
Type | Name |
---|---|
Meadow.Hardware.IPin | pin |
GetPin(string)
Get pin from name
View Source
public IPin GetPin(string pinName)
Returns
Meadow.Hardware.IPin
: An IPin object
Parameters
Type | Name | Description |
---|---|---|
System.String | pinName | The pin name |
Implements
Meadow.Hardware.IDigitalOutputController
Meadow.Hardware.IPinController
Meadow.Hardware.ISpiPeripheral