mcp4x.h

Control functions for the MCP4x series of digitally controlled potentiometers.  Relies on the spihelper.h module.

NOTE: These functions do NOT manipulate any SPI Slave Select pins.  Application developers must ensure that the commands these functions transmit via the SPI peripheral reach the intended destination device.

NOTE: By default, these functions will use the asynchronous API of the SPI helper module (i.e.  spihelper_request), unless that API has been disabled.  To use the synchronous API (i.e.  spihelper_exchange_bytes) regardless of whether the asynchronous API is available, define the macro MCP4X_SYNCHRONOUS.

Summary
mcp4x.hControl functions for the MCP4x series of digitally controlled potentiometers.
Macros
MCP4X_P0Numeric identifier of the P0 potentiometer in an MCP4x device.
MCP4X_P1Numeric identifier of the P1 potentiometer in an MCP4x device.
Functions
mcp4x_set_wiperUpdates potentiometer wiper settings in the selected MCP4x device.
mcp4x_shutdownDisables potentiometers in the selected MCP4x device.

Macros

MCP4X_P0

Numeric identifier of the P0 potentiometer in an MCP4x device.  Constant macro.

MCP4X_P1

Numeric identifier of the P1 potentiometer in an MCP4x device.  Constant macro.

Functions

mcp4x_set_wiper

uint8_t mcp4x_set_wiper(uint8_t pot_bits,
uint8_t pos)

Updates potentiometer wiper settings in the selected MCP4x device.

Parameters

pot_bitsIdentifier of the target potentiometer(s) in the destination device.  Note that this is a bit mask, where the bit at position n is set in order to target potentiometer n (as identified by an MCP4X_P[n] constant).
posThe potentiometer wiper setting.

Returns

A true value if and only if the operation was successfully initiated (in asynchronous mode) or completed (in synchronous mode).

mcp4x_shutdown

uint8_t mcp4x_shutdown(uint8_t pot_bits)

Disables potentiometers in the selected MCP4x device.

Parameters

pot_bitsIdentifier of the target potentiometer(s) in the destination device.  Note that this is a bit mask, where the bit at position n is set in order to target potentiometer n (as identified by an MCP4X_P[n] constant).

Returns

A true value if and only if the operation was successfully initiated (in asynchronous mode) or completed (in synchronous mode).

uint8_t mcp4x_set_wiper(uint8_t pot_bits,
uint8_t pos)
Updates potentiometer wiper settings in the selected MCP4x device.
uint8_t mcp4x_shutdown(uint8_t pot_bits)
Disables potentiometers in the selected MCP4x device.
Helper module for SPI communication.
spi_state spihelper_request(uint8_t n_out,
volatile const uint8_t *bfr_out,
uint8_t n_in,
uint8_t offset_in,
volatile uint8_t *bfr_in)
Initiates an SPI request operation consisting of a transmit phase followed by a receive phase.
uint8_t spihelper_exchange_bytes(uint8_t data_out)
Synchronously exchanges a single pair of bytes via the SPI peripheral.
Close