Skip to content

Fundevoge/mcp23s17

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MCP23S17 driver

Crates.io Crates.io Crates.io

A driver for the MCP23S17 I/O expander which is accessed over an SPI bus.

Example usage

// spi implements the SPI traits from embedded_hal 
// cs_pin implements the OutputPin embedded_hal
// The hardware address corresponds to the way the pins A0, A1, A2 are physically connected
let mut mcp23s17 = mcp23s17::Mcp23s17::new(spi, cs_pin, 0b000).ok().unwrap();

// Configure pin GPA0 as an output
mcp23s17.pin_mode(0, mcp23s17::PinMode::Output).ok().unwrap();
// Set pin GPA0 high
mcp23s17.set_high(0);

// Configure pin GPA1 as an pullup input
mcp23s17.pin_mode(1, mcp23s17::PinMode::InputPullup).ok().unwrap();
// Read GPA1's level
let is_high = mcp23s17.read(1);

Acknowledgements

Many of the documentation comments in this library are taken direct from the MCP23S17 datasheet and are © 2005-2022 Microchip Technology Inc. and its subsidiaries.

Inspired by this Arduino MCP23S17 Library and the RPPAL MCP23S17 Library

About

A hardware-agnostic driver for the MCP23S17 I/O expander.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages