Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: MAX5171BOB_Tester MAX5171BOB_14bit_Remote_Sense_SPI_DAC MAX5171BOB_Serial_Tester
MAX5171 Class Reference
MAX5171 Low-Power, Serial, 14-Bit, 1-Channel DACs with Force/Sense Voltage Output and SPI Interface. More...
#include <MAX5171.h>
Public Types | |
| enum | MAX5171_CMD_enum_t { CMD_00dd_dddd_dddd_dddd_CODE = 0x0000, CMD_01dd_dddd_dddd_dddd_CODE_LOAD = 0x4000, CMD_10xx_xxxx_xxxx_xxxx_LOAD = 0x8000, CMD_1100_xxxx_xxxx_xxxx_NOP = 0xc000, CMD_1101_xxxx_xxxx_xxxx_SHUTDOWN = 0xd000, CMD_1110_0xxx_xxxx_xxxx_UPO_LOW = 0xe000, CMD_1110_1xxx_xxxx_xxxx_UPO_HIGH = 0xe800, CMD_1111_0xxx_xxxx_xxxx_MODE1_DOUT_SCLK_RISING_EDGE = 0xf000, CMD_1111_1xxx_xxxx_xxxx_MODE0_DOUT_SCLK_FALLING_EDGE = 0xf800 } |
Command Codes (first byte) More... | |
| enum | MAX5171_ic_t |
IC's supported with this driver. More... | |
| typedef enum MAX5171::MAX5171_CMD_enum_t | MAX5171_CMD_enum_t |
| Command Codes (first byte) | |
Public Member Functions | |
| MAX5171 (SPI &spi, DigitalOut &cs_pin, DigitalOut &RS_pin, DigitalOut &PDLb_pin, DigitalOut &CLRb_pin, DigitalOut &SHDN_pin, DigitalIn &UPO_pin, MAX5171_ic_t ic_variant) | |
| Constructor for MAX5171 Class. | |
| void | spi_frequency (int spi_sclk_Hz) |
| set SPI SCLK frequency | |
| int | get_spi_frequency () const |
| get SPI SCLK frequency | |
| int | get_spi_dataMode () const |
| get SPI mode | |
| void | Init (void) |
| Menu item '!' Initialize device. | |
| uint16_t | DACCodeOfVoltage (double voltageV) |
| Return the DAC register value corresponding to physical voltage. | |
| double | VoltageOfCode (uint16_t value_u14) |
| Return the physical voltage corresponding to DAC register. | |
| uint8_t | CODE (uint16_t dacCodeLsbs) |
| CMD_00dd_dddd_dddd_dddd_CODE. | |
| uint8_t | CODE_LOAD (uint16_t dacCodeLsbs) |
| CMD_01dd_dddd_dddd_dddd_CODE_LOAD. | |
| uint8_t | LOAD (void) |
| CMD_10xx_xxxx_xxxx_xxxx_LOAD. | |
| uint8_t | NOP (void) |
| CMD_1100_xxxx_xxxx_xxxx_NOP. | |
| uint8_t | SHUTDOWN (void) |
| CMD_1101_xxxx_xxxx_xxxx_SHUTDOWN. | |
| uint8_t | UPO_LOW (void) |
| CMD_1110_0xxx_xxxx_xxxx_UPO_LOW. | |
| uint8_t | UPO_HIGH (void) |
| CMD_1110_1xxx_xxxx_xxxx_UPO_HIGH. | |
| uint8_t | MODE1_DOUT_SCLK_RISING_EDGE (void) |
| CMD_1111_0xxx_xxxx_xxxx_MODE1_DOUT_SCLK_RISING_EDGE. | |
| uint8_t | MODE0_DOUT_SCLK_FALLING_EDGE (void) |
| CMD_1111_1xxx_xxxx_xxxx_MODE0_DOUT_SCLK_FALLING_EDGE. | |
Data Fields | |
| Callback< void(size_t, uint8_t *, uint8_t *) | onSPIprint ) |
| Function pointer void f(size_t byteCount, uint8_t mosiData[], uint8_t misoData[]) | |
| double | VRef |
| reference voltage, in Volts | |
| int16_t | DACCode |
| shadow of dacCodeLsbs; write-only dacCodeLsbs field CMD_00dd_dddd_dddd_dddd_CODE or CMD_01dd_dddd_dddd_dddd_CODE_LOAD | |
Detailed Description
MAX5171 Low-Power, Serial, 14-Bit, 1-Channel DACs with Force/Sense Voltage Output and SPI Interface.
Datasheet: https://www.maximintegrated.com/MAX5171
// example code includes // standard include for target platform -- Platform_Include_Boilerplate #include "mbed.h" // Platforms: // - MAX32625MBED // - supports mbed-os-5.11, requires USBDevice library // - add https://developer.mbed.org/teams/MaximIntegrated/code/USBDevice/ // - remove max32630fthr library (if present) // - remove MAX32620FTHR library (if present) // - MAX32600MBED // - remove max32630fthr library (if present) // - remove MAX32620FTHR library (if present) // - Windows 10 note: Don't connect HDK until you are ready to load new firmware into the board. // - NUCLEO_F446RE // - remove USBDevice library // - remove max32630fthr library (if present) // - remove MAX32620FTHR library (if present) // - NUCLEO_F401RE // - remove USBDevice library // - remove max32630fthr library (if present) // - remove MAX32620FTHR library (if present) // - MAX32630FTHR // - #include "max32630fthr.h" // - add http://os.mbed.org/teams/MaximIntegrated/code/max32630fthr/ // - remove MAX32620FTHR library (if present) // - MAX32620FTHR // - #include "MAX32620FTHR.h" // - remove max32630fthr library (if present) // - add https://os.mbed.com/teams/MaximIntegrated/code/MAX32620FTHR/ // - not tested yet // - MAX32625PICO // - remove max32630fthr library (if present) // - remove MAX32620FTHR library (if present) // - not tested yet // // end Platform_Include_Boilerplate #include "MAX5171.h" // example code board support //MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3); //DigitalOut rLED(LED1); //DigitalOut gLED(LED2); //DigitalOut bLED(LED3); // // Arduino "shield" connector port definitions (MAX32625MBED shown) #if defined(TARGET_MAX32625MBED) #define A0 AIN_0 #define A1 AIN_1 #define A2 AIN_2 #define A3 AIN_3 #define D0 P0_0 #define D1 P0_1 #define D2 P0_2 #define D3 P0_3 #define D4 P0_4 #define D5 P0_5 #define D6 P0_6 #define D7 P0_7 #define D8 P1_4 #define D9 P1_5 #define D10 P1_3 #define D11 P1_1 #define D12 P1_2 #define D13 P1_0 #endif // example code declare SPI interface (GPIO controlled CS) #if defined(TARGET_MAX32625MBED) SPI spi(SPI1_MOSI, SPI1_MISO, SPI1_SCK); // mosi, miso, sclk spi1 TARGET_MAX32625MBED: P1_1 P1_2 P1_0 Arduino 10-pin header D11 D12 D13 DigitalOut spi_cs(SPI1_SS); // TARGET_MAX32625MBED: P1_3 Arduino 10-pin header D10 #elif defined(TARGET_MAX32600MBED) SPI spi(SPI2_MOSI, SPI2_MISO, SPI2_SCK); // mosi, miso, sclk spi1 TARGET_MAX32600MBED: Arduino 10-pin header D11 D12 D13 DigitalOut spi_cs(SPI2_SS); // Generic: Arduino 10-pin header D10 #elif defined(TARGET_NUCLEO_F446RE) || defined(TARGET_NUCLEO_F401RE) // TODO1: avoid resource conflict between P5_0, P5_1, P5_2 SPI and DigitalInOut // void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel) // // TODO1: NUCLEO_F446RE SPI not working; CS and MOSI data looks OK but no SCLK clock pulses. SPI spi(SPI_MOSI, SPI_MISO, SPI_SCK); // mosi, miso, sclk spi1 TARGET_NUCLEO_F446RE: Arduino 10-pin header D11 D12 D13 DigitalOut spi_cs(SPI_CS); // TARGET_NUCLEO_F446RE: PB_6 Arduino 10-pin header D10 // #else SPI spi(D11, D12, D13); // mosi, miso, sclk spi1 TARGET_MAX32600MBED: Arduino 10-pin header D11 D12 D13 DigitalOut spi_cs(D10); // Generic: Arduino 10-pin header D10 #endif // example code declare GPIO interface pins // AnalogOut FB_pin(Px_x_PortName_To_Be_Determined); // Analog Input to MAX5171 device DigitalOut RS_pin(D9); // Digital Configuration Input to MAX5171 device DigitalOut PDLb_pin(D8); // Digital Configuration Input to MAX5171 device DigitalOut CLRb_pin(D7); // Digital Configuration Input to MAX5171 device DigitalOut SHDN_pin(D6); // Digital Configuration Input to MAX5171 device // AnalogIn OUT_pin(A0); // Analog Output from MAX5171 device DigitalIn UPO_pin(D5); // Digital General-Purpose Output from MAX5171 device // example code declare device instance MAX5171 g_MAX5171_device(spi, spi_cs, RS_pin, PDLb_pin, CLRb_pin, SHDN_pin, UPO_pin, MAX5171::MAX5171_IC); // example code main function int main() { g_MAX5171_device.Init(); while (1) { uint16_t code; // // example #1 code = 0x3fff; // 100.0% of full scale REF(2.50V) = 2.50V (FB=1-2:FORCE_BIP/SENSE_BIP: 2.50V) (FB=2-3:FORCE_UNI/SENSE_UNI: 5.00V) g_MAX5171_device.CODE_LOAD(code); wait_ms(3000); // wait_ms(unsigned long interval_msec) // // example #2 code = 0x3998; // 90.0% of full scale REF(2.50V) = 2.25V (FB=1-2:FORCE_BIP/SENSE_BIP: 2.00V) (FB=2-3:FORCE_UNI/SENSE_UNI: 4.50V) g_MAX5171_device.CODE_LOAD(code); wait_ms(3000); // wait_ms(unsigned long interval_msec) // // example #3 code = 0x3332; // 80.0% of full scale REF(2.50V) = 2.00V (FB=1-2:FORCE_BIP/SENSE_BIP: 1.50V) (FB=2-3:FORCE_UNI/SENSE_UNI: 4.00V) g_MAX5171_device.CODE_LOAD(code); wait_ms(3000); // wait_ms(unsigned long interval_msec) // // example #4 code = 0x2ccc; // 70.0% of full scale REF(2.50V) = 1.75V (FB=1-2:FORCE_BIP/SENSE_BIP: 1.00V) (FB=2-3:FORCE_UNI/SENSE_UNI: 3.50V) g_MAX5171_device.CODE_LOAD(code); wait_ms(3000); // wait_ms(unsigned long interval_msec) // // example #5 code = 0x2665; // 60.0% of full scale REF(2.50V) = 1.50V (FB=1-2:FORCE_BIP/SENSE_BIP: 0.50V) (FB=2-3:FORCE_UNI/SENSE_UNI: 3.00V) g_MAX5171_device.CODE_LOAD(code); wait_ms(3000); // wait_ms(unsigned long interval_msec) // // example #6 code = 0x1fff; // 50.0% of full scale REF(2.50V) = 1.25V (FB=1-2:FORCE_BIP/SENSE_BIP: 0.00V) (FB=2-3:FORCE_UNI/SENSE_UNI: 2.50V) g_MAX5171_device.CODE_LOAD(code); wait_ms(3000); // wait_ms(unsigned long interval_msec) // // example #7 code = 0x1999; // 40.0% of full scale REF(2.50V) = 1.00V (FB=1-2:FORCE_BIP/SENSE_BIP: -0.50V) (FB=2-3:FORCE_UNI/SENSE_UNI: 2.00V) g_MAX5171_device.CODE_LOAD(code); wait_ms(3000); // wait_ms(unsigned long interval_msec) // // example #8 code = 0x1332; // 30.0% of full scale REF(2.50V) = 0.75V (FB=1-2:FORCE_BIP/SENSE_BIP: -1.00V) (FB=2-3:FORCE_UNI/SENSE_UNI: 1.50V) g_MAX5171_device.CODE_LOAD(code); wait_ms(3000); // wait_ms(unsigned long interval_msec) // // example #9 code = 0x0ccc; // 20.0% of full scale REF(2.50V) = 0.50V (FB=1-2:FORCE_BIP/SENSE_BIP: -1.50V) (FB=2-3:FORCE_UNI/SENSE_UNI: 1.00V) g_MAX5171_device.CODE_LOAD(code); wait_ms(3000); // wait_ms(unsigned long interval_msec) // // example #10 code = 0x0666; // 10.0% of full scale REF(2.50V) = 0.25V (FB=1-2:FORCE_BIP/SENSE_BIP: -2.00V) (FB=2-3:FORCE_UNI/SENSE_UNI: 0.50V) g_MAX5171_device.CODE_LOAD(code); wait_ms(3000); // wait_ms(unsigned long interval_msec) // // example #11 code = 0x0000; // 0.0% of full scale REF(2.50V) = 0.00V (FB=1-2:FORCE_BIP/SENSE_BIP: -2.50V) (FB=2-3:FORCE_UNI/SENSE_UNI: 0.00V) g_MAX5171_device.CODE_LOAD(code); wait_ms(3000); // wait_ms(unsigned long interval_msec) // // example #12 code = 0x0000; // 0.0% of full scale REF(2.50V) = 0.00V (FB=1-2:FORCE_BIP/SENSE_BIP: -2.50V) (FB=2-3:FORCE_UNI/SENSE_UNI: 0.00V) g_MAX5171_device.CODE_LOAD(code); wait_ms(3000); // wait_ms(unsigned long interval_msec) // // example #13 code = 0x0666; // 10.0% of full scale REF(2.50V) = 0.25V (FB=1-2:FORCE_BIP/SENSE_BIP: -2.00V) (FB=2-3:FORCE_UNI/SENSE_UNI: 0.50V) g_MAX5171_device.CODE_LOAD(code); wait_ms(3000); // wait_ms(unsigned long interval_msec) // // example #14 code = 0x0ccc; // 20.0% of full scale REF(2.50V) = 0.50V (FB=1-2:FORCE_BIP/SENSE_BIP: -1.50V) (FB=2-3:FORCE_UNI/SENSE_UNI: 1.00V) g_MAX5171_device.CODE_LOAD(code); wait_ms(3000); // wait_ms(unsigned long interval_msec) // // example #15 code = 0x1332; // 30.0% of full scale REF(2.50V) = 0.75V (FB=1-2:FORCE_BIP/SENSE_BIP: -1.00V) (FB=2-3:FORCE_UNI/SENSE_UNI: 1.50V) g_MAX5171_device.CODE_LOAD(code); wait_ms(3000); // wait_ms(unsigned long interval_msec) // // example #16 code = 0x1999; // 40.0% of full scale REF(2.50V) = 1.00V (FB=1-2:FORCE_BIP/SENSE_BIP: -0.50V) (FB=2-3:FORCE_UNI/SENSE_UNI: 2.00V) g_MAX5171_device.CODE_LOAD(code); wait_ms(3000); // wait_ms(unsigned long interval_msec) // // example #17 code = 0x1fff; // 50.0% of full scale REF(2.50V) = 1.25V (FB=1-2:FORCE_BIP/SENSE_BIP: 0.00V) (FB=2-3:FORCE_UNI/SENSE_UNI: 2.50V) g_MAX5171_device.CODE_LOAD(code); wait_ms(3000); // wait_ms(unsigned long interval_msec) // // example #18 code = 0x2665; // 60.0% of full scale REF(2.50V) = 1.50V (FB=1-2:FORCE_BIP/SENSE_BIP: 0.50V) (FB=2-3:FORCE_UNI/SENSE_UNI: 3.00V) g_MAX5171_device.CODE_LOAD(code); wait_ms(3000); // wait_ms(unsigned long interval_msec) // // example #19 code = 0x2ccc; // 70.0% of full scale REF(2.50V) = 1.75V (FB=1-2:FORCE_BIP/SENSE_BIP: 1.00V) (FB=2-3:FORCE_UNI/SENSE_UNI: 3.50V) g_MAX5171_device.CODE_LOAD(code); wait_ms(3000); // wait_ms(unsigned long interval_msec) // // example #20 code = 0x3332; // 80.0% of full scale REF(2.50V) = 2.00V (FB=1-2:FORCE_BIP/SENSE_BIP: 1.50V) (FB=2-3:FORCE_UNI/SENSE_UNI: 4.00V) g_MAX5171_device.CODE_LOAD(code); wait_ms(3000); // wait_ms(unsigned long interval_msec) // // example #21 code = 0x3998; // 90.0% of full scale REF(2.50V) = 2.25V (FB=1-2:FORCE_BIP/SENSE_BIP: 2.00V) (FB=2-3:FORCE_UNI/SENSE_UNI: 4.50V) g_MAX5171_device.CODE_LOAD(code); wait_ms(3000); // wait_ms(unsigned long interval_msec) // // example #22 code = 0x3fff; // 100.0% of full scale REF(2.50V) = 2.50V (FB=1-2:FORCE_BIP/SENSE_BIP: 2.50V) (FB=2-3:FORCE_UNI/SENSE_UNI: 5.00V) g_MAX5171_device.CODE_LOAD(code); wait_ms(3000); // wait_ms(unsigned long interval_msec) // wait(3.0); } }
Definition at line 333 of file MAX5171.h.
Member Typedef Documentation
| typedef enum MAX5171::MAX5171_CMD_enum_t MAX5171_CMD_enum_t |
Command Codes (first byte)
Naming convention is CMD_bitstream_FUNCTION_NAME
- dd_dddd_dddd_dddd = data field
- xxxx = don't care
Member Enumeration Documentation
| enum MAX5171_CMD_enum_t |
Command Codes (first byte)
Naming convention is CMD_bitstream_FUNCTION_NAME
- dd_dddd_dddd_dddd = data field
- xxxx = don't care
- Enumerator:
| enum MAX5171_ic_t |
Constructor & Destructor Documentation
| MAX5171 | ( | SPI & | spi, |
| DigitalOut & | cs_pin, | ||
| DigitalOut & | RS_pin, | ||
| DigitalOut & | PDLb_pin, | ||
| DigitalOut & | CLRb_pin, | ||
| DigitalOut & | SHDN_pin, | ||
| DigitalIn & | UPO_pin, | ||
| MAX5171_ic_t | ic_variant | ||
| ) |
Constructor for MAX5171 Class.
Requires an existing SPI object as well as a DigitalOut object. The DigitalOut object is used for a chip enable signal
On Entry:
- Parameters:
-
[in] spi - pointer to existing SPI object [in] cs_pin - pointer to a DigitalOut pin object [in] RS_pin - pointer to a DigitalOut pin object [in] PDLb_pin - pointer to a DigitalOut pin object [in] CLRb_pin - pointer to a DigitalOut pin object [in] SHDN_pin - pointer to a DigitalOut pin object [in] UPO_pin - pointer to a DigitalIn pin object [in] ic_variant - which type of MAX5171 is used
On Exit:
- Returns:
- None
Definition at line 118 of file MAX5171.cpp.
Member Function Documentation
| uint8_t CODE | ( | uint16_t | dacCodeLsbs ) |
CMD_00dd_dddd_dddd_dddd_CODE.
Load input register; DAC registers are unchanged.
- Returns:
- 1 on success; 0 on failure
Definition at line 494 of file MAX5171.cpp.
| uint8_t CODE_LOAD | ( | uint16_t | dacCodeLsbs ) |
CMD_01dd_dddd_dddd_dddd_CODE_LOAD.
Load input register; DAC registers are updated (start up DAC with new data).
- Returns:
- 1 on success; 0 on failure
Definition at line 522 of file MAX5171.cpp.
| uint16_t DACCodeOfVoltage | ( | double | voltageV ) |
Return the DAC register value corresponding to physical voltage.
Does not perform any offset or gain correction.
- Precondition:
- g_MAX5171_device.VRef = Voltage of REF input, in Volts
- Parameters:
-
[in] voltage = physical voltage in Volts
- Returns:
- raw 14-bit MAX5171 code (right justified).
Definition at line 445 of file MAX5171.cpp.
| void Init | ( | void | ) |
Menu item '!' Initialize device.
TODO1: #170 MAX5171 Self Test for Test Fixture Firmware test group ____ // Verify function ____ (enabled by default) test tinyTester.settle_time_msec = 250;
Device Testing: DAC commands, verify using on-board ADC inputs
tinyTester.err_threshold = 0.030; // 30mV
cmdLine.serial().printf(" MAX5171.CODE_LOAD code=%d", code); g_MAX5171_device.CODE_LOAD(code);
code = 0x0000; cmdLine.serial().printf(" MAX5171.CODE_LOAD code=%d", code); g_MAX5171_device.CODE_LOAD(code);
code = 0x1FFF; cmdLine.serial().printf(" MAX5171.CODE_LOAD code=%d", code); g_MAX5171_device.CODE_LOAD(code);
test UPO User Programmable Output, verify using digital input D2
cmdLine.serial().printf(" MAX5171.UPO_LOW"); g_MAX5171_device.UPO_LOW();
cmdLine.serial().printf(" MAX5171.UPO_HIGH"); g_MAX5171_device.UPO_HIGH();
Definition at line 430 of file MAX5171.cpp.
| uint8_t LOAD | ( | void | ) |
CMD_10xx_xxxx_xxxx_xxxx_LOAD.
Update DAC register from input register (start up DAC with data previously stored in the input registers).
- Returns:
- 1 on success; 0 on failure
Definition at line 551 of file MAX5171.cpp.
| uint8_t MODE0_DOUT_SCLK_FALLING_EDGE | ( | void | ) |
CMD_1111_1xxx_xxxx_xxxx_MODE0_DOUT_SCLK_FALLING_EDGE.
Mode 0, DOUT clocked out on SCLK's falling edge (default).
- Returns:
- 1 on success; 0 on failure
Definition at line 689 of file MAX5171.cpp.
| uint8_t MODE1_DOUT_SCLK_RISING_EDGE | ( | void | ) |
CMD_1111_0xxx_xxxx_xxxx_MODE1_DOUT_SCLK_RISING_EDGE.
Mode 1, DOUT clocked out on SCLK's rising edge.
- Returns:
- 1 on success; 0 on failure
Definition at line 666 of file MAX5171.cpp.
| uint8_t NOP | ( | void | ) |
CMD_1100_xxxx_xxxx_xxxx_NOP.
No operation (NOP).
- Returns:
- 1 on success; 0 on failure
Definition at line 574 of file MAX5171.cpp.
| uint8_t SHUTDOWN | ( | void | ) |
CMD_1101_xxxx_xxxx_xxxx_SHUTDOWN.
Shut down DAC (provided PDL# = 1).
- Returns:
- 1 on success; 0 on failure
Definition at line 597 of file MAX5171.cpp.
| void spi_frequency | ( | int | spi_sclk_Hz ) |
set SPI SCLK frequency
Definition at line 189 of file MAX5171.cpp.
| uint8_t UPO_HIGH | ( | void | ) |
CMD_1110_1xxx_xxxx_xxxx_UPO_HIGH.
UPO goes high.
- Returns:
- 1 on success; 0 on failure
Definition at line 643 of file MAX5171.cpp.
| uint8_t UPO_LOW | ( | void | ) |
CMD_1110_0xxx_xxxx_xxxx_UPO_LOW.
UPO goes low (default).
- Returns:
- 1 on success; 0 on failure
Definition at line 620 of file MAX5171.cpp.
| double VoltageOfCode | ( | uint16_t | value_u14 ) |
Return the physical voltage corresponding to DAC register.
Does not perform any offset or gain correction.
- Precondition:
- g_MAX5171_device.VRef = Voltage of REF input, in Volts
- Parameters:
-
[in] value_u14,: raw 14-bit MAX5171 code (right justified).
- Returns:
- physical voltage corresponding to MAX5171 code.
Definition at line 475 of file MAX5171.cpp.
Field Documentation
| int16_t DACCode |
| Callback<void(size_t, uint8_t*, uint8_t*) onSPIprint) |
Function pointer void f(size_t byteCount, uint8_t mosiData[], uint8_t misoData[])
optional onSPIprint SPI diagnostic function
Generated on Thu Jul 14 2022 04:41:37 by
1.7.2
MAX5171BOB